misc: moving zip import into a standalone publisher function
This commit is contained in:
parent
f9f6d3d4c7
commit
a405180a9f
|
@ -742,62 +742,7 @@ class SettingsDirectory(QommonSettingsDirectory):
|
|||
return r.getvalue()
|
||||
|
||||
def import_submit(self, form):
|
||||
z = zipfile.ZipFile(form.get_widget('file').parse().fp, 'r')
|
||||
app_dir = get_publisher().app_dir
|
||||
results = {'formdefs': 0, 'workflows': 0, 'categories': 0, 'roles': 0, 'settings': 0}
|
||||
for f in z.namelist():
|
||||
path = os.path.join(app_dir, f)
|
||||
data = z.read(f)
|
||||
if not os.path.exists(os.path.dirname(path)):
|
||||
os.mkdir(os.path.dirname(path))
|
||||
if f == 'config.pck':
|
||||
results['settings'] = 1
|
||||
d = cPickle.loads(data)
|
||||
if get_publisher().cfg.has_key('sp'):
|
||||
current_sp = get_publisher().cfg['sp']
|
||||
else:
|
||||
current_sp = None
|
||||
get_publisher().cfg = d
|
||||
if current_sp:
|
||||
get_publisher().cfg['sp'] = current_sp
|
||||
elif get_publisher().cfg.has_key('sp'):
|
||||
del get_publisher().cfg['sp']
|
||||
get_publisher().write_cfg()
|
||||
continue
|
||||
open(path, 'w').write(data)
|
||||
if results.has_key(os.path.split(f)[0]):
|
||||
results[os.path.split(f)[0]] += 1
|
||||
|
||||
# rebuild indexes for imported objects
|
||||
for k, v in results.items():
|
||||
if k == 'settings':
|
||||
continue
|
||||
if v == 0:
|
||||
continue
|
||||
klass = None
|
||||
if k == 'formdefs':
|
||||
from formdef import FormDef
|
||||
klass = FormDef
|
||||
elif k == 'categories':
|
||||
from categories import Category
|
||||
klass = Category
|
||||
elif k == 'roles':
|
||||
from roles import Role
|
||||
klass = Role
|
||||
elif k == 'workflows':
|
||||
from workflows import Workflow
|
||||
klass = Workflow
|
||||
if klass:
|
||||
klass.rebuild_indexes()
|
||||
|
||||
if k ==' formdefs':
|
||||
# in case of formdefs, we store them anew in case SQL changes
|
||||
# are required.
|
||||
for formdef in FormDef.select():
|
||||
formdef.store()
|
||||
|
||||
z.close()
|
||||
return results
|
||||
return get_publisher().import_zip(form.get_widget('file').parse().fp)
|
||||
|
||||
def sitename(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
|
|
|
@ -14,8 +14,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import cPickle
|
||||
import os
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
from Defaults import *
|
||||
|
||||
|
@ -135,6 +137,63 @@ class WcsPublisher(StubWcsPublisher):
|
|||
else:
|
||||
self.user_class = User
|
||||
|
||||
def import_zip(self, fd):
|
||||
z = zipfile.ZipFile(fd)
|
||||
results = {'formdefs': 0, 'workflows': 0, 'categories': 0, 'roles': 0, 'settings': 0}
|
||||
for f in z.namelist():
|
||||
path = os.path.join(self.app_dir, f)
|
||||
data = z.read(f)
|
||||
if not os.path.exists(os.path.dirname(path)):
|
||||
os.mkdir(os.path.dirname(path))
|
||||
if f == 'config.pck':
|
||||
results['settings'] = 1
|
||||
d = cPickle.loads(data)
|
||||
if self.cfg.has_key('sp'):
|
||||
current_sp = self.cfg['sp']
|
||||
else:
|
||||
current_sp = None
|
||||
self.cfg = d
|
||||
if current_sp:
|
||||
self.cfg['sp'] = current_sp
|
||||
elif self.cfg.has_key('sp'):
|
||||
del self.cfg['sp']
|
||||
self.write_cfg()
|
||||
continue
|
||||
open(path, 'w').write(data)
|
||||
if results.has_key(os.path.split(f)[0]):
|
||||
results[os.path.split(f)[0]] += 1
|
||||
|
||||
# rebuild indexes for imported objects
|
||||
for k, v in results.items():
|
||||
if k == 'settings':
|
||||
continue
|
||||
if v == 0:
|
||||
continue
|
||||
klass = None
|
||||
if k == 'formdefs':
|
||||
from formdef import FormDef
|
||||
klass = FormDef
|
||||
elif k == 'categories':
|
||||
from categories import Category
|
||||
klass = Category
|
||||
elif k == 'roles':
|
||||
from roles import Role
|
||||
klass = Role
|
||||
elif k == 'workflows':
|
||||
from wcs.workflows import Workflow
|
||||
klass = Workflow
|
||||
if klass:
|
||||
klass.rebuild_indexes()
|
||||
|
||||
if k ==' formdefs':
|
||||
# in case of formdefs, we store them anew in case SQL changes
|
||||
# are required.
|
||||
for formdef in FormDef.select():
|
||||
formdef.store()
|
||||
|
||||
z.close()
|
||||
return results
|
||||
|
||||
def try_publish(self, request):
|
||||
if request.get_header('X_WCS_IFRAME_MODE', '') in ('true', 'yes'):
|
||||
request.response.iframe_mode = True
|
||||
|
|
Loading…
Reference in New Issue