0001-workflows-add-support-for-django-template-as-anchor-.patch
tests/test_workflow_import.py | ||
---|---|---|
638 | 638 |
ac1 = wf.add_global_action('Action', 'ac1') |
639 | 639 |
trigger = ac1.append_trigger('timeout') |
640 | 640 |
trigger.anchor_expression = 'False' |
641 |
trigger.anchor_template = '{{x}}' |
|
641 | 642 |
trigger.anchor = 'python' |
642 | 643 | |
643 | 644 |
wf2 = assert_import_export_works(wf, include_id=True) |
644 | 645 |
assert wf2.global_actions[0].triggers[-1].id == trigger.id |
645 | 646 |
assert wf2.global_actions[0].triggers[-1].anchor == trigger.anchor |
646 | 647 |
assert wf2.global_actions[0].triggers[-1].anchor_expression == trigger.anchor_expression |
648 |
assert wf2.global_actions[0].triggers[-1].anchor_template == trigger.anchor_template |
|
647 | 649 | |
648 | 650 | |
649 | 651 |
def test_global_webservice_trigger(pub): |
tests/test_workflows.py | ||
---|---|---|
3436 | 3436 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'green' |
3437 | 3437 |
formdata1.store() |
3438 | 3438 | |
3439 |
# django template |
|
3440 |
trigger.anchor = 'template' |
|
3441 |
trigger.anchor_template = '{{ form_receipt_date|date:"Y-m-d" }}' |
|
3442 |
workflow.store() |
|
3443 |
pub.apply_global_action_timeouts() |
|
3444 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'yellow' |
|
3445 |
formdata1.store() |
|
3446 | ||
3447 |
# django template |
|
3448 |
trigger.anchor = 'template' |
|
3449 |
trigger.anchor_template = '{{ form_receipt_date|date:"Y-m-d" }}' |
|
3450 |
workflow.store() |
|
3451 |
pub.apply_global_action_timeouts() |
|
3452 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'yellow' |
|
3453 |
formdata1.store() |
|
3454 | ||
3455 |
# django template (with local date format) |
|
3456 |
trigger.anchor = 'template' |
|
3457 |
trigger.anchor_template = '{{ form_receipt_date }}' |
|
3458 |
workflow.store() |
|
3459 |
pub.apply_global_action_timeouts() |
|
3460 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'yellow' |
|
3461 |
formdata1.store() |
|
3462 | ||
3463 |
# django template (with local date/time format) |
|
3464 |
trigger.anchor = 'template' |
|
3465 |
trigger.anchor_template = '{{ form_receipt_datetime }}' |
|
3466 |
workflow.store() |
|
3467 |
pub.apply_global_action_timeouts() |
|
3468 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'yellow' |
|
3469 |
formdata1.store() |
|
3470 | ||
3439 | 3471 | |
3440 | 3472 |
def test_global_timeouts_latest_arrival(two_pubs): |
3441 | 3473 |
pub = two_pubs |
wcs/workflows.py | ||
---|---|---|
1062 | 1062 |
key = 'timeout' |
1063 | 1063 |
anchor = None |
1064 | 1064 |
anchor_expression = '' |
1065 |
anchor_template = '' |
|
1065 | 1066 |
anchor_status_first = None |
1066 | 1067 |
anchor_status_latest = None |
1067 | 1068 |
timeout = None |
1068 | 1069 | |
1069 | 1070 |
def get_parameters(self): |
1070 |
return ('anchor', 'anchor_expression', 'anchor_status_first', |
|
1071 |
return ('anchor', 'anchor_expression', 'anchor_template', 'anchor_status_first',
|
|
1071 | 1072 |
'anchor_status_latest', 'timeout') |
1072 | 1073 | |
1073 | 1074 |
def get_anchor_labels(self): |
... | ... | |
1076 | 1077 |
('1st-arrival', _('First arrival in status')), |
1077 | 1078 |
('latest-arrival', _('Latest arrival in status')), |
1078 | 1079 |
('finalized', _('Arrival in final status')), |
1080 |
('template', _('String / Template')), |
|
1079 | 1081 |
('python', _('Python expression')), |
1080 | 1082 |
]) |
1081 | 1083 | |
... | ... | |
1110 | 1112 |
options=options, value=self.anchor, required=True, |
1111 | 1113 |
attrs={'data-dynamic-display-parent': 'true'}) |
1112 | 1114 | |
1113 |
form.add(StringWidget, 'anchor_expression', title=_('Expression'), size=80,
|
|
1115 |
form.add(StringWidget, 'anchor_expression', title=_('Python Expression to get reference date'), size=80,
|
|
1114 | 1116 |
value=self.anchor_expression, |
1115 |
hint=_('This will only apply to open forms.'), |
|
1117 |
hint=_('This should produce a date; it will only apply to open forms.'),
|
|
1116 | 1118 |
attrs={'data-dynamic-display-child-of': 'anchor', |
1117 | 1119 |
'data-dynamic-display-value': _('Python expression')}) |
1120 | ||
1121 |
form.add(StringWidget, 'anchor_template', title=_('String / Template with reference date'), size=80, |
|
1122 |
value=self.anchor_template, |
|
1123 |
hint=_('This should be a date; it will only apply to open forms.'), |
|
1124 |
attrs={'data-dynamic-display-child-of': 'anchor', |
|
1125 |
'data-dynamic-display-value': _('String / Template')}) |
|
1126 | ||
1118 | 1127 |
possible_status = [(None, _('Current Status'), None)] |
1119 | 1128 |
possible_status.extend([('wf-%s' % x.id, x.name, x.id) for x in workflow.possible_status]) |
1120 | 1129 |
form.add(SingleSelectWidget, 'anchor_status_first', title=_('Status'), |
... | ... | |
1180 | 1189 |
anchor_date = evolution.time |
1181 | 1190 |
else: |
1182 | 1191 |
break |
1192 |
elif self.anchor == 'template': |
|
1193 |
variables = get_publisher().substitutions.get_context_variables() |
|
1194 |
anchor_date = Template(self.anchor_template, autoescape=False).render(variables) |
|
1183 | 1195 |
elif self.anchor == 'python': |
1184 | 1196 |
variables = get_publisher().substitutions.get_context_variables() |
1185 | 1197 |
try: |
1186 |
- |