Commit 9ea10e11 authored by Charles's avatar Charles

Added checks for existing portal_type, property_sheet names

parent 1cd8b3cd
...@@ -13,15 +13,21 @@ fields_ = [field_1, field_2, field_3, field_4, field_5, ...@@ -13,15 +13,21 @@ 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:
failed_message += "Property+sheet+name+already+taken. "
failed = 1
else:
module_new_property_sheet = property_sheets.newContent(id = property_sheet_name)
for i, field_name in enumerate(fields_):
if field_name == "None": if field_name == "None":
break; break;
module_new_property_sheet.newContent( module_new_property_sheet.newContent(
...@@ -30,36 +36,41 @@ for i, field_name in enumerate(fields_): ...@@ -30,36 +36,41 @@ for i, field_name in enumerate(fields_):
elementary_type=ele_types[field_types_[i]]) 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:
failed_message += "Property+type+name+already+taken\n"
failed = 1
else:
module_portal_type_value = portal_types.newContent(id=descriptor_id,
title = data_type_name,
portal_type='Base Type', portal_type='Base Type',
type_factory_method_id='Item', type_class='Item',
type_property_Sheet=property_sheet_name) type_property_Sheet=property_sheet_name)
#adding a view #adding a view
module_portal_type_value.setTranslationDomain('title', 'erp5_ui') module_portal_type_value.setTranslationDomain('title', 'erp5_ui')
module_portal_type_value.setTranslationDomain('short_title', 'erp5_ui') module_portal_type_value.setTranslationDomain('short_title', 'erp5_ui')
module_list_form_id = ('%s_view%s' % ("DataDescriptor", module_list_form_id = ('%s_view%s' % ("DataDescriptor",
descriptor_portal_type)).replace(' ', '') data_type_name)).replace(' ', '')
module_portal_type_value.newContent(portal_type='Action Information', module_portal_type_value.newContent(portal_type='Action Information',
reference="view", reference="view",
title="View", title="View",
action="string:${object_url}/%s" % module_list_form_id, action="string:${object_url}/%s" % module_list_form_id,
action_type="object_list") 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( form.manage_settings(
dict(field_title=form.title, dict(field_title=form.title,
field_name=form.name, field_name=form.name,
field_description=form.description, field_description=form.description,
...@@ -75,7 +86,7 @@ form.manage_settings( ...@@ -75,7 +86,7 @@ form.manage_settings(
field_pt='form_view', field_pt='form_view',
field_edit_order=[])) field_edit_order=[]))
for i, field_name in enumerate(fields_): for i, field_name in enumerate(fields_):
if field_name == "None": if field_name == "None":
break; break;
form.manage_addField( form.manage_addField(
...@@ -83,12 +94,20 @@ for i, field_name in enumerate(fields_): ...@@ -83,12 +94,20 @@ for i, field_name in enumerate(fields_):
fieldname= field_names_[field_types_[i]], fieldname= field_names_[field_types_[i]],
title= field_name) title= field_name)
k=portal_types["Data Descriptor Module"] data_descriptor_module=portal_types["Data Descriptor Module"]
p = k.setDefaultTypeAllowedContentType(descriptor_portal_type) data_descriptor_module.setDefaultTypeAllowedContentType(data_type_name)
p = "Property Sheet, {} created! \n Portal type {} created!".format(property_sheet_name, descriptor_portal_type)
print p # redirect to page saying created
#editing stuff in the portal type if failed:
redirect_url = '%s/%s?%s' % ( context.absolute_url()
, form_id
, '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