[Checkins] SVN: Products.CMFDefault/trunk/Products/CMFDefault/ -
more add form refactoring
Yvo Schubbe
y.2008 at wcm-solutions.de
Sat May 3 10:44:18 EDT 2008
Log message for revision 86225:
- more add form refactoring
Changed:
U Products.CMFDefault/trunk/Products/CMFDefault/browser/file.py
U Products.CMFDefault/trunk/Products/CMFDefault/formlib/form.py
-=-
Modified: Products.CMFDefault/trunk/Products/CMFDefault/browser/file.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/browser/file.py 2008-05-03 14:36:07 UTC (rev 86224)
+++ Products.CMFDefault/trunk/Products/CMFDefault/browser/file.py 2008-05-03 14:44:18 UTC (rev 86225)
@@ -107,7 +107,7 @@
obj = super(FileAddView,
self).create(dict(id=data['file'].filename,
portal_type=data['portal_type']))
- adapted = FileSchemaAdapter(obj)
+ adapted = IFileSchema(obj)
adapted.title = data['title']
adapted.language = u''
adapted.description = data['description']
Modified: Products.CMFDefault/trunk/Products/CMFDefault/formlib/form.py
===================================================================
--- Products.CMFDefault/trunk/Products/CMFDefault/formlib/form.py 2008-05-03 14:36:07 UTC (rev 86224)
+++ Products.CMFDefault/trunk/Products/CMFDefault/formlib/form.py 2008-05-03 14:44:18 UTC (rev 86225)
@@ -129,21 +129,9 @@
obj_type = translate(fti.Title(), self.context)
return _(u'Add ${obj_type}', mapping={'obj_type': obj_type})
+ #same as in form.AddFormBase but without action decorator
def handle_add(self, action, data):
- obj = self.createAndAdd(data)
- if obj is None:
- if self.status:
- message = translate(self.status, self.context)
- self.request.other['portal_status_message'] = message
- return
- obj_type = translate(obj.Type(), self.context)
- message = translate(_(u'${obj_type} added.',
- mapping={'obj_type': obj_type}), self.context)
- if isinstance(message, unicode):
- message = message.encode(self._getBrowserCharset())
- fti = obj.getTypeInfo()
- self._nextURL = '%s/%s?%s' % (obj.absolute_url(), fti.immediate_view,
- make_query(portal_status_message=message))
+ self.createAndAdd(data)
def handle_cancel_success(self, action, data):
return self._setRedirect('portal_types',
@@ -173,20 +161,30 @@
portal_type = obj.getPortalTypeName()
if container_ti is not None and \
not container_ti.allowType(portal_type):
- self.status = u'Disallowed subobject type: %s' % portal_type
- return None
+ raise ValueError('Disallowed subobject type: %s' % portal_type)
name = INameChooser(container).chooseName(obj.getId(), obj)
obj.id = name
container._setObject(name, obj)
+ obj = container._getOb(name)
+ obj_type = translate(obj.Type(), self.context)
+ self.status = _(u'${obj_type} added.', mapping={'obj_type': obj_type})
self._finished_add = True
- return container._getOb(name)
+ self._added_obj = obj
+ return obj
def nextURL(self):
- return self._nextURL
+ obj = self._added_obj
+ fti = obj.getTypeInfo()
+ message = translate(self.status, self.context)
+ if isinstance(message, unicode):
+ message = message.encode(self._getBrowserCharset())
+ return '%s/%s?%s' % (obj.absolute_url(), fti.immediate_view,
+ make_query(portal_status_message=message))
+
class ContentEditFormBase(_EditFormMixin, PageForm):
actions = form.Actions(
More information about the Checkins
mailing list