From 40e8a5f258b042f68812b17ef3c5cb8414155b7a Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 27 Mar 2012 15:49:41 +0200 Subject: [PATCH] appy.gen: bugfix while using Zope behind Apache and using the VHM; Ref.view macro is not called via Ajax anymore for single-valued Refs (when displaying lists containing single-valued Ref fields, it produces too many ajax requests, leading to ConflictErrors in the ZODB). --- gen/__init__.py | 24 +++++++++++++++++++++++ gen/mixins/__init__.py | 13 +++++++++---- gen/ui/appy.css | 4 ++-- gen/ui/portlet.pt | 9 ++++----- gen/ui/widgets/ref.pt | 43 +++++++++++++++++++++++------------------- 5 files changed, 63 insertions(+), 30 deletions(-) diff --git a/gen/__init__.py b/gen/__init__.py index 2236535..d3fd745 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -1926,6 +1926,30 @@ class Ref(Type): res.select = None # Not callable from tool. return res + def mayAdd(self, obj, folder): + '''May the user create a new referred object to p_obj via this Ref, + in p_folder?''' + # We can't (yet) do that on back references. + if self.isBack: return + # Check if this Ref is addable + if callable(self.add): + add = self.callMethod(obj, self.add) + else: + add = self.add + if not add: return + # Have we reached the maximum number of referred elements? + if self.multiplicity[1] != None: + refCount = len(getattr(obj, self.name, ())) + if refCount >= self.multiplicity[1]: return + # May the user edit this Ref field? + if not obj.allows(self.writePermission): return + # Have the user the correct add permission on p_folder? + tool = obj.getTool() + addPermission = '%s: Add %s' % (tool.getAppName(), + tool.getPortalType(self.klass)) + if not obj.getUser().has_permission(addPermission, folder): return + return True + class Computed(Type): def __init__(self, validator=None, multiplicity=(0,1), index=None, default=None, optional=False, editDefault=False, show='view', diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 51594df..61b8e58 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -302,15 +302,15 @@ class BaseMixin: '''Reindexes this object the catalog. If names of indexes are specified in p_indexes, recataloging is limited to those indexes. If p_unindex is True, instead of cataloguing the object, it uncatalogs it.''' - url = self.absolute_url_path() + path = '/'.join(self.getPhysicalPath()) catalog = self.getPhysicalRoot().catalog if unindex: - catalog.uncatalog_object(url) + catalog.uncatalog_object(path) else: if indexes: - catalog.catalog_object(self, url, idxs=indexes) + catalog.catalog_object(self, path, idxs=indexes) else: - catalog.catalog_object(self, url) + catalog.catalog_object(self, path) def say(self, msg, type='info'): '''Prints a p_msg in the user interface. p_logLevel may be "info", @@ -533,6 +533,11 @@ class BaseMixin: if not refs: raise IndexError() return refs.index(obj.UID()) + def mayAddReference(self, name, folder): + '''May the user add references via Ref field named p_name in + p_folder?''' + return self.getAppyType(name).mayAdd(self, folder) + def isDebug(self): '''Are we in debug mode ?''' for arg in sys.argv: diff --git a/gen/ui/appy.css b/gen/ui/appy.css index 57a24b9..81540cf 100644 --- a/gen/ui/appy.css +++ b/gen/ui/appy.css @@ -59,8 +59,8 @@ img {border: 0} .portletSep { border-top: 1px solid #5F7983; margin-top: 2px;} .portletPage { font-style: italic; } .portletGroup { font-variant: small-caps; font-weight: bold; font-style: normal; - margin: 0.4em 0 0.2em 0; } -.phase { border-style: dashed; border-width: thin; padding: 0 0.6em 5px 1em;} + margin: 0 0 0.2em 0; } +.phase { border-style: dashed; border-width: thin; padding: 4px 0.6em 5px 1em;} .phaseSelected { background-color: #F4F5F6; } .content { padding: 14px 14px 9px 15px;} .grey { display: none; position: absolute; left: 0px; top: 0px; diff --git a/gen/ui/portlet.pt b/gen/ui/portlet.pt index dfa2563..f95fa4c 100644 --- a/gen/ui/portlet.pt +++ b/gen/ui/portlet.pt @@ -106,21 +106,20 @@ tal:condition="python: phases" width="100%"> The box containing phase-related information - + The title of the phase -
The page(s) within the phase - +
1st line: page name and icons - +
diff --git a/gen/ui/widgets/ref.pt b/gen/ui/widgets/ref.pt index 545d20e..013a311 100644 --- a/gen/ui/widgets/ref.pt +++ b/gen/ui/widgets/ref.pt @@ -88,22 +88,34 @@ View macro for a Ref. -
- -
+ + + For performance reasons, multivalued references are called via Ajax, while single-valued aren't. + + +
+ +
+
+
+ + + +
+
- This macro is called by a XmlHttpRequest for displaying the paginated - referred objects of a reference field. + This macro is called by a XmlHttpRequest (or directly by the macro above) + for displaying the referred objects of a reference field.
@@ -163,10 +172,6 @@ - Object description -

- Appy (top) navigation