[Erp5-report] r43610 nicolas - /erp5/trunk/products/ERP5Form/MultiRelationField.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Feb 23 15:37:11 CET 2011


Author: nicolas
Date: Wed Feb 23 15:37:11 2011
New Revision: 43610

URL: http://svn.erp5.org?rev=43610&view=rev
Log:
Add new option on (Multi)RelationFields to enable edition of distant objects other than current context: context_getter_id
It will be useful to some properties on object hidden to users.
like edit assignment's subordination from Person_view;
     edit Arrow categories of Open Sale Order Lines from Subscription Items;
     any many others use cases...

Modified:
    erp5/trunk/products/ERP5Form/MultiRelationField.py

Modified: erp5/trunk/products/ERP5Form/MultiRelationField.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/MultiRelationField.py?rev=43610&r1=43609&r2=43610&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/MultiRelationField.py [utf8] (original)
+++ erp5/trunk/products/ERP5Form/MultiRelationField.py [utf8] Wed Feb 23 15:37:11 2011
@@ -61,7 +61,8 @@ class MultiRelationStringFieldWidget(Wid
   """
   local_property_names = ['update_method', 'jump_method', 'allow_jump', 
                           'base_category', 'portal_type', 'allow_creation', 
-                          'container_getter_id', 'catalog_index',
+                          'container_getter_id', 'context_getter_id',
+                          'catalog_index',
                           'relation_setter_id', 'relation_form_id', 'columns', 
                           'sort', 'parameter_list','list_method', 
                           'first_item', 'items', 'proxy_listbox_ids', 
@@ -122,6 +123,13 @@ class MultiRelationStringFieldWidget(Wid
                              default="",
                              required=0)
 
+  context_getter_id = fields.StringField('context_getter_id',
+                             title='Context Getter Method',
+                             description=(
+      "The method to call to get the context."),
+                             default="",
+                             required=0)
+
   catalog_index = fields.StringField('catalog_index',
                              title='Catalog Index',
                              description=(
@@ -200,6 +208,16 @@ class MultiRelationStringFieldWidget(Wid
 
   default_widget_rendering_instance = Widget.LinesTextAreaWidgetInstance
 
+  def _getContextValue(self, field, REQUEST):
+    """Return result of evaluated method
+    defined by context_getter_id or here.
+    """
+    context_getter_id =  field.get_value('context_getter_id')
+    here = REQUEST['here']
+    if context_getter_id:
+      return getattr(here, context_getter_id)()
+    return here
+
   def _generateRenderValueList(self, field, key, value_list, REQUEST):
     result_list = []
     need_validation = 0
@@ -305,7 +323,7 @@ class MultiRelationStringFieldWidget(Wid
     Render read only field.
     """
     html_string = ''
-    here = REQUEST['here']
+    here = self._getContextValue(field, REQUEST)
     portal_url = getToolByName(here, 'portal_url')
     portal_url_string = portal_url()
     if (value not in ((), [], None, '')) and \
@@ -338,7 +356,7 @@ class MultiRelationStringFieldWidget(Wid
     """
     Render wheel used to display a listbox
     """
-    here = REQUEST['here']
+    here = self._getContextValue(field, REQUEST)
     portal_url = getToolByName(here, 'portal_url')
     portal_url_string = portal_url()
     portal_selections_url_string = here.portal_url.getRelativeContentURL(here.portal_selections)
@@ -358,7 +376,7 @@ class MultiRelationStringFieldWidget(Wid
     Render link to the related object.
     """
     html_string = ''
-    here = REQUEST['here']
+    here = self._getContextValue(field, REQUEST)
     portal_url = getToolByName(here, 'portal_url')
     portal_url_string = portal_url()
     if (value not in ((), [], None, '')) and \
@@ -389,7 +407,8 @@ class MultiRelationEditor:
     def __init__(self, field_id, base_category, 
                  portal_type_list, 
                  portal_type_item, key, relation_setter_id, 
-                 relation_editor_list):
+                 relation_editor_list,
+                 context_getter_id):
       self.field_id = field_id
       self.base_category = base_category
       self.portal_type_list = portal_type_list
@@ -397,6 +416,7 @@ class MultiRelationEditor:
       self.key = key
       self.relation_setter_id = relation_setter_id
       self.relation_editor_list = relation_editor_list
+      self.context_getter_id = context_getter_id
 
     def __call__(self, REQUEST):
       if self.relation_editor_list != None:
@@ -422,6 +442,8 @@ class MultiRelationEditor:
 
     def edit(self, o):
       if self.relation_editor_list is not None:
+        if self.context_getter_id:
+          o = getattr(o, self.context_getter_id)()
         portal = o.getPortalObject()
 
         relation_object_list = []
@@ -779,11 +801,13 @@ class MultiRelationStringFieldValidator(
       base_category = field.get_value('base_category')
       portal_type_item = field.get_value('portal_type')
       relation_setter_id = field.get_value('relation_setter_id')
+      context_getter_id = field.get_value('context_getter_id')
       return self.editor(field.id, 
                          base_category,
                          portal_type_list, 
                          portal_type_item, catalog_index, 
-                         relation_setter_id, relation_editor_list)
+                         relation_setter_id, relation_editor_list,
+                         context_getter_id)
 
 MultiRelationStringFieldWidgetInstance = MultiRelationStringFieldWidget()
 MultiRelationStringFieldValidatorInstance = MultiRelationStringFieldValidator()



More information about the Erp5-report mailing list