Commit 4abb1c86 authored by Julien Muchembled's avatar Julien Muchembled

Add compatibility code and the wizard to create a module

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/portal_types@29248 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 48acc068
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
request = container.REQUEST\n
\n
portal = context.getPortalObject()\n
portal_types = portal.portal_types\n
object_portal_type_id = object_portal_type\n
\n
# Create a new portal_type for the module\n
module_portal_type_value = portal_types.newContent(portal_type=\'Base Type\',\n
id=module_portal_type,\n
type_factory_method_id=\'addFolder\',\n
type_icon=\'folder_icon.gif\',\n
type_filter_content_type=1,\n
type_allowed_content_type=object_portal_type_id,\n
type_group=\'module\')\n
# initialize translation domains\n
module_portal_type_value.changeTranslations(\n
properties=dict(title=\'erp5_ui\', short_title=\'erp5_ui\'))\n
\n
module_list_form_id = (\'%s_view%sList\' % (module_portal_type,\n
object_portal_type)).replace(\' \', \'\')\n
\n
module_portal_type_value.newContent(portal_type=\'Action Information\',\n
reference="view",\n
title="View",\n
action_expression="string:${object_url}/%s" % module_list_form_id,\n
action_type="object_list")\n
\n
# Create the skin folder if does not exist yet\n
portal_skins_folder_name = portal_skins_folder\n
portal_skins = portal.portal_skins\n
if not portal_skins_folder_name in portal.portal_skins.objectIds():\n
portal_skins.manage_addFolder(portal_skins_folder_name)\n
skin_folder = portal.portal_skins[portal_skins_folder_name]\n
# Add new folders into skin paths.\n
for skin_name, selection in portal_skins.getSkinPaths():\n
selection = selection.split(\',\')\n
if portal_skins_folder_name not in selection:\n
new_selection = [portal_skins_folder_name,]\n
new_selection.extend(selection)\n
portal_skins.manage_skinLayers( skinpath = tuple(new_selection)\n
, skinname = skin_name\n
, add_skin = 1\n
)\n
\n
factory = skin_folder.manage_addProduct[\'ERP5Form\']\n
\n
# Create a form for the module\n
factory.addERP5Form(module_list_form_id, title=module_title)\n
form = skin_folder[module_list_form_id]\n
default_groups = [\'bottom\', \'hidden\']\n
for group in default_groups:\n
form.add_group(group)\n
\n
# XXX this is too low level, but we don\'t have an API available from restricted\n
# environment. Afterall, this script should not use restricted environment\n
form.manage_settings(\n
dict(field_title=form.title,\n
field_name=form.name,\n
field_description=form.description,\n
field_action=\'Base_doSelect\',\n
field_update_action=form.update_action,\n
field_update_action_title=form.update_action_title,\n
field_enctype=form.enctype,\n
field_encoding=form.encoding,\n
field_stored_encoding=form.stored_encoding,\n
field_unicode_mode=form.unicode_mode,\n
field_method=form.method,\n
field_row_length=str(form.row_length),\n
field_pt=\'form_list\',\n
field_edit_order=[]))\n
\n
form.manage_addField(\n
id=\'listbox\',\n
fieldname=\'ProxyField\',\n
title=\'\')\n
form.move_field_group((\'listbox\',), \'left\', \'bottom\')\n
\n
form.listbox.manage_edit_xmlrpc(\n
dict(form_id=\'Base_viewFieldLibrary\',\n
field_id=\'my_list_mode_listbox\'))\n
\n
form.listbox.manage_edit_surcharged_xmlrpc(\n
dict(selection_name=(\'_\'.join(module_portal_type.split())).lower() + \'_selection\',\n
title=module_title,\n
portal_type=[(object_portal_type, object_portal_type), ], ))\n
\n
\n
# Create a form for the document\n
form_view_id = object_portal_type_id.replace(\' \',\'\') + \'_view\'\n
factory.addERP5Form(form_view_id, title=object_title)\n
form = skin_folder[form_view_id]\n
form.rename_group(\'Default\', \'left\')\n
default_groups = [\'right\', \'center\', \'bottom\', \'hidden\']\n
for group in default_groups:\n
form.add_group(group)\n
\n
form.manage_settings(\n
dict(field_title=form.title,\n
field_name=form.name,\n
field_description=form.description,\n
field_action=\'Base_edit\',\n
field_update_action=form.update_action,\n
field_update_action_title=form.update_action_title,\n
field_enctype=form.enctype,\n
field_encoding=form.encoding,\n
field_stored_encoding=form.stored_encoding,\n
field_unicode_mode=form.unicode_mode,\n
field_method=form.method,\n
field_row_length=str(form.row_length),\n
field_pt=\'form_view\',\n
field_edit_order=[]))\n
\n
form.manage_addField(\n
id=\'my_title\',\n
fieldname=\'StringField\',\n
title=\'Title\')\n
\n
\n
# Then add the portal_type corresponding to the new object\n
object_portal_type_value = portal_types.newContent(portal_type=\'Base Type\',\n
id=object_portal_type_id,\n
type_factory_method_id=\'addXMLObject\')\n
\n
# Chain to edit_workflow\n
portal.portal_workflow.setChainForPortalTypes([object_portal_type_id],\n
\'edit_workflow\')\n
\n
# Set default actions\n
object_portal_type_value.newContent(portal_type=\'Action Information\',\n
reference="view",\n
title="View",\n
action_expression="string:${object_url}/%s" % form_view_id,\n
action_type="object_view")\n
\n
# Finally add the module to the site\n
module_object = portal.newContent( portal_type = module_portal_type\n
, id = module_id\n
, title = module_title\n
)\n
module_object.Base_setDefaultSecurity()\n
\n
# Clear caches so that module is immediatly visible\n
portal.changeSkin(None)\n
portal.portal_caches.clearAllCache()\n
\n
if not selection_index:\n
redirect_url = \'%s/%s?%s\' % ( context.absolute_url()\n
, form_id\n
, \'portal_status_message=Module+Created.\'\n
)\n
else:\n
redirect_url = \'%s/%s?selection_index=%s&selection_name=%s&%s\' % ( context.absolute_url()\n
, form_id\n
, selection_index\n
, selection_name\n
, \'portal_status_message=Module+Created.\'\n
)\n
\n
\n
request[ \'RESPONSE\' ].redirect( redirect_url )\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>module_portal_type, portal_skins_folder, object_portal_type, object_title, module_id, module_title, selection_index=0, selection_name=\'\', form_id=\'\'</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>9</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>module_portal_type</string>
<string>portal_skins_folder</string>
<string>object_portal_type</string>
<string>object_title</string>
<string>module_id</string>
<string>module_title</string>
<string>selection_index</string>
<string>selection_name</string>
<string>form_id</string>
<string>_getattr_</string>
<string>container</string>
<string>request</string>
<string>context</string>
<string>portal</string>
<string>portal_types</string>
<string>object_portal_type_id</string>
<string>module_portal_type_value</string>
<string>dict</string>
<string>module_list_form_id</string>
<string>portal_skins_folder_name</string>
<string>portal_skins</string>
<string>_getitem_</string>
<string>skin_folder</string>
<string>_getiter_</string>
<string>skin_name</string>
<string>selection</string>
<string>new_selection</string>
<string>tuple</string>
<string>factory</string>
<string>form</string>
<string>default_groups</string>
<string>group</string>
<string>str</string>
<string>form_view_id</string>
<string>object_portal_type_value</string>
<string>module_object</string>
<string>None</string>
<string>redirect_url</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<int>0</int>
<string></string>
<string></string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_createModule</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
57 60
\ No newline at end of file \ No newline at end of file
...@@ -644,6 +644,31 @@ class ERP5TypeInformation(XMLObject, ...@@ -644,6 +644,31 @@ class ERP5TypeInformation(XMLObject,
# Compatibitility code for actions # Compatibitility code for actions
# #
security.declareProtected(Permissions.ModifyPortalContent, 'addAction')
def addAction(self, id, name, action, condition, permission, category,
icon=None, visible=1, priority=1.0, REQUEST=None,
description=None):
# XXX Should be deprecated. newContent already does everything we want.
if isinstance(permission, basestring):
permission = permission,
self.newContent(portal_type='Action Information',
reference=id,
title=name,
action=action,
condition=condition,
permission_list=permission,
action_type=category,
icon=icon,
visible=visible,
float_index=priority,
description=description)
security.declareProtected(Permissions.ModifyPortalContent, 'deleteActions')
def deleteActions(self, selections=(), REQUEST=None):
# XXX Should be deprecated.
action_list = self.listActions()
self.manage_delObjects([action_list[x].id for x in selections])
security.declarePrivate('listActions') security.declarePrivate('listActions')
def listActions(self, info=None, object=None): def listActions(self, info=None, object=None):
""" List all the actions defined by a provider.""" """ List all the actions defined by a provider."""
......
...@@ -33,6 +33,11 @@ class BaseType: ...@@ -33,6 +33,11 @@ class BaseType:
""" """
_properties = ( _properties = (
{ 'id': 'type_icon',
'storage_id': 'content_icon', # CMF Compatibility
'type': 'string',
'mode': 'w',
},
{ 'id': 'type_factory_method_id', { 'id': 'type_factory_method_id',
'storage_id': 'factory', # CMF Compatibility 'storage_id': 'factory', # CMF Compatibility
'type': 'string', 'type': 'string',
......
...@@ -26,6 +26,7 @@ import Products ...@@ -26,6 +26,7 @@ import Products
from zLOG import LOG from zLOG import LOG
_MARKER = {}
class PropertyDomainDict(Implicit): class PropertyDomainDict(Implicit):
""" """
...@@ -100,14 +101,14 @@ class TranslationProviderBase: ...@@ -100,14 +101,14 @@ class TranslationProviderBase:
property_domain_dict[prop_id] = TranslationInformation(prop_id, domain_name) property_domain_dict[prop_id] = TranslationInformation(prop_id, domain_name)
original_property_domain_dict = getattr(aq_base(self), original_property_domain_dict = getattr(aq_base(self),
'_property_domain_dict', None) '_property_domain_dict', _MARKER)
original_property_domain_keys = original_property_domain_dict.keys() original_property_domain_keys = original_property_domain_dict.keys()
property_domain_keys = property_domain_dict.keys() property_domain_keys = property_domain_dict.keys()
property_domain_keys.sort() property_domain_keys.sort()
original_property_domain_keys.sort() original_property_domain_keys.sort()
# Only update if required in order to prevent ZODB from growing # Only update if required in order to prevent ZODB from growing
if original_property_domain_dict is None or \ if original_property_domain_dict is _MARKER or\
property_domain_keys != original_property_domain_keys: property_domain_keys != original_property_domain_keys:
# Update existing dict # Update existing dict
property_domain_dict.update(original_property_domain_dict) property_domain_dict.update(original_property_domain_dict)
...@@ -169,7 +170,7 @@ class TranslationProviderBase: ...@@ -169,7 +170,7 @@ class TranslationProviderBase:
new_domain_name = properties.get(prop_name) new_domain_name = properties.get(prop_name)
prop_object = property_domain_dict[prop_name] prop_object = property_domain_dict[prop_name]
if new_domain_name != prop_object.getDomainName(): if new_domain_name != prop_object.getDomainName():
prop_object.setDomainName(new_domain_name) prop_object.edit(domain_name=new_domain_name)
from Products.ERP5Type.Base import _aq_reset from Products.ERP5Type.Base import _aq_reset
_aq_reset() # Reset accessor cache _aq_reset() # Reset accessor cache
......
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