From 38f71be89aafd08bc0f65da503882d04ad637955 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Wed, 19 Jan 2011 20:51:43 +0100 Subject: [PATCH] Added method 'unlink' on any appy class, for unlinking objects from references. Bugfixes in display of workflow state in columns. --- gen/plone25/mixins/ToolMixin.py | 2 +- gen/plone25/mixins/__init__.py | 6 +++--- gen/plone25/skin/widgets/ref.pt | 7 ++++--- gen/plone25/wrappers/__init__.py | 28 ++++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gen/plone25/mixins/ToolMixin.py b/gen/plone25/mixins/ToolMixin.py index a9b2254..ad2942b 100644 --- a/gen/plone25/mixins/ToolMixin.py +++ b/gen/plone25/mixins/ToolMixin.py @@ -482,7 +482,7 @@ class ToolMixin(BaseMixin): (p_usage can be "ref" or "search")?''' if (',' in className) or (name == 'workflowState'): return False appyType = self.getAppyType(name, className=className) - return appyType.isSortable(usage=usage) + if appyType: return appyType.isSortable(usage=usage) def _searchValueIsEmpty(self, key): '''Returns True if request value in key p_key can be considered as diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index f22b215..e1e0f7c 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -509,7 +509,7 @@ class BaseMixin: for name in fieldNames: appyType = self.getAppyType(name, asDict) if appyType: res.append(appyType) - elif name == 'workflowState': + elif name == 'state': # We do not return a appyType if the attribute is not a *real* # attribute, but the workfow state. res.append({'name': name, 'labelId': 'workflow_state', @@ -1044,7 +1044,7 @@ class BaseMixin: params = '' return '%s%s' % (base, params) - def getLanguage(self): + def getUserLanguage(self): '''Gets the language (code) of the current user.''' # Try first the "LANGUAGE" key from the request res = self.REQUEST.get('LANGUAGE', None) @@ -1076,7 +1076,7 @@ class BaseMixin: else: # We will get the translation from a Translation object. # In what language must we get the translation? - if not language: language = self.getLanguage() + if not language: language = self.getUserLanguage() tool = self.getTool() try: translation = getattr(tool, language).appy() diff --git a/gen/plone25/skin/widgets/ref.pt b/gen/plone25/skin/widgets/ref.pt index 7a7110d..7f4c42e 100644 --- a/gen/plone25/skin/widgets/ref.pt +++ b/gen/plone25/skin/widgets/ref.pt @@ -78,7 +78,8 @@ ref field according to the field that corresponds to this column. + tal:define="ajaxBaseCall python: navBaseCall.replace('**v**', '\'%s\',\'SortReference\', {\'sortKey\':\'%s\', \'reverse\':\'**v**\'}' % (startNumber, widget['name']))" + tal:condition="python: canWrite and tool.isSortable(widget['name'], objs[0].meta_type, 'ref')"> @@ -198,10 +199,10 @@ - - + diff --git a/gen/plone25/wrappers/__init__.py b/gen/plone25/wrappers/__init__.py index b80bbd6..ea0de66 100644 --- a/gen/plone25/wrappers/__init__.py +++ b/gen/plone25/wrappers/__init__.py @@ -89,8 +89,8 @@ class AbstractWrapper: fields = property(get_fields) def link(self, fieldName, obj): - '''This method links p_obj to this one through reference field - p_fieldName. p_obj can also be a list or tuple of objects.''' + '''This method links p_obj (which can be a list of objects) to this one + through reference field p_fieldName.''' postfix = 'et%s%s' % (fieldName[0].upper(), fieldName[1:]) # Update the Archetypes reference field exec 'objs = self.o.g%s()' % postfix @@ -111,6 +111,30 @@ class AbstractWrapper: else: sorted.append(obj.o.UID()) + def unlink(self, fieldName, obj): + '''This method unlinks p_obj (which can be a list of objects) from this + one through reference field p_fieldName.''' + postfix = 'et%s%s' % (fieldName[0].upper(), fieldName[1:]) + # Update the Archetypes reference field. + exec 'objs = self.o.g%s()' % postfix + if not objs: return + # Remove p_obj from existing objects + if type(obj) in sequenceTypes: + for o in obj: + if o.o in objs: objs.remove(o.o) + else: + if obj.o in objs: objs.remove(obj.o) + exec 'self.o.s%s(objs)' % postfix + # Update the ordered list of references + sorted = self.o._appy_getSortedField(fieldName) + if type(obj) in sequenceTypes: + for o in obj: + if o.o.UID() in sorted: + sorted.remove(o.o.UID()) + else: + if obj.o.UID() in sorted: + sorted.remove(obj.o.UID()) + def sort(self, fieldName, sortKey='title', reverse=False): '''Sorts referred elements linked to p_self via p_fieldName according to a given p_sortKey which must be an attribute set on referred