Beispiel #1
0
    def _decode_files(self, files):
        """
        Helper method that when given *files* -- a ``dict`` with the
        structure::

            {
                "<field_name>": {
                    "file_storage_key": "<unicode>",
                    "name": "<unicode>",
                    "content_type": "<unicode>",
                    "size": "<int>",
                    "charset": "<unicode>",
                },
                ...
            }

        a new ``dict`` it returned with the structure::

            {
                "<field_name>": <UploadedFile object>,
                ...
            }

        """
        if files is None:
            return None
        decoded = {}
        for name, data in files.iteritems():
            key = data.pop('file_storage_key')
            uploaded_file = UploadedFile(file=self.file_storage.open(key),
                                         **data)
            # In order to ensure that files aren't repeatedly saved to the file
            # storage, the filename of each file in the file storage is added
            # to ``UploadedFile`` objects as a ``_wizard_file_storage_key``
            # attribute when they're decoded. This acts as a marker to indicate
            # that the file already exists in the file storage.
            uploaded_file._wizard_file_storage_key = key
            decoded[name] = uploaded_file
        return decoded
Beispiel #2
0
    def _decode_files(self, files):
        """
        Helper method that when given *files* -- a ``dict`` with the
        structure::

            {
                "<field_name>": {
                    "file_storage_key": "<unicode>",
                    "name": "<unicode>",
                    "content_type": "<unicode>",
                    "size": "<int>",
                    "charset": "<unicode>",
                },
                ...
            }

        a new ``dict`` it returned with the structure::

            {
                "<field_name>": <UploadedFile object>,
                ...
            }

        """
        if files is None:
            return None
        decoded = {}
        for name, data in files.iteritems():
            key = data.pop('file_storage_key')
            uploaded_file = UploadedFile(file=self.file_storage.open(key),
                                         **data)
            # In order to ensure that files aren't repeatedly saved to the file
            # storage, the filename of each file in the file storage is added
            # to ``UploadedFile`` objects as a ``_wizard_file_storage_key``
            # attribute when they're decoded. This acts as a marker to indicate
            # that the file already exists in the file storage.
            uploaded_file._wizard_file_storage_key = key
            decoded[name] = uploaded_file
        return decoded