From 0d0d7c11237d44b29c58c145802d1fd0ceadc023 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 7 Jun 2013 11:32:23 +0200 Subject: [PATCH] [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. --- gen/wrappers/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gen/wrappers/__init__.py b/gen/wrappers/__init__.py index db66d05..978b522 100644 --- a/gen/wrappers/__init__.py +++ b/gen/wrappers/__init__.py @@ -104,6 +104,8 @@ class AbstractWrapper(object): elif name == 'id': return self.o.id elif name == 'uid': return self.o.UID() 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 == 'state': return self.o.State() elif name == 'stateLabel': @@ -344,6 +346,13 @@ class AbstractWrapper(object): if res: return res._len # It is a LazyMap instance 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, expression=None, noSecurity=False, **fields): '''This method, like m_search and m_count above, performs a query on