Commit 2c9dfa51 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Julien Muchembled

ERP5 Base: Refactor addition of new objects for erp5 objects

It's better to create new objects using same script rather than
keeping 2 scripts that try to do the same thing: Folder_create
(script used to add in case we create new object using the icon next to actions bar)
did not support the getRedirectParameter API. We now do all the work
related to adding new object in Folder_create itself.


Test Result : https://nexedi.erp5.net/test_result_module/20161006-39C681E1
Reviewed by: @jm 

/reviewed-on !177
parent 3d1a8811
......@@ -34,18 +34,9 @@ if doAction0 in ('object', 'workflow', 'folder'):
kw['dialog_category'] = 'object_action'
# Otherwise, check if this is an automatic menu (add)
elif doAction0 == 'add':
type_name = ' '.join(Base_doAction[1:])
new_content = context.newContent(portal_type=type_name,
container=context)
preserved_parameter_dict['portal_status_message'] = Base_translateString("Object created.")
preserved_parameter_dict['editable_mode'] = 1
try:
tmp_kw = new_content.getRedirectParameterDictAfterAdd(context, **kw)
except AttributeError:
# Maybe the Product is not upgraded yet.
tmp_kw = new_content.Base_getRedirectParameterDictAfterAdd(context, **kw)
redirect_url = tmp_kw.pop('redirect_url', new_content.absolute_url())
kw.update(tmp_kw)
return context.Folder_create(' '.join(Base_doAction[1:]),
preserved_parameter_dict,
**kw)
# Otherwise, check if this is an automatic menu (template)
elif doAction0 == 'template':
template_relative_url = ' '.join(Base_doAction[1:])
......
# This is the default method for a redirection after being added.
return dict(redirect_url=context.absolute_url(), selection_index=None, selection_name=None)
return dict(selection_index=None, selection_name=None)
Base_translateString = context.getPortalObject().Base_translateString
allowed_type_list = context.getVisibleAllowedContentTypeList()
if not allowed_type_list:
return context.ERP5Site_redirect(context.absolute_url(), keep_items={'portal_status_message': Base_translateString("You are not allowed to add new content in this context.")})
if not type_name:
allowed_type_list = context.getVisibleAllowedContentTypeList()
if not allowed_type_list:
return context.Base_redirect(keep_items={'portal_status_message':
Base_translateString("You are not allowed to add new content in this context.")})
# newContent will add the first allowed type when we do not specify portal_type=
type_name = allowed_type_list[0]
# newContent will add the first allowed type when we do not specify portal_type=
new_object = context.newContent(portal_type=allowed_type_list[0])
return context.ERP5Site_redirect(new_object.absolute_url(),
keep_items={'portal_status_message': Base_translateString("Object created."),
'editable_mode': 1})
if keep_items is None:
keep_items = {}
new_content = context.newContent(portal_type=type_name)
keep_items['portal_status_message'] = Base_translateString("Object created.")
keep_items['editable_mode'] = 1
kw = new_content.getRedirectParameterDictAfterAdd(context, **kw)
redirect_url = kw.pop('redirect_url', None)
return new_content.Base_redirect(redirect_url, keep_items=keep_items, **kw)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>type_name=None, keep_items=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -2930,14 +2930,8 @@ class Base( CopyContainer,
def getRedirectParameterDictAfterAdd(self, container, **kw):
"""Return a dict of parameters to specify where the user is redirected
to after a new object is added in the UI."""
method = self._getTypeBasedMethod('getRedirectParameterDictAfterAdd',
'Base_getRedirectParameterDictAfterAdd')
if method is not None:
return method(container, **kw)
# XXX this should not happen, unless the Business Template is broken.
return dict(redirect_url=container.absolute_url(),
selection_index=None, selection_name=None)
method = self._getTypeBasedMethod('getRedirectParameterDictAfterAdd')
return method(container, **kw)
security.declareProtected(Permissions.ModifyPortalContent, 'setGuid')
def setGuid(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment