Commit a0effd84 authored by Jérome Perrin's avatar Jérome Perrin

Introspect preference properties instead of hardcoding

parent 0473f076
...@@ -55,35 +55,21 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -55,35 +55,21 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore ) , PropertySheet.DublinCore )
def _getPreferenceNameList(self): def _getPreferenceNameList(self):
"""Returns all existing preference names. """Return names of preference properties.
TODO: this should be done by introspecting property sheet.
""" """
return ( 'preferred_category_child_item_list_method_id', property_id_list = []
'preferred_accounting_transaction_from_date', portal = self.getPortalObject()
'preferred_accounting_transaction_at_date', for property_sheet_id in portal.portal_types.Preference.getTypePropertySheetList():
'preferred_section_category', property_sheet = portal.portal_property_sheets[property_sheet_id]
'preferred_section', for prop in property_sheet.contentValues():
'preferred_accounting_transaction_section_category', if prop.getProperty('preference'):
'preferred_accounting_transaction_source_section', list_prefix = ''
'preferred_accounting_transaction_currency', if prop.getProperty('multivalued') or (
'preferred_accounting_transaction_gap', prop.getProperty('elementary_type') in (
'preferred_accounting_transaction_simulation_state_list', 'lines', 'multiple_selection', 'tokens')):
'preferred_text_format', list_prefix = '_list'
'preferred_text_editor', property_id_list.append('%s%s' % (prop.getReference(), list_prefix))
'preferred_date_order', return property_id_list
'preferred_listbox_view_mode_line_count',
'preferred_listbox_list_mode_line_count',
'preferred_string_field_width',
'preferred_textarea_width',
'preferred_textarea_height',
'preferred_money_quantity_field_width',
'preferred_quantity_field_width',
'preferred_report_style',
'preferred_report_format',
'preferred_html_style_access_tab',
)
def _build(self, business_configuration): def _build(self, business_configuration):
portal = self.getPortalObject() portal = self.getPortalObject()
...@@ -103,7 +89,7 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -103,7 +89,7 @@ class PreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
for preference_name in self._getPreferenceNameList(): for preference_name in self._getPreferenceNameList():
preference_value = getattr(self, preference_name, preference_value = getattr(self, preference_name,
preference.getProperty(preference_name, marker)) preference.getProperty(preference_name, marker))
if preference_value is not marker: if preference_value is not marker and preference_value is not None:
preference_dict[preference_name] = preference_value preference_dict[preference_name] = preference_value
if self.portal_workflow.isTransitionPossible(preference, 'enable'): if self.portal_workflow.isTransitionPossible(preference, 'enable'):
......
...@@ -55,43 +55,22 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -55,43 +55,22 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
, PropertySheet.DublinCore ) , PropertySheet.DublinCore )
def _getPreferenceNameList(self): def _getPreferenceNameList(self):
"""Returns all existing preference names. """Return names of preference properties.
TODO: this should be done by introspecting property sheet.
""" """
return ( # CRM property_id_list = []
'preferred_campaign_resource_list', portal = self.getPortalObject()
'preferred_event_assessment_form_id_list', for property_sheet_id in portal.portal_types[
'preferred_event_resource_list', 'System Preference'].getTypePropertySheetList():
'preferred_event_sender_email', property_sheet = portal.portal_property_sheets[property_sheet_id]
'preferred_meeting_resource_list', for prop in property_sheet.contentValues():
'preferred_sale_opportunity_resource_list', if prop.getProperty('preference'):
'preferred_support_request_resource_list', list_prefix = ''
# DMS if prop.getProperty('multivalued') or (
'preferred_conversion_cache_factory', prop.getProperty('elementary_type') in (
'preferred_document_email_ingestion_address', 'lines', 'multiple_selection', 'tokens')):
'preferred_document_reference_method_id', list_prefix = '_list'
'preferred_document_file_name_regular_expression', property_id_list.append('%s%s' % (prop.getReference(), list_prefix))
'preferred_document_reference_regular_expression', return property_id_list
'preferred_document_classification',
'preferred_synchronous_metadata_discovery',
'preferred_redirect_to_document',
'preferred_ooodoc_server_address',
'preferred_ooodoc_server_port_number',
# PDM
'preferred_product_individual_variation_base_category_list',
'preferred_component_individual_variation_base_category_list',
'preferred_service_individual_variation_base_category_list',
# Trade
'preferred_supplier_role_list',
'preferred_client_role_list',
'preferred_sale_use_list',
'preferred_purchase_use_list',
'preferred_packing_use_list',
'preferred_tax_use_list',
# Express
)
def _build(self, business_configuration): def _build(self, business_configuration):
portal = self.getPortalObject() portal = self.getPortalObject()
...@@ -112,9 +91,9 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject): ...@@ -112,9 +91,9 @@ class SystemPreferenceConfiguratorItem(ConfiguratorItemMixin, XMLObject):
for preference_name in self._getPreferenceNameList(): for preference_name in self._getPreferenceNameList():
preference_value = getattr(self, preference_name, preference_value = getattr(self, preference_name,
preference.getProperty(preference_name, marker)) preference.getProperty(preference_name, marker))
if preference_value is None and activated_preference is not None: if preference_value is marker and activated_preference is not None:
preference_value = activated_preference.getProperty(preference_name) preference_value = activated_preference.getProperty(preference_name, marker)
if preference_value is not marker: if preference_value is not marker and preference_value is not None:
preference_dict[preference_name] = preference_value preference_dict[preference_name] = preference_value
if self.portal_workflow.isTransitionPossible(preference, 'enable'): if self.portal_workflow.isTransitionPossible(preference, 'enable'):
......
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