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).

This commit is contained in:
Gaetan Delannay 2012-03-27 15:49:41 +02:00
parent 5928996730
commit 40e8a5f258
5 changed files with 63 additions and 30 deletions

View file

@ -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',