[gen] More methods on AbstractWrapper.

This commit is contained in:
Gaetan Delannay 2014-05-02 14:34:10 +02:00
parent 1d0ee7a614
commit b83f6d512d
2 changed files with 19 additions and 3 deletions

View file

@ -1022,12 +1022,18 @@ class Ref(Field):
res = refObject.tool.o.truncateValue(res, maxWidth)
return res
def getIndexOf(self, obj, tiedUid):
def getIndexOf(self, obj, tiedUid, raiseError=True):
'''Gets the position of tied object identified by p_tiedUid within this
field on p_obj.'''
uids = getattr(obj.aq_base, self.name, None)
if not uids: raise IndexError()
return uids.index(tiedUid)
if not uids:
if raiseError: raise IndexError()
else: return
if tiedUid in uids:
return uids.index(tiedUid)
else:
if raiseError: raise IndexError()
else: return
def sort(self, obj):
'''Called when the user wants to sort the content of this field.'''

View file

@ -1083,4 +1083,14 @@ class AbstractWrapper(object):
p_name.'''
v = getattr(self, name)
if v: return v.getFilePath(self)
def getIndexOf(self, name, obj):
'''Returns, as an integer starting at 0, the position of p_obj within
objects linked to p_self via field p_name.'''
o = self.o
return o.getAppyType(name).getIndexOf(o, obj.uid)
def allows(self, permission, raiseError=False):
'''Check doc @Mixin.allows.'''
return self.o.allows(permission, raiseError=raiseError)
# ------------------------------------------------------------------------------