def handleApply(self, action): data, errors = self.extractData() if errors: return # Context may not be a container, get one. context_state = getMultiAdapter((self.context, self.request), name="plone_context_state") container = context_state.folder() title = data['file'].filename # Generate a name based on the title.. util = queryUtility(IIDNormalizer) id = util.normalize(title) # Make sure our chosen id is unique, iterate until we get one that is. chooser = INameChooser(container) id = chooser._findUniqueName(id, None) # Determine the Content Type ct_reg = getToolByName(self.context, 'content_type_registry') typeName = ct_reg.findTypeName(data['file'].filename, data['file'].contentType, data['file'].data) # Really, we want Image if it's an image, and File for everything else... typeName = 'Image' if typeName == 'Image' else 'File' # create the object container.invokeFactory(typeName, id=id, title=title, file=data['file'].data) # Redirect to the view page. self.request.response.redirect("%s/view" % container[id].absolute_url())
def handleApply(self, action): data, errors = self.extractData() if errors: return title = data['title'] # Generate a name based on the title.. util = queryUtility(IIDNormalizer) id = util.normalize(title) # Context may not be a container, get one. context_state = getMultiAdapter((self.context, self.request), name="plone_context_state") container = context_state.folder() # Make sure our chosen id is unique, iterate until we get one that is. chooser = INameChooser(container) id = chooser._findUniqueName(id, None) # create the object type_name = data['type_name'] container.invokeFactory(type_name, id=id, title=title) if type_name in [u'Folder']: self.request.response.redirect("%s/@@cmsui-structure" % container[id].absolute_url()) else: self.request.response.redirect("%s/edit" % container[id].absolute_url())