Project

General

Profile

0001-formdata-handle-form_tracking_code-of-unsaved-data-i.patch

Frédéric Péters, 11 Feb 2019 10:16 PM

Download (3.28 KB)

View differences:

Subject: [PATCH] formdata: handle form_tracking_code of unsaved data in lazy
 mode (#30536)

 tests/test_formdata.py | 18 ++++++++++++++++++
 wcs/formdata.py        |  8 ++++++--
 wcs/variables.py       |  8 +++++++-
 3 files changed, 31 insertions(+), 3 deletions(-)
tests/test_formdata.py
715 715
    assert lazy_formdata.var.filefield.raw.base_filename == 'test.txt'
716 716
    assert lazy_formdata.var.filefield.raw.content_type == 'text/plain'
717 717

  
718
    formdata = FormDef.select()[0].data_class()
719
    lazy_formdata = LazyFormData(formdata)
720
    assert lazy_formdata.tracking_code is None
721
    formdata.data = {'future_tracking_code': 'CDCBGWQX'}
722
    assert lazy_formdata.tracking_code == 'CDCBGWQX'
723

  
724
    formdata = FormDef.select()[0].data_class().select()[0]
725
    lazy_formdata = LazyFormData(formdata)
726
    assert lazy_formdata.tracking_code is None
727

  
728
    tracking_code = pub.tracking_code_class()
729
    tracking_code.formdata = formdata
730
    tracking_code.store()
731
    formdata = FormDef.select()[0].data_class().get(formdata.id)
732
    lazy_formdata = LazyFormData(formdata)
733
    assert lazy_formdata.tracking_code == tracking_code.id
734

  
735

  
718 736
def test_lazy_variables(pub, variable_test_data):
719 737
    formdata = FormDef.select()[0].data_class().select()[0]
720 738
    for mode in (None, 'lazy'):
wcs/formdata.py
686 686

  
687 687
        if self.tracking_code:
688 688
            d['form_tracking_code'] = self.tracking_code
689
        elif not self.status and self.data and 'future_tracking_code' in self.data:
690
            d['form_tracking_code'] = self.data['future_tracking_code']
689
        elif not self.status and self.data:
690
            if 'future_tracking_code' in self.data:
691
                d['form_tracking_code'] = self.data['future_tracking_code']
692
            elif 'draft_formdata_id' in self.data:
693
                formdata = self.formdef.data_class().get(self.data['draft_formdata_id'])
694
                d['form_tracking_code'] = formdata.tracking_code
691 695

  
692 696
        d['form_submission_backoffice'] = self.backoffice_submission
693 697
        d['form_submission_channel'] = self.submission_channel
wcs/variables.py
144 144

  
145 145
    @property
146 146
    def tracking_code(self):
147
        return self.formdata.tracking_code
147
        formdata = self.formdata
148
        if not formdata.status and formdata.data:
149
            if 'future_tracking_code' in formdata.data:
150
                return formdata.data['future_tracking_code']
151
            elif 'draft_formdata_id' in formdata.data:
152
                formdata = formdata.formdef.data_class().get(formdata.data['draft_formdata_id'])
153
        return formdata.tracking_code
148 154

  
149 155
    @property
150 156
    def submission_backoffice(self):
151
-