0002-admin-change-export-import-to-use-XML-files-for-form.patch
tests/test_admin_pages.py | ||
---|---|---|
3988 | 3988 |
zip_content = StringIO.StringIO(resp.body) |
3989 | 3989 |
zipf = zipfile.ZipFile(zip_content, 'a') |
3990 | 3990 |
filelist = zipf.namelist() |
3991 |
assert 'formdefs/1' in filelist |
|
3992 |
assert 'workflows/1' in filelist |
|
3993 |
assert 'models/export_to_model-1.upload' in filelist |
|
3991 |
assert 'formdefs/1' not in filelist |
|
3992 |
assert 'formdefs_xml/1' in filelist |
|
3993 |
assert 'workflows/1' not in filelist |
|
3994 |
assert 'workflows_xml/1' in filelist |
|
3995 |
assert 'models/export_to_model-1.upload' not in filelist |
|
3994 | 3996 |
assert 'roles/1' in filelist |
3995 | 3997 |
assert 'categories/1' in filelist |
3996 | 3998 |
assert 'datasources/1' in filelist |
... | ... | |
4027 | 4029 |
zip_content = StringIO.StringIO(resp.body) |
4028 | 4030 |
zipf = zipfile.ZipFile(zip_content, 'a') |
4029 | 4031 |
filelist = zipf.namelist() |
4030 |
assert 'formdefs/1' in filelist |
|
4031 |
assert 'workflows/1' in filelist |
|
4032 |
assert 'models/export_to_model-1.upload' in filelist |
|
4032 |
assert 'formdefs/1' not in filelist |
|
4033 |
assert 'formdefs_xml/1' in filelist |
|
4034 |
assert 'workflows/1' not in filelist |
|
4035 |
assert 'workflows_xml/1' in filelist |
|
4036 |
assert 'models/export_to_model-1.upload' not in filelist |
|
4033 | 4037 |
assert 'roles/1' not in filelist |
4034 | 4038 |
assert 'categories/1' in filelist |
4035 | 4039 |
assert 'datasources/1' in filelist |
wcs/admin/settings.py | ||
---|---|---|
53 | 53 |
import qommon.template |
54 | 54 | |
55 | 55 |
from formdef import FormDef |
56 |
from workflows import Workflow |
|
56 | 57 |
from fields import FieldDefPage, FieldsDirectory |
57 | 58 |
from wcs.roles import Role |
58 | 59 | |
... | ... | |
876 | 877 |
c = StringIO() |
877 | 878 |
z = zipfile.ZipFile(c, 'w') |
878 | 879 |
for d in self.dirs: |
880 |
if d not in ('roles', 'categories', 'datasources', 'wscalls'): |
|
881 |
continue |
|
879 | 882 |
path = os.path.join(self.app_dir, d) |
880 | 883 |
if not os.path.exists(path): |
881 | 884 |
continue |
... | ... | |
883 | 886 |
if f == '.indexes': |
884 | 887 |
continue |
885 | 888 |
z.write(os.path.join(path, f), os.path.join(d, f)) |
889 |
if 'formdefs' in self.dirs: |
|
890 |
for formdef in FormDef.select(): |
|
891 |
node = formdef.export_to_xml(include_id=True) |
|
892 |
misc.indent_xml(node) |
|
893 |
z.writestr(os.path.join('formdefs_xml', str(formdef.id)), |
|
894 |
'<?xml version="1.0" encoding="iso-8859-15"?>\n' + ET.tostring(node)) |
|
895 |
if 'workflows' in self.dirs: |
|
896 |
for workflow in Workflow.select(): |
|
897 |
node = workflow.export_to_xml(include_id=True) |
|
898 |
misc.indent_xml(node) |
|
899 |
z.writestr(os.path.join('workflows_xml', str(workflow.id)), |
|
900 |
'<?xml version="1.0" encoding="iso-8859-15"?>\n' + ET.tostring(node)) |
|
901 | ||
886 | 902 |
if self.settings: |
887 | 903 |
z.write(os.path.join(self.app_dir, 'config.pck'), 'config.pck') |
888 | 904 |
for f in os.listdir(self.app_dir): |
... | ... | |
901 | 917 |
'datasources', 'wscalls'): |
902 | 918 |
if form.get_widget(w) and form.get_widget(w).parse(): |
903 | 919 |
dirs.append(w) |
904 |
if 'workflows' in dirs: |
|
905 |
dirs.append('models') |
|
906 | 920 |
if not dirs and not form.get_widget('settings').parse(): |
907 | 921 |
return redirect('.') |
908 | 922 |
wcs/publisher.py | ||
---|---|---|
195 | 195 |
for f in z.namelist(): |
196 | 196 |
if '.indexes' in f: |
197 | 197 |
continue |
198 |
if os.path.dirname(f) in ('formdefs_xml', 'workflows_xml'): |
|
199 |
continue |
|
198 | 200 |
path = os.path.join(self.app_dir, f) |
199 | 201 |
if not os.path.exists(os.path.dirname(path)): |
200 | 202 |
os.mkdir(os.path.dirname(path)) |
... | ... | |
223 | 225 |
if results.has_key(os.path.split(f)[0]): |
224 | 226 |
results[os.path.split(f)[0]] += 1 |
225 | 227 | |
228 |
# second pass, workflows |
|
229 |
from wcs.workflows import Workflow |
|
230 |
for f in z.namelist(): |
|
231 |
if os.path.dirname(f) == 'workflows_xml' and os.path.basename(f): |
|
232 |
workflow = Workflow.import_from_xml(z.open(f), include_id=True) |
|
233 |
workflow.store() |
|
234 |
results['workflows'] += 1 |
|
235 | ||
236 |
# third pass, forms |
|
237 |
from wcs.formdef import FormDef |
|
238 |
formdefs = [] |
|
239 |
for f in z.namelist(): |
|
240 |
if os.path.dirname(f) == 'formdefs_xml' and os.path.basename(f): |
|
241 |
formdef = FormDef.import_from_xml(z.open(f), include_id=True) |
|
242 |
formdef.store() |
|
243 |
formdefs.append(formdef) |
|
244 |
results['formdefs'] += 1 |
|
245 | ||
226 | 246 |
# rebuild indexes for imported objects |
227 | 247 |
for k, v in results.items(): |
228 | 248 |
if k == 'settings': |
... | ... | |
248 | 268 |
if k == 'formdefs': |
249 | 269 |
# in case of formdefs, we store them anew in case SQL changes |
250 | 270 |
# are required. |
251 |
for formdef in FormDef.select():
|
|
271 |
for formdef in (formdefs or FormDef.select()):
|
|
252 | 272 |
formdef.store() |
253 | 273 | |
254 | 274 |
z.close() |
255 |
- |