[gen] Ensure the tool can't be deleted. [gen] Wrapper.sort can now sort according to param field.insert if sortKey is None.
This commit is contained in:
parent
90657e0faf
commit
bccc9c8320
|
@ -1020,7 +1020,7 @@ class Ref(Field):
|
|||
'''This method links p_value (which can be a list of objects) to p_obj
|
||||
through this Ref field. When linking 2 objects via a Ref,
|
||||
p_linkObject must be called twice: once on the forward Ref and once
|
||||
on the backward ref. p_back indicates if we are calling it on the
|
||||
on the backward Ref. p_back indicates if we are calling it on the
|
||||
forward or backward Ref. If p_noSecurity is True, we bypass security
|
||||
checks (has the logged user the right to modify this Ref field?).
|
||||
If p_executeMethods is False, we do not execute methods that
|
||||
|
@ -1040,7 +1040,7 @@ class Ref(Field):
|
|||
if refs == None:
|
||||
refs = zobj.getProductConfig().PersistentList()
|
||||
setattr(zobj, self.name, refs)
|
||||
# Insert p_value into it.
|
||||
# Insert p_value into it
|
||||
uid = value.o.id
|
||||
if uid in refs: return
|
||||
# Execute self.beforeLink if present
|
||||
|
|
|
@ -767,4 +767,8 @@ class ToolWrapper(AbstractWrapper):
|
|||
'''Show this button only if a LDAP connection exists and is enabled.'''
|
||||
cfg = self.o.getProductConfig(True).ldap
|
||||
if cfg and cfg.enabled: return 'view'
|
||||
|
||||
def mayDelete(self):
|
||||
'''No one can delete the tool.'''
|
||||
return
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -276,7 +276,7 @@ class UserWrapper(AbstractWrapper):
|
|||
def mayDelete(self):
|
||||
'''No one can delete users "system", "anon" and "admin".'''
|
||||
if self.o.id in self.specialUsers: return
|
||||
# Call custom "mayDelete" when present.
|
||||
# Call custom "mayDelete" when present
|
||||
custom = self._getCustomMethod('mayDelete')
|
||||
if custom: return self._callCustom('mayDelete')
|
||||
return True
|
||||
|
@ -292,7 +292,7 @@ class UserWrapper(AbstractWrapper):
|
|||
(for local users only).'''
|
||||
if self.source == 'zodb': del self.o.acl_users.data[self.login]
|
||||
self.log('user %s deleted.' % self.login)
|
||||
# Call a custom "onDelete" if any.
|
||||
# Call a custom "onDelete" if any
|
||||
return self._callCustom('onDelete')
|
||||
|
||||
def getLogins(self, groupsOnly=False):
|
||||
|
|
|
@ -850,15 +850,27 @@ class AbstractWrapper(object):
|
|||
def sort(self, fieldName, sortKey='title', reverse=False):
|
||||
'''Sorts referred elements linked to p_self via p_fieldName according
|
||||
to a given p_sortKey which must be an attribute set on referred
|
||||
objects ("title", by default).'''
|
||||
objects ("title", by default) or None. If None, default sorting will
|
||||
occur, using the method stored in field.insert.'''
|
||||
refs = getattr(self.o, fieldName, None)
|
||||
if not refs: return
|
||||
tool = self.tool
|
||||
# refs is a PersistentList: param "key" is not available. So perform the
|
||||
# sort on the real list and then indicate that the persistent list has
|
||||
# changed (the ZODB way).
|
||||
refs.data.sort(key=lambda x: getattr(tool.getObject(x), sortKey),
|
||||
reverse=reverse)
|
||||
# refs is a PersistentList: param "key" is not available for method
|
||||
# "sort". So perform the sort on the real list and then indicate that
|
||||
# the persistent list has changed (the ZODB way).
|
||||
if not sortKey:
|
||||
# Sort according to field.insert
|
||||
field = self.getField(fieldName)
|
||||
insertMethod = field.insert
|
||||
if not insertMethod:
|
||||
raise Exception('Param "insert" for Ref field %s is None.' % \
|
||||
fieldName)
|
||||
if not callable(insertMethod): insertMethod = insertMethod[1]
|
||||
keyMethod = lambda uid: insertMethod(self, tool.getObject(uid))
|
||||
else:
|
||||
# Sort according to p_sortKey
|
||||
keyMethod = lambda uid: getattr(tool.getObject(uid), sortKey)
|
||||
refs.data.sort(key=keyMethod, reverse=reverse)
|
||||
refs._p_changed = 1
|
||||
|
||||
def create(self, fieldNameOrClass, noSecurity=False,
|
||||
|
|
Loading…
Reference in a new issue