Projet

Général

Profil

0001-workflows-check-file-type-with-hasattr-for-backoffic.patch

Thomas Noël, 27 octobre 2016 17:22

Télécharger (2,96 ko)

Voir les différences:

Subject: [PATCH] workflows: check file type with hasattr() for backoffice
 fields (#13777)

PicklableUpload may exist in different namespaces, and then there's also
an independant UploadedFile class; just check if will duck like a file.
Similar to #11000 (commit 2adbdc1720)
 tests/test_workflows.py     | 19 +++++++++++++++++++
 wcs/wf/backoffice_fields.py |  7 +++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
tests/test_workflows.py
1938 1938

  
1939 1939
    formdata = formdef.data_class().get(formdata.id)
1940 1940
    assert formdata.data['bo1'].base_filename == 'test.jpeg'
1941
    assert formdata.data['bo1'].content_type == 'image/jpeg'
1942
    assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__),
1943
                                                                   'image-with-gps-data.jpeg')).read()
1944

  
1945
    # same test with PicklableUpload wcs.qommon.form
1946
    from wcs.qommon.form import PicklableUpload as PicklableUpload2
1947
    upload2 = PicklableUpload2('test2.odt', 'application/vnd.oasis.opendocument.text')
1948
    upload2.receive([open(os.path.join(os.path.dirname(__file__), 'template.odt')).read()])
1949
    formdata = formdef.data_class()()
1950
    formdata.data = {'00': upload2}
1951
    formdata.just_created()
1952
    formdata.store()
1953
    pub.substitutions.feed(formdata)
1954
    item.perform(formdata)
1955
    formdata = formdef.data_class().get(formdata.id)
1956
    assert formdata.data['bo1'].base_filename == 'test2.odt'
1957
    assert formdata.data['bo1'].content_type == 'application/vnd.oasis.opendocument.text'
1958
    assert formdata.data['bo1'].get_content() == open(os.path.join(os.path.dirname(__file__),
1959
                                                                   'template.odt')).read()
1941 1960

  
1942 1961
    # check storing response as attachment
1943 1962
    pub.substitutions.feed(formdata)
wcs/wf/backoffice_fields.py
85 85
                    workflow=self.parent.parent)
86 86

  
87 87
    def get_file_value(self, new_value):
88
        if isinstance(new_value, PicklableUpload):
89
            return new_value
88
        if hasattr(new_value, 'base_filename'):
89
            upload = PicklableUpload(new_value.base_filename,
90
                                     new_value.content_type or 'application/octet-stream')
91
            upload.receive([new_value.get_content()])
92
            return upload
90 93

  
91 94
        if isinstance(new_value, NamedAttachmentsSubstitutionProxy):
92 95
            upload = PicklableUpload(new_value.filename, new_value.content_type)
93
-