From 0b4e78bf83e59e4b7296d13f850a250faa9de1dd Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 17 Feb 2015 12:50:44 +0100 Subject: [PATCH] [gen] Removed pxViewPickList, replaced by a recursive call pxView->pxView. --- fields/ref.py | 114 ++++++++++++++++++--------------------- gen/wrappers/__init__.py | 11 ++-- 2 files changed, 57 insertions(+), 68 deletions(-) diff --git a/fields/ref.py b/fields/ref.py index 1fb8fdd..3da2014 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -295,39 +295,6 @@ class Ref(Field): ''') - # PX that displays the list of objects the user may select to insert into a - # ref field with link="list". - pxViewPickList = Px(''' - :field.pxViewList''') - # PX that displays referred objects as dropdown menus. pxMenu = Px(''' :', '.join(infos) or _('no_ref')''') - # PX that displays referred objects through this field. In mode link="list", - # if, in the request, key "scope" is present and holds value "objs", the - # pick list (containing possible values) will not be rendered. + # PX that displays referred objects through this field. + # In mode link="list", if request key "scope" is: + # - not in the request, the whole field is shown (both available and already + # tied objects); + # - "objs", only tied objects are rendered; + # - "poss", only available objects are rendered (the pick list). + # ! scope is forced to "objs" on non-view "inner" (cell, buttons) layouts. pxView = Px(''' - - - :field.pxViewPickList + + + :field.pxView + :field.pxViewList + var2="subLabel=field.getListLabel(inPickList)">:field.pxViewList :getattr(field, 'pxView%s' % \ render.capitalize()) ''') @@ -888,8 +862,8 @@ class Ref(Field): # Indeed, in this case, unlike m_getValue, we already have all objects # in "objects": we can't limit objects "waking up" to at most # self.maxPerPage. + total = len(objects) if paginated and not isSearch: - total = len(objects) objects = objects[startNumber:startNumber + self.maxPerPage] # Return the result, wrapped in a SomeObjects instance if required if not someObjects: @@ -903,6 +877,17 @@ class Ref(Field): res.objects = objects return res + def getViewValues(self, obj, startNumber, scope): + '''Gets the values as must be shown on pxView. If p_scope is "poss", it + is the list of possible, not-yet-linked, values. Else, it is the list + of linked values. In both cases, we take the subset starting at + p_startNumber.''' + if scope == 'poss': + return self.getPossibleValues(obj, startNumber=startNumber, + someObjects=True, removeLinked=True) + # Return the list of already linked values + return self.getValue(obj, startNumber=startNumber, someObjects=True) + def getLinkedObjectsByMenu(self, obj, objects): '''This method groups p_objects into sub-lists of objects, grouped by menu (happens when self.render == 'menus').''' @@ -1220,6 +1205,13 @@ class Ref(Field): if not inMenu: return obj.translate('add_ref') return tiedClassLabel + def getListLabel(self, inPickList): + '''If self.link == "list", a label must be shown in front of the list. + Moreover, the label is different if the list is a pick list or the + list of tied objects.''' + if self.link != 'list': return + return inPickList and 'selectable_objects' or 'selected_objects' + def mayUnlinkElement(self, obj, tied, raiseError=False): '''May we unlink from this Ref field this specific p_tied object?''' if not self.unlinkElement: return True @@ -1267,11 +1259,9 @@ class Ref(Field): # Complete params with default parameters params['ajaxHookId'] = hook; params['scope'] = hook.rsplit('_', 1)[-1] - px = (params['scope'] == 'poss') and 'pxViewPickList' or 'pxView' - px = '%s:%s' % (self.name, px) params = sutils.getStringDict(params) - return "new AjaxData('%s', '%s', %s, null, '%s')" % \ - (hook, px, params, zobj.absolute_url()) + return "new AjaxData('%s', '%s:pxView', %s, null, '%s')" % \ + (hook, self.name, params, zobj.absolute_url()) def getAjaxDataRow(self, obj, parentHook, **params): '''Initializes an AjaxData object on the DOM node corresponding to diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index 4f12fb9..89ec0b1 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -607,13 +607,12 @@ class AbstractWrapper(object): tiedClassName=ztool.getPortalType(field.klass); target=ztool.getLinksTargetInfo(field.klass, zobj.id); mayEdit=not field.isBack and zobj.mayEdit(field.writePermission); - mayLink=not inPickList and mayEdit and \ - field.mayAdd(zobj, mode='link', checkMayEdit=False); - mayUnlink=not inPickList and mayEdit and \ - field.getAttribute(zobj, 'unlink'); + mayEd=not inPickList and mayEdit; + mayLink=mayEd and field.mayAdd(zobj, mode='link', \ + checkMayEdit=False); + mayUnlink=mayEd and field.getAttribute(zobj, 'unlink'); gotoNumber=numbered; - changeOrder=not inPickList and mayEdit and \ - field.getAttribute(zobj, 'changeOrder'); + changeOrder=mayEd and field.getAttribute(zobj, 'changeOrder'); changeNumber=not inPickList and numbered and changeOrder and \ (totalNumber > 3); columns=ztool.getColumnsSpecifiers(tiedClassName, \