From cee7b49e3c1acba59a4a4e801eaa644b956a299e Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 25 Apr 2014 12:14:50 +0200 Subject: [PATCH] [gen] Added method Mixin.onCall allowing to call a specific method on a gen-class from the UI. --- fields/ref.py | 24 ++++++++++++++---------- gen/mixins/__init__.py | 9 ++++++++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/fields/ref.py b/fields/ref.py index 5ef7e08..576dff0 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -62,7 +62,7 @@ class Ref(Field): style=":'%s; %s' % (url('linkMany', bg=True), \ ztool.getButtonWidth(label))"/> - - - + @@ -142,9 +141,10 @@ class Ref(Field): # Displays the button allowing to add a new object through a Ref field, if # it has been declared as addable and if multiplicities allow it. pxAdd = Px(''' - :totalNumber) :field.pxAdd - +
@@ -376,6 +378,8 @@ class Ref(Field): folder=zobj.getCreateFolder(); tiedClassName=ztool.getPortalType(field.klass); canWrite=not field.isBack and zobj.allows(field.writePermission); + mayUnlink=not isBack and canWrite and \ + field.getAttribute(zobj, 'unlink'); showPlusIcon=field.mayAdd(zobj); atMostOneRef=(field.multiplicity[1]==1) and (len(objects)<=1); addConfirmMsg=field.addConfirm and \ diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 8752910..b96fd83 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -1180,7 +1180,7 @@ class BaseMixin: rq = self.getProductConfig().fakeRequest if not hasattr(rq, 'wrappers'): rq.wrappers = {} # Return the Appy wrapper if already present in the cache - uid = self.UID() + uid = self.id if uid in rq.wrappers: return rq.wrappers[uid] # Create the Appy wrapper, cache it in rq.wrappers and return it wrapper = self.wrapperClass(self) @@ -1559,4 +1559,11 @@ class BaseMixin: '''This method is a general hook for transfering processing of a request to a given field, whose name must be in the request.''' return self.getAppyType(self.REQUEST['name']).process(self) + + def onCall(self): + '''Calls a specific method on the corresponding wrapper.''' + self.allows('read', raiseError=True) + method = self.REQUEST['method'] + obj = self.appy() + return getattr(obj, method)() # ------------------------------------------------------------------------------