From cb216a9e9cc77d87a19e3a6ef9920734aa40029e Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 30 Apr 2010 14:43:44 +0200 Subject: [PATCH] Bugfixes in new sorting/filtering features. --- gen/__init__.py | 9 +++++++++ gen/plone25/mixins/__init__.py | 7 +++++++ gen/plone25/skin/macros.pt | 2 +- gen/plone25/skin/ref.pt | 7 +++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gen/__init__.py b/gen/__init__.py index 261daa8..8ef53ae 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -189,6 +189,15 @@ class Type: res = True return res + def isSortable(self, usage='search'): + '''Can fields of this type be used for sorting purposes (when sorting + search results (p_usage="search") or when sorting reference fields + (p_usage="ref")?''' + if usage == 'search': return self.indexed + elif usage == 'ref': + return self.type in ('Integer', 'Float', 'Boolean', 'Date') or \ + ((self.type == 'String') and (self.format == 0)) + class Integer(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show=True, diff --git a/gen/plone25/mixins/__init__.py b/gen/plone25/mixins/__init__.py index 82ece9c..3323f40 100644 --- a/gen/plone25/mixins/__init__.py +++ b/gen/plone25/mixins/__init__.py @@ -668,6 +668,13 @@ class AbstractMixin: reverse = rq.get('reverse') == 'True' self.appy().sort(fieldName, sortKey=sortKey, reverse=reverse) + def isRefSortable(self, fieldName): + '''Can p_fieldName, which is a field defined on self, be used as a sort + key in a reference field?''' + appyType = self.getAppyType(fieldName, asDict=False) + if not appyType: return True # Probably implicit field 'title'. + return appyType.isSortable(usage='ref') + def getWorkflow(self, appy=True): '''Returns the Appy workflow instance that is relevant for this object. If p_appy is False, it returns the DC workflow.''' diff --git a/gen/plone25/skin/macros.pt b/gen/plone25/skin/macros.pt index 153c91d..7473154 100644 --- a/gen/plone25/skin/macros.pt +++ b/gen/plone25/skin/macros.pt @@ -857,7 +857,7 @@ class="listing nosort" width="100%" cellpadding="0" cellspacing="0"> Every item in fieldDescr is a FieldDescr instance, excepted for workflow state (which is not a field): in this case it is simply the - string "workflowState". + string "workflow_state". Headers, with filters and sort arrows diff --git a/gen/plone25/skin/ref.pt b/gen/plone25/skin/ref.pt index 405195c..dc2f077 100644 --- a/gen/plone25/skin/ref.pt +++ b/gen/plone25/skin/ref.pt @@ -68,14 +68,12 @@ 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, shownField))" tal:condition="python: canWrite and objs[0].isRefSortable(shownField)"> @@ -122,9 +120,10 @@ flavour python:tool.getFlavour(contextObj); linkedPortalType python:flavour.getPortalType(appyType['klass']); addPermission python: '%s: Add %s' % (tool.getAppName(), linkedPortalType); + canWrite python: not isBack and member.has_permission(contextObj.getField(fieldName).write_permission, contextObj); multiplicity python:test(isBack, appyType['backd']['multiplicity'], appyType['multiplicity']); maxReached python:(multiplicity[1] != None) and (len(objs) >= multiplicity[1]); - showPlusIcon python:not isBack and appyType['add'] and not maxReached and member.has_permission(addPermission, folder); + showPlusIcon python:not isBack and appyType['add'] and not maxReached and member.has_permission(addPermission, folder) and canWrite; atMostOneRef python: (multiplicity[1] == 1) and (len(objs)<=1); label python: tool.translate(labelId); description python: tool.translate(descrId);