Skip to content

Commit

Permalink
Merge pull request #582 from 4teamwork/tg_dropzone
Browse files Browse the repository at this point in the history
To create a file, get the correct file type from the schema.
  • Loading branch information
tinagerber committed Jan 7, 2020
2 parents 6b3cb4f + 27468f9 commit bb61215
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/HISTORY.txt
Expand Up @@ -6,6 +6,7 @@ Changelog
------------------

- Repair overlay styles. [djowett-ftw]
- To create a file, get the correct file type from the schema. [tinagerber]


2.5.5 (2019-12-20)
Expand Down
14 changes: 8 additions & 6 deletions ftw/simplelayout/contenttypes/browser/dropzone.py
Expand Up @@ -5,8 +5,7 @@
from ftw.simplelayout.utils import IS_PLONE_5
from plone import api
from plone.dexterity.interfaces import IDexterityFTI
from plone.namedfile.file import NamedBlobFile
from plone.namedfile.file import NamedBlobImage
from plone.dexterity.utils import iterSchemataForType
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
from Products.Five.browser import BrowserView
Expand Down Expand Up @@ -54,10 +53,8 @@ def create_obj(self, portal_type, file_field_name, file_):
'safe_id': True}

if self.is_dexterity_fti(portal_type):
if file_field_name == 'image':
kwargs[file_field_name] = NamedBlobImage(file_, filename=filename)
else:
kwargs[file_field_name] = NamedBlobFile(file_, filename=filename)
field = self.get_field_of_type(portal_type, file_field_name)
kwargs[file_field_name] = field._type(file_, filename=filename)
return api.content.create(**kwargs)

else:
Expand All @@ -66,6 +63,11 @@ def create_obj(self, portal_type, file_field_name, file_):
obj.reindexObject(idxs=['SearchableText'])
return obj

def get_field_of_type(self, portal_type, file_field_name):
for schema in iterSchemataForType(portal_type):
if file_field_name in schema:
return schema[file_field_name]


class FileListingUpload(DropzoneUploadBase):

Expand Down

0 comments on commit bb61215

Please sign in to comment.