[gen] Added attributes 'created' and 'modified', now accessible on Appy wrappers; added method AbstractWrapper.countRef that allows to count the number of objects tied to a given object via a Ref field whose name is given as method param.

This commit is contained in:
Gaetan Delannay 2013-06-07 11:32:23 +02:00
parent 1b3af98305
commit 0d0d7c1123

View file

@ -104,6 +104,8 @@ class AbstractWrapper(object):
elif name == 'id': return self.o.id elif name == 'id': return self.o.id
elif name == 'uid': return self.o.UID() elif name == 'uid': return self.o.UID()
elif name == 'klass': return self.__class__.__bases__[-1] elif name == 'klass': return self.__class__.__bases__[-1]
elif name == 'created': return self.o.created
elif name == 'modified': return self.o.modified
elif name == 'url': return self.o.absolute_url() elif name == 'url': return self.o.absolute_url()
elif name == 'state': return self.o.State() elif name == 'state': return self.o.State()
elif name == 'stateLabel': elif name == 'stateLabel':
@ -344,6 +346,13 @@ class AbstractWrapper(object):
if res: return res._len # It is a LazyMap instance if res: return res._len # It is a LazyMap instance
else: return 0 else: return 0
def countRefs(self, fieldName):
'''Counts the number of objects linked to this one via Ref field
p_fieldName.'''
uids = getattr(self.o.aq_base, fieldName, None)
if not uids: return 0
return len(uids)
def compute(self, klass, sortBy='', maxResults=None, context=None, def compute(self, klass, sortBy='', maxResults=None, context=None,
expression=None, noSecurity=False, **fields): expression=None, noSecurity=False, **fields):
'''This method, like m_search and m_count above, performs a query on '''This method, like m_search and m_count above, performs a query on