Projet

Général

Profil

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

Frédéric Péters, 30 juin 2019 17:23

Télécharger (4,11 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        | 27 +++++++++++++++------------
 2 files changed, 23 insertions(+), 12 deletions(-)
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 expression
3230
    trigger.anchor = 'python'
3231
    trigger.anchor_expression = '{{ 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
1011 1011
                ('1st-arrival', _('First arrival in status')),
1012 1012
                ('latest-arrival', _('Latest arrival in status')),
1013 1013
                ('finalized', _('Arrival in final status')),
1014
                ('python', _('Python expression')),
1014
                ('python', _('Expression')),
1015 1015
        ])
1016 1016

  
1017 1017
    def properly_configured(self):
......
1035 1035
        form.add(StringWidget, 'anchor_expression', title=_('Expression'), size=80,
1036 1036
                 value=self.anchor_expression,
1037 1037
                 attrs={'data-dynamic-display-child-of': 'anchor',
1038
                        'data-dynamic-display-value': _('Python expression')})
1038
                        'data-dynamic-display-value': _('Expression')})
1039 1039
        possible_status = [(None, _('Current Status'), None)]
1040 1040
        possible_status.extend([('wf-%s' % x.id, x.name, x.id) for x in workflow.possible_status])
1041 1041
        form.add(SingleSelectWidget, 'anchor_status_first', title=_('Status'),
......
1096 1096
                        anchor_date = evolution.time
1097 1097
                    else:
1098 1098
                        break
1099
        elif self.anchor == 'python':
1099
        elif self.anchor == 'python':  # actually both python & django expressions
1100 1100
            variables = get_publisher().substitutions.get_context_variables()
1101
            try:
1102
                anchor_date = eval(self.anchor_expression,
1103
                        get_publisher().get_global_eval_dict(), variables)
1104
            except:
1105
                # get the variables in the locals() namespace so they are
1106
                # displayed within the trace.
1107
                expression = self.anchor_expression
1108
                global_variables = get_publisher().get_global_eval_dict()
1109
                get_publisher().notify_of_exception(sys.exc_info(), context='[TIMEOUTS]')
1101
            if '{{' in self.anchor_expression or '{% 'in self.anchor_expression:
1102
                anchor_date = Template(self.anchor_expression, autoescape=False).render(variables)
1103
            else:
1104
                try:
1105
                    anchor_date = eval(self.anchor_expression,
1106
                            get_publisher().get_global_eval_dict(), variables)
1107
                except:
1108
                    # get the variables in the locals() namespace so they are
1109
                    # displayed within the trace.
1110
                    expression = self.anchor_expression
1111
                    global_variables = get_publisher().get_global_eval_dict()
1112
                    get_publisher().notify_of_exception(sys.exc_info(), context='[TIMEOUTS]')
1110 1113

  
1111 1114
        # convert anchor_date to datetime.datetime()
1112 1115
        if isinstance(anchor_date, datetime.datetime):
1113
-