Projet

Général

Profil

0001-unfeed-clean-cached-values-of-substitution-variables.patch

Nicolas Roche, 24 avril 2019 16:03

Télécharger (4,14 ko)

Voir les différences:

Subject: [PATCH] unfeed: clean cached values of substitution variables using a
 condition before entering into workflow (#32558)

 tests/test_form_pages.py | 68 ++++++++++++++++++++++++++++++++++++++++
 wcs/forms/root.py        |  2 ++
 2 files changed, 70 insertions(+)
tests/test_form_pages.py
6158 6158
    params = resp.form.submit_fields()
6159 6159
    params = [(key, value if key != 'page_id' else 'eiuiu') for key, value in params]
6160 6160
    app.post('/foo/live', params=params)
6161

  
6162
def test_unfeed_structured_list_when_condition_changes(pub):
6163
    """
6164
    simulate selection of a structured list via condition on from,
6165
    followed by a firstof evaluation on workflow in order to get
6166
    a structured value from the selected list.
6167
    """
6168
    Workflow.wipe()
6169
    workflow = Workflow(name='test')
6170
    workflow.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(workflow)
6171
    workflow.backoffice_fields_formdef.fields = [
6172
        fields.StringField(
6173
            id='bo1', label='first text', type='string', varname='firstof_text'),
6174
        fields.StringField(
6175
            id='bo2', label='first more', type='string', varname='firstof_more')
6176
    ]
6177

  
6178
    st1 = workflow.add_status('Status1', 'st1')
6179
    setbo = SetBackofficeFieldsWorkflowStatusItem()
6180
    setbo.parent = st1
6181
    setbo.fields = [
6182
        {'field_id': 'bo1',
6183
         'value': '{% firstof form_var_listA form_var_listB %}'},
6184
        {'field_id': 'bo2',
6185
         'value': '{% firstof form_var_listA_more form_var_listB_more %}'}
6186
         ]
6187
    st1.items.append(setbo)
6188
    workflow.store()
6189

  
6190
    items_A = [{'id': '1', 'text': 'A1', 'more':'moreA1'}]
6191
    items_B = [{'id': '1', 'text': 'B1', 'more':'moreB1'},
6192
               {'id': '2', 'text': 'B2', 'more':'moreB2'}]
6193
    formdef = create_formdef()
6194
    formdef.fields = [
6195
        fields.ItemField(id='1', varname='choice', items=['A', 'B'],
6196
                         type='item', label='list to choice'),
6197
        fields.ItemField(id='2', varname='listA', type='item', label='list A',
6198
                         data_source={'type': 'formula', 'value': str(items_A)},
6199
                         condition={'type': 'python',
6200
                                    'value': 'form_var_choice_raw == "A"'}),
6201
        fields.ItemField(id='3', varname='listB', type='item', label='list B',
6202
                         data_source={'type': 'formula', 'value': str(items_B)},
6203
                         condition={'type': 'python',
6204
                                    'value': 'form_var_choice_raw == "B"'})
6205
        ]
6206
    formdef.confirmation = False
6207
    formdef.workflow_id = workflow.id
6208
    formdef.store()
6209
    formdef.data_class().wipe()
6210

  
6211
    create_user_and_admin(pub)
6212
    resp = get_app(pub).get('/test/')
6213

  
6214
    resp.form['f1'].value = 'B'
6215
    resp.form['f2'].value = '1'
6216
    resp.form['f3'].value = '2'
6217

  
6218
    resp = resp.form.submit('submit').follow()
6219
    assert 'The form has been recorded' in resp.body
6220

  
6221
    assert formdef.data_class().count() == 1
6222
    formdata = formdef.data_class().select()[0]
6223
    assert formdata.data['1'] == 'B'
6224
    assert formdata.data.get('2') is None
6225
    assert formdata.data['3'] == '2'
6226

  
6227
    assert formdata.data['bo1'] == 'B2'
6228
    assert formdata.data['bo2'] == 'moreB2'
wcs/forms/root.py
1148 1148
        get_logger().info('form %s - done (id: %s)' % (self.formdef.name, filled.id))
1149 1149
        url = None
1150 1150
        if existing_formdata is None:
1151
            get_publisher().substitutions.unfeed(lambda x: x.__class__.__name__ == 'ConditionVars')
1152
            get_publisher().substitutions.unfeed(lambda x: isinstance(x, FormData))
1151 1153
            url = filled.perform_workflow()
1152 1154

  
1153 1155
        if not filled.user_id:
1154
-