Commit 1cd8b3cd authored by Charles's avatar Charles

Dialog to create new property and portal type in the Data Descriptor module.

parent 8a9ba2e1
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
response = request.response
portal = context.getPortalObject()
portal_types = portal.portal_types
# if request.get('field_prefix', None):
# field_prefix = 'your_'
fields_ = [field_1, field_2, field_3, field_4, field_5,
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_6_type, field_7_type, field_8_type, field_9_type, field_10_type]
ele_types = {'Integer':'int', 'String':'string', 'Float':'float'}
field_names_ = {'Integer':'IntegerField', 'String':'StringField', 'Float': 'FloatField'}
property_sheets = portal.portal_property_sheets
# Create new property sheet with fields
module_new_property_sheet = property_sheets.newContent(id = property_sheet_name)
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
module_portal_type_value = portal_types.newContent(id=descriptor_portal_type,
portal_type='Base Type',
type_factory_method_id='Item',
type_property_Sheet=property_sheet_name)
#adding a view
module_portal_type_value.setTranslationDomain('title', 'erp5_ui')
module_portal_type_value.setTranslationDomain('short_title', 'erp5_ui')
module_list_form_id = ('%s_view%s' % ("DataDescriptor",
descriptor_portal_type)).replace(' ', '')
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
portal_skins_folder_name = "woelfel_viblab_meda"
portal_skins = portal.portal_skins
skin_folder = portal.portal_skins[portal_skins_folder_name]
factory = skin_folder.manage_addProduct['ERP5Form']
factory.addERP5Form(module_list_form_id, title=data_type_name)
form = skin_folder[module_list_form_id]
default_groups = ['bottom', 'hidden']
for group in default_groups:
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=[]))
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"]
p = k.setDefaultTypeAllowedContentType(descriptor_portal_type)
p = "Property Sheet, {} created! \n Portal type {} created!".format(property_sheet_name, descriptor_portal_type)
print p
#editing stuff in the portal type
# Return a string identifying this script.
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</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>_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>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DataDescriptor_createDataDescriptorType</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>DataDescriptor_createDataDescriptorType</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Create a new Data Descriptor</string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string>multipart/form-data</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>bottom R</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>bottom R</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>your_data_type_name</string>
<string>your_descriptor_portal_type</string>
<string>your_descriptor_id</string>
<string>your_property_sheet_name</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list>
<string>your_field_1</string>
<string>your_field_1_type</string>
<string>your_field_2</string>
<string>your_field_2_type</string>
<string>your_field_3</string>
<string>your_field_3_type</string>
<string>your_field_4</string>
<string>your_field_4_type</string>
<string>your_field_5</string>
<string>your_field_5_type</string>
<string>your_field_6</string>
<string>your_field_6_type</string>
<string>your_field_7</string>
<string>your_field_7_type</string>
<string>your_field_8</string>
<string>your_field_8_type</string>
<string>your_field_9</string>
<string>your_field_9_type</string>
<string>your_field_10</string>
<string>your_field_10_type</string>
</list>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>DataDescriptor_viewCreateDataDescriptorTypeDialog</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>DataDescriptor_viewCreateDataDescriptorType</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create New Data Descriptor Type</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_data_type_name</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>Data Type Name</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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_id</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 ID</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?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