Projet

Général

Profil

0001-workflows-add-support-for-django-template-as-anchor-.patch

Frédéric Péters, 01 juillet 2019 09:24

Télécharger (3,53 ko)

Voir les différences:

Subject: [PATCH] workflows: add support for django template as anchor date
 (#33862)

 tests/test_workflows.py |  8 ++++++++
 wcs/workflows.py        | 13 ++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)
tests/test_workflows.py
3226 3226
    assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'green'
3227 3227
    formdata1.store()
3228 3228

  
3229
    # django template
3230
    trigger.anchor = 'template'
3231
    trigger.anchor_template = '{{ form_receipt_date|date:"Y-m-d" }}'
3232
    workflow.store()
3233
    pub.apply_global_action_timeouts()
3234
    assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'yellow'
3235
    formdata1.store()
3236

  
3229 3237
def test_profile(two_pubs):
3230 3238
    User = two_pubs.user_class
3231 3239
    user = User()
wcs/workflows.py
997 997
    key = 'timeout'
998 998
    anchor = None
999 999
    anchor_expression = None
1000
    anchor_template = None
1000 1001
    anchor_status_first = None
1001 1002
    anchor_status_latest = None
1002 1003
    timeout = None
1003 1004

  
1004 1005
    def get_parameters(self):
1005
        return ('anchor', 'anchor_expression', 'anchor_status_first',
1006
        return ('anchor', 'anchor_expression', 'anchor_template', 'anchor_status_first',
1006 1007
                'anchor_status_latest', 'timeout')
1007 1008

  
1008 1009
    def get_anchor_labels(self):
......
1011 1012
                ('1st-arrival', _('First arrival in status')),
1012 1013
                ('latest-arrival', _('Latest arrival in status')),
1013 1014
                ('finalized', _('Arrival in final status')),
1015
                ('template', _('Text / Template')),
1014 1016
                ('python', _('Python expression')),
1015 1017
        ])
1016 1018

  
......
1036 1038
                 value=self.anchor_expression,
1037 1039
                 attrs={'data-dynamic-display-child-of': 'anchor',
1038 1040
                        'data-dynamic-display-value': _('Python expression')})
1041

  
1042
        form.add(StringWidget, 'anchor_template', title=_('Text / Template'), size=80,
1043
                 value=self.anchor_expression,
1044
                 attrs={'data-dynamic-display-child-of': 'anchor',
1045
                        'data-dynamic-display-value': _('Text / Template')})
1046

  
1039 1047
        possible_status = [(None, _('Current Status'), None)]
1040 1048
        possible_status.extend([('wf-%s' % x.id, x.name, x.id) for x in workflow.possible_status])
1041 1049
        form.add(SingleSelectWidget, 'anchor_status_first', title=_('Status'),
......
1096 1104
                        anchor_date = evolution.time
1097 1105
                    else:
1098 1106
                        break
1107
        elif self.anchor == 'template':
1108
            variables = get_publisher().substitutions.get_context_variables()
1109
            anchor_date = Template(self.anchor_template, autoescape=False).render(variables)
1099 1110
        elif self.anchor == 'python':
1100 1111
            variables = get_publisher().substitutions.get_context_variables()
1101 1112
            try:
1102
-