Commit 9ea10e11 authored by Charles's avatar Charles

Added checks for existing portal_type, property_sheet names

parent 1cd8b3cd
...@@ -13,82 +13,101 @@ fields_ = [field_1, field_2, field_3, field_4, field_5, ...@@ -13,82 +13,101 @@ fields_ = [field_1, field_2, field_3, field_4, field_5,
field_6, field_7, field_8, field_9, field_10] field_6, field_7, field_8, field_9, field_10]
field_types_ = [field_1_type, field_2_type, field_3_type, field_4_type, field_5_type, field_types_ = [field_1_type, field_2_type, field_3_type, field_4_type, field_5_type,
field_6_type, field_7_type, field_8_type, field_9_type, field_10_type] field_6_type, field_7_type, field_8_type, field_9_type, field_10_type]
ele_types = {'Integer':'int', 'String':'string', 'Float':'float'} ele_types = {'integer':'int', 'string':'string', 'float':'float'}
field_names_ = {'Integer':'IntegerField', 'String':'StringField', 'Float': 'FloatField'} field_names_ = {'integer':'IntegerField', 'string':'StringField', 'float': 'FloatField'}
property_sheets = portal.portal_property_sheets property_sheets = portal.portal_property_sheets
# Create new property sheet with fields # Create new property sheet with fields
module_new_property_sheet = property_sheets.newContent(id = property_sheet_name) failed_message = ""
failed = None
for i, field_name in enumerate(fields_): if failed or property_sheet_name in property_sheets:
if field_name == "None": failed_message += "Property+sheet+name+already+taken. "
break; failed = 1
module_new_property_sheet.newContent( else:
portal_type='Standard Property', module_new_property_sheet = property_sheets.newContent(id = property_sheet_name)
reference=field_name,
elementary_type=ele_types[field_types_[i]]) for i, field_name in enumerate(fields_):
if field_name == "None":
break;
module_new_property_sheet.newContent(
portal_type='Standard Property',
reference=field_name,
elementary_type=ele_types[field_types_[i]])
#create new portal type #create new portal type
module_portal_type_value = portal_types.newContent(id=descriptor_portal_type, if failed or descriptor_id in portal_types:
portal_type='Base Type', failed_message += "Property+type+name+already+taken\n"
type_factory_method_id='Item', failed = 1
type_property_Sheet=property_sheet_name) else:
module_portal_type_value = portal_types.newContent(id=descriptor_id,
#adding a view title = data_type_name,
module_portal_type_value.setTranslationDomain('title', 'erp5_ui') portal_type='Base Type',
module_portal_type_value.setTranslationDomain('short_title', 'erp5_ui') type_class='Item',
type_property_Sheet=property_sheet_name)
module_list_form_id = ('%s_view%s' % ("DataDescriptor",
descriptor_portal_type)).replace(' ', '') #adding a view
module_portal_type_value.setTranslationDomain('title', 'erp5_ui')
module_portal_type_value.newContent(portal_type='Action Information', module_portal_type_value.setTranslationDomain('short_title', 'erp5_ui')
reference="view",
title="View", module_list_form_id = ('%s_view%s' % ("DataDescriptor",
action="string:${object_url}/%s" % module_list_form_id, data_type_name)).replace(' ', '')
action_type="object_list")
module_portal_type_value.newContent(portal_type='Action Information',
reference="view",
title="View",
action="string:${object_url}/%s" % module_list_form_id,
action_type="object_list")
#create form #create form
portal_skins_folder_name = "woelfel_viblab_meda" portal_skins_folder_name = "woelfel_viblab_meda"
portal_skins = portal.portal_skins portal_skins = portal.portal_skins
skin_folder = portal.portal_skins[portal_skins_folder_name] skin_folder = portal.portal_skins[portal_skins_folder_name]
factory = skin_folder.manage_addProduct['ERP5Form'] factory = skin_folder.manage_addProduct['ERP5Form']
factory.addERP5Form(module_list_form_id, title=data_type_name) factory.addERP5Form(module_list_form_id, title=data_type_name)
form = skin_folder[module_list_form_id] form = skin_folder[module_list_form_id]
default_groups = ['bottom', 'hidden'] default_groups = ['bottom', 'hidden']
for group in default_groups: for group in default_groups:
form.add_group(group) form.add_group(group)
form.manage_settings(
dict(field_title=form.title,
field_name=form.name,
field_description=form.description,
field_action='Base_edit',
field_update_action=form.update_action,
field_update_action_title=form.update_action_title,
field_enctype=form.enctype,
field_encoding=form.encoding,
field_stored_encoding=form.stored_encoding,
field_unicode_mode=form.unicode_mode,
field_method=form.method,
field_row_length=str(form.row_length),
field_pt='form_view',
field_edit_order=[]))
form.manage_settings( for i, field_name in enumerate(fields_):
dict(field_title=form.title, if field_name == "None":
field_name=form.name, break;
field_description=form.description, form.manage_addField(
field_action='Base_edit', id='my_' + field_name.lower(),
field_update_action=form.update_action, fieldname= field_names_[field_types_[i]],
field_update_action_title=form.update_action_title, title= field_name)
field_enctype=form.enctype,
field_encoding=form.encoding, data_descriptor_module=portal_types["Data Descriptor Module"]
field_stored_encoding=form.stored_encoding, data_descriptor_module.setDefaultTypeAllowedContentType(data_type_name)
field_unicode_mode=form.unicode_mode,
field_method=form.method,
field_row_length=str(form.row_length),
field_pt='form_view',
field_edit_order=[]))
for i, field_name in enumerate(fields_):
if field_name == "None":
break;
form.manage_addField(
id='my_' + field_name.lower(),
fieldname= field_names_[field_types_[i]],
title= field_name)
k=portal_types["Data Descriptor Module"] # redirect to page saying created
p = k.setDefaultTypeAllowedContentType(descriptor_portal_type) if failed:
p = "Property Sheet, {} created! \n Portal type {} created!".format(property_sheet_name, descriptor_portal_type) redirect_url = '%s/%s?%s' % ( context.absolute_url()
print p , form_id
#editing stuff in the portal type , 'portal_status_message=' + failed_message
)
else:
redirect_url = '%s/%s?%s' % ( context.absolute_url()
, form_id
, 'portal_status_message=Data+Descriptor+Created.'
)
# Return a string identifying this script. request[ 'RESPONSE' ].redirect( redirect_url )
return printed
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>data_type_name, descriptor_id, descriptor_portal_type, property_sheet_name, field_1, field_1_type, field_2, field_2_type, field_3, field_3_type, field_4, field_4_type, field_5, field_5_type, field_6, field_6_type, field_7, field_7_type, field_8, field_8_type, field_9, field_9_type, field_10, field_10_type, form_id=\'\', **kw</string> </value> <value> <string>data_type_name, descriptor_id, property_sheet_name, field_1, field_1_type, field_2, field_2_type, field_3, field_3_type, field_4, field_4_type, field_5, field_5_type, field_6, field_6_type, field_7, field_7_type, field_8, field_8_type, field_9, field_9_type, field_10, field_10_type, form_id=\'\', **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -73,7 +73,6 @@ ...@@ -73,7 +73,6 @@
<value> <value>
<list> <list>
<string>your_data_type_name</string> <string>your_data_type_name</string>
<string>your_descriptor_portal_type</string>
<string>your_descriptor_id</string> <string>your_descriptor_id</string>
<string>your_property_sheet_name</string> <string>your_property_sheet_name</string>
</list> </list>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>your_descriptor_portal_type</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Descriptor Portal Type</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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