0001-general-directly-apply-formdef-carddef-schema-change.patch
tests/backoffice_pages/test_all.py | ||
---|---|---|
1961 | 1961 |
formdef = FormDef.get_by_urlname('form-title') |
1962 | 1962 |
formdef.fields.append(fields.MapField(id='4', label='4th field', type='map')) |
1963 | 1963 |
formdef.fields.append(fields.MapField(id='5', label='5th field', type='string')) |
1964 |
formdef.store() |
|
1964 | 1965 |
form_class = formdef.data_class() |
1965 | 1966 |
number31 = [x for x in form_class.select() if x.data['1'] == 'FOO BAR 30'][0] |
1966 | 1967 |
app = login(get_app(pub)) |
tests/test_formdata.py | ||
---|---|---|
2422 | 2422 | |
2423 | 2423 | |
2424 | 2424 |
def test_form_digest_error(pub): |
2425 |
FormDef.wipe() |
|
2425 | 2426 |
if pub.is_using_postgresql(): |
2426 | 2427 |
pub.loggederror_class.wipe() |
2427 | 2428 | |
... | ... | |
2460 | 2461 | |
2461 | 2462 | |
2462 | 2463 |
def test_lazy_formdata_decimal_filter(pub): |
2464 |
FormDef.wipe() |
|
2463 | 2465 |
formdef = FormDef() |
2464 | 2466 |
formdef.name = 'foobar' |
2465 | 2467 |
formdef.url_name = 'foobar' |
... | ... | |
2489 | 2491 | |
2490 | 2492 | |
2491 | 2493 |
def test_lazy_formdata_timesince_filter(pub): |
2494 |
FormDef.wipe() |
|
2492 | 2495 |
formdef = FormDef() |
2493 | 2496 |
formdef.name = 'foobar' |
2494 | 2497 |
formdef.url_name = 'foobar' |
... | ... | |
2534 | 2537 | |
2535 | 2538 | |
2536 | 2539 |
def test_lazy_formdata_mathematics_filters(pub): |
2540 |
FormDef.wipe() |
|
2537 | 2541 |
formdef = FormDef() |
2538 | 2542 |
formdef.name = 'foobar' |
2539 | 2543 |
formdef.url_name = 'foobar' |
... | ... | |
2566 | 2570 | |
2567 | 2571 | |
2568 | 2572 |
def test_lazy_formdata_add_filters(pub): |
2573 |
FormDef.wipe() |
|
2569 | 2574 |
formdef = FormDef() |
2570 | 2575 |
formdef.name = 'foobar' |
2571 | 2576 |
formdef.url_name = 'foobar' |
... | ... | |
2702 | 2707 | |
2703 | 2708 | |
2704 | 2709 |
def test_lazy_formdata_ceil_filter(pub): |
2710 |
FormDef.wipe() |
|
2705 | 2711 |
formdef = FormDef() |
2706 | 2712 |
formdef.name = 'foobar' |
2707 | 2713 |
formdef.url_name = 'foobar' |
... | ... | |
2724 | 2730 | |
2725 | 2731 | |
2726 | 2732 |
def test_lazy_formdata_count_as_len_filter(pub): |
2733 |
FormDef.wipe() |
|
2727 | 2734 |
formdef = FormDef() |
2728 | 2735 |
formdef.name = 'foobar' |
2729 | 2736 |
formdef.url_name = 'foobar' |
... | ... | |
2785 | 2792 |
), |
2786 | 2793 |
} |
2787 | 2794 | |
2795 |
FormDef.wipe() |
|
2788 | 2796 |
formdef = FormDef() |
2789 | 2797 |
formdef.name = 'foobar' |
2790 | 2798 |
formdef.url_name = 'foobar' |
... | ... | |
2825 | 2833 |
'value': repr([{'id': '1', 'text': 'un'}, {'id': '2', 'text': 'deux'}]), |
2826 | 2834 |
} |
2827 | 2835 | |
2836 |
FormDef.wipe() |
|
2828 | 2837 |
formdef = FormDef() |
2829 | 2838 |
formdef.name = 'foobar' |
2830 | 2839 |
formdef.url_name = 'foobar' |
... | ... | |
2925 | 2934 |
pub.cfg['users']['field_name'] = ['3', '4'] |
2926 | 2935 |
pub.write_cfg() |
2927 | 2936 | |
2937 |
FormDef.wipe() |
|
2928 | 2938 |
formdef = FormDef() |
2929 | 2939 |
formdef.name = 'foobar' |
2930 | 2940 |
formdef.url_name = 'foobar' |
wcs/carddef.py | ||
---|---|---|
60 | 60 |
cls = types.ClassType( |
61 | 61 |
self.data_class_name, (sql.SqlCardData,), {'_formdef': self, '_table_name': table_name} |
62 | 62 |
) |
63 |
actions = sql.do_formdef_tables(self) |
|
64 | 63 |
else: |
65 | 64 |
cls = types.ClassType( |
66 | 65 |
self.data_class_name, |
67 | 66 |
(CardData,), |
68 | 67 |
{'_names': 'card-%s' % self.internal_identifier, '_formdef': self}, |
69 | 68 |
) |
70 |
actions = [] |
|
71 | 69 |
setattr(sys.modules['carddef'], self.data_class_name, cls) |
72 | 70 |
setattr(sys.modules['wcs.carddef'], self.data_class_name, cls) |
73 | 71 | |
74 |
if actions: |
|
75 |
for action in actions: |
|
76 |
getattr(cls, action)() |
|
77 | ||
78 | 72 |
return cls |
79 | 73 | |
80 | 74 |
@classmethod |
... | ... | |
151 | 145 |
return True |
152 | 146 |
return False |
153 | 147 | |
154 |
def store(self, comment=None): |
|
148 |
def store(self, comment=None, *args, **kwargs):
|
|
155 | 149 |
self.roles = self.backoffice_submission_roles |
156 |
return super().store(comment=comment) |
|
150 |
return super().store(comment=comment, *args, **kwargs)
|
|
157 | 151 | |
158 | 152 |
@classmethod |
159 | 153 |
def get_carddefs_as_data_source(cls): |
wcs/formdef.py | ||
---|---|---|
312 | 312 |
cls = types.ClassType( |
313 | 313 |
self.data_class_name, (sql.SqlFormData,), {'_formdef': self, '_table_name': table_name} |
314 | 314 |
) |
315 |
actions = sql.do_formdef_tables(self) |
|
316 | 315 |
else: |
317 | 316 |
cls = types.ClassType( |
318 | 317 |
self.data_class_name, |
319 | 318 |
(FormData,), |
320 | 319 |
{'_names': 'form-%s' % self.internal_identifier, '_formdef': self}, |
321 | 320 |
) |
322 |
actions = [] |
|
323 | 321 |
setattr(sys.modules['formdef'], self.data_class_name, cls) |
324 | 322 |
setattr(sys.modules['wcs.formdef'], self.data_class_name, cls) |
325 | 323 | |
326 |
if actions: |
|
327 |
for action in actions: |
|
328 |
getattr(cls, action)() |
|
329 | ||
330 | 324 |
return cls |
331 | 325 | |
332 | 326 |
def get_new_field_id(self): |
... | ... | |
408 | 402 |
new_internal_identifier = self.get_new_internal_identifier() |
409 | 403 |
if not self.internal_identifier: |
410 | 404 |
self.internal_identifier = new_internal_identifier |
405 |
object_only = kwargs.pop('object_only', False) |
|
411 | 406 |
if new_internal_identifier != self.internal_identifier: |
412 | 407 |
# title changed, internal identifier will be changed only if |
413 | 408 |
# the formdef is currently being imported (self.id is None) |
... | ... | |
415 | 410 |
if self.id is None or self.data_class().count() == 0: |
416 | 411 |
self.internal_identifier = new_internal_identifier |
417 | 412 |
StorableObject.store(self, *args, **kwargs) |
413 |
if object_only: |
|
414 |
return |
|
418 | 415 |
if get_publisher().snapshot_class: |
419 | 416 |
get_publisher().snapshot_class.snap(instance=self, comment=comment) |
420 |
if get_publisher().is_using_postgresql(): |
|
421 |
from . import sql |
|
422 | 417 | |
423 |
sql.do_formdef_tables(self, rebuild_views=True, rebuild_global_views=True)
|
|
418 |
self.update_storage()
|
|
424 | 419 |
self.store_related_custom_views() |
425 | 420 | |
421 |
def update_storage(self): |
|
422 |
if not get_publisher().is_using_postgresql(): |
|
423 |
return |
|
424 | ||
425 |
from . import sql |
|
426 | ||
427 |
actions = sql.do_formdef_tables(self, rebuild_views=True, rebuild_global_views=True) |
|
428 |
if actions: |
|
429 |
cls = self.data_class() |
|
430 |
for action in actions: |
|
431 |
getattr(cls, action)() |
|
432 | ||
426 | 433 |
def store_related_custom_views(self): |
427 | 434 |
for view in getattr(self, '_custom_views', []): |
428 | 435 |
view.formdef = self |
... | ... | |
434 | 441 |
def get_widget_fields(self): |
435 | 442 |
return [field for field in self.fields or [] if isinstance(field, fields.WidgetField)] |
436 | 443 | |
437 |
def rebuild(self): |
|
438 |
if get_publisher().is_using_postgresql(): |
|
439 |
from . import sql |
|
440 | ||
441 |
sql.do_formdef_tables(self, rebuild_views=True, rebuild_global_views=True) |
|
442 | ||
443 | 444 |
@property |
444 | 445 |
def default_digest_template(self): |
445 | 446 |
return (self.digest_templates or {}).get('default') |
wcs/sql.py | ||
---|---|---|
424 | 424 |
formdef.id, |
425 | 425 |
get_name_as_sql_identifier(formdef.url_name)[:30], |
426 | 426 |
) |
427 |
formdef.store() |
|
427 |
formdef.store(object_only=True)
|
|
428 | 428 |
return formdef.table_name |
429 | 429 | |
430 | 430 |
wcs/workflows.py | ||
---|---|---|
531 | 531 |
self.formdefs(ignore_migration=True, order_by='id'), |
532 | 532 |
self.carddefs(ignore_migration=True, order_by='id'), |
533 | 533 |
): |
534 |
form.data_class().rebuild_security() |
|
535 | 534 |
if must_update: |
536 |
form.rebuild() |
|
535 |
form.update_storage() |
|
536 |
form.data_class().rebuild_security() |
|
537 | 537 | |
538 | 538 |
if get_response(): |
539 | 539 |
get_response().add_after_job(_('Reindexing cards and forms after workflow change'), update) |
540 |
- |