diff -r 101344a6ff9b -r 294e084f1263 entity.py --- a/entity.py Tue Feb 02 18:24:45 2010 +0100 +++ b/entity.py Wed Feb 03 14:46:32 2010 +0100 @@ -272,7 +272,7 @@ def has_perm(self, action): return self.e_schema.has_perm(self._cw, action, eid=self.eid) - def view(self, vid, __registry='views', **kwargs): + def view(self, __vid, __registry='views', **kwargs): """shortcut to apply a view on this entity""" view = self._cw.vreg[__registry].select(vid, self._cw, rset=self.cw_rset, row=self.cw_row, col=self.cw_col, @@ -477,6 +477,7 @@ continue yield attr + _cw_completed = False def complete(self, attributes=None, skip_bytes=True): """complete this entity by adding missing attributes (i.e. query the repository to fill the entity) @@ -486,6 +487,10 @@ if true, attribute of type Bytes won't be considered """ assert self.has_eid() + if self._cw_completed: + return + if attributes is None: + self._cw_completed = True varmaker = rqlvar_maker() V = varmaker.next() rql = ['WHERE %s eid %%(x)s' % V] @@ -763,14 +768,23 @@ self._related_cache.pop('%s_%s' % (rtype, role), None) def clear_all_caches(self): + """flush all caches on this entity. Further attributes/relations access + will triggers new database queries to get back values. + + If you use custom caches on your entity class (take care to @cached!), + you should override this method to clear them as well. + """ + # clear attributes cache haseid = 'eid' in self + self._cw_completed = False self.clear() - for rschema, _, role in self.e_schema.relation_definitions(): - self.clear_related_cache(rschema.type, role) # set eid if it was in, else we may get nasty error while editing this # entity if it's bound to a repo session if haseid: self['eid'] = self.eid + # clear relations cache + for rschema, _, role in self.e_schema.relation_definitions(): + self.clear_related_cache(rschema.type, role) # raw edition utilities ###################################################