[Erp5-report] r19508 - in /experimental/Experimental: ./ patches/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 26 13:45:30 CET 2008


Author: bartek
Date: Tue Feb 26 13:45:28 2008
New Revision: 19508

URL: http://svn.erp5.org?rev=19508&view=rev
Log:
a list field which allows jump to its base category (if present and you can add categories there)

Added:
    experimental/Experimental/patches/ERP5Form_ListField_with_jump.py
Modified:
    experimental/Experimental/ZopePatch.py

Modified: experimental/Experimental/ZopePatch.py
URL: http://svn.erp5.org/experimental/Experimental/ZopePatch.py?rev=19508&r1=19507&r2=19508&view=diff
==============================================================================
--- experimental/Experimental/ZopePatch.py (original)
+++ experimental/Experimental/ZopePatch.py Tue Feb 26 13:45:28 2008
@@ -32,3 +32,6 @@
 
 LOG('EXPERIMENTAL monkey-patch', INFO, 'In disabled RadioField show translated title (not value)')
 from Products.Experimental.patches import Formulator_RadioField_show_title
+
+LOG('EXPERIMENTAL monkey-patch', INFO, 'ListField with jump to category if you have Add permission')
+from Products.Experimental.patches import ERP5Form_ListField_with_jump

Added: experimental/Experimental/patches/ERP5Form_ListField_with_jump.py
URL: http://svn.erp5.org/experimental/Experimental/patches/ERP5Form_ListField_with_jump.py?rev=19508&view=auto
==============================================================================
--- experimental/Experimental/patches/ERP5Form_ListField_with_jump.py (added)
+++ experimental/Experimental/patches/ERP5Form_ListField_with_jump.py Tue Feb 26 13:45:28 2008
@@ -1,0 +1,111 @@
+##############################################################################
+#
+# Copyright (c) 2007 ERP5 Polska. All Rights Reserved.
+#          Bartek Gorny <bartek at erp5.pl>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+##############################################################################
+
+"""
+  This patch makes a ListField show a jump to base_category it draws its items from,
+  but only if the user has "Add portal content" in this base_category
+  so that he can immediately start editing the right category.
+
+  RATIONALE: to facilitate site administration, esp. when building the structure
+  and if it is built by the client's staff. Normally they have to figure out first
+  which category is used and look it up in portal_categories, this way it is much faster
+  and easier. And can be switched off with one click in my_category_list library field.
+"""
+
+import string
+from DocumentTemplate.DT_Util import html_quote
+from Products.Formulator.DummyField import fields
+from Products.Formulator import Widget, Validator
+from Products.Formulator.Widget import render_element, render_tag
+from Products.CMFCore.utils import getToolByName
+
+Widget.ListWidget.allow_jump = fields.CheckBoxField('allow_jump',
+                                   title='Allow Jump',
+                                   description=("Do we allow to jump to the base category?"),
+                                   default=1,
+                                   required=0)
+
+Widget.ListWidget.base_category = fields.StringField('base_category',
+                             title='Base Category',
+                             description=("The category to edit (if missing we try do derive it from the field id)"),
+                             default="",
+                             required=0)
+
+Widget.ListWidget.property_names += ['allow_jump', 'base_category']
+
+# a hack because ParallelListField doesn't get it normally
+from Products.ERP5Form.ParallelListField import ParallelListWidget
+ParallelListWidget.property_names += ['allow_jump', 'base_category']
+
+
+def ListWidget_render_relation_link(self, field, value, REQUEST):
+  """
+    Render link to the base category (for those who can add something there)
+  """
+  html_string = ''
+  here = REQUEST['here']
+  # see if jump is allowed
+  allow_jump = field.get_value('allow_jump')
+  if not allow_jump:
+    return ''
+  portal_categories = getToolByName(here, 'portal_categories')
+  # base cat can be set explicitly on the field...
+  base_category = field.get_value('base_category')
+  # ...or derived from field id
+  if base_category == '':
+    field_id = field.id
+    if field_id.startswith('my_'):
+      field_id = field_id[3:]
+    if field_id.endswith('_list'):
+      field_id = field_id[:-5]
+    base_category = field_id
+  # get category
+  base_category_value = portal_categories.resolveCategory(base_category)
+  # check if category does exist
+  if base_category_value is None: 
+    return ''
+  # be lazy
+  portal_membership = getToolByName(here, 'portal_membership')
+  user = portal_membership.getAuthenticatedMember()
+  # check if user can not add categories
+  if not user.has_permission('Add portal content', base_category_value):
+    return '' 
+  portal_url = getToolByName(here, 'portal_url')
+  portal_url_string = portal_url()
+  html_string += '<a href="%s/view">' \
+                     '<img src="%s/images/jump.png" alt="jump" />' \
+                   '</a>' % (base_category_value.absolute_url(), portal_url_string)
+  return html_string
+
+
+def ListWidget_render(self, field, key, value, REQUEST):
+  rendered_items = self.render_items(field, key, value, REQUEST)
+  element = render_element('select',
+                          name=key,
+                          css_class=field.get_value('css_class'),
+                          size=field.get_value('size'),
+                          contents=string.join(rendered_items, "\n"),
+                          extra=field.get_value('extra'))
+
+  return element + self.render_relation_link(field, value, REQUEST)
+
+  
+Widget.ListWidget.render_relation_link = ListWidget_render_relation_link
+Widget.ListWidget.render = ListWidget_render




More information about the Erp5-report mailing list