571 or attrschema.type == 'Password': |
571 or attrschema.type == 'Password': |
572 self[attr] = None |
572 self[attr] = None |
573 continue |
573 continue |
574 yield attr |
574 yield attr |
575 |
575 |
|
576 _cw_completed = False |
576 def complete(self, attributes=None, skip_bytes=True): |
577 def complete(self, attributes=None, skip_bytes=True): |
577 """complete this entity by adding missing attributes (i.e. query the |
578 """complete this entity by adding missing attributes (i.e. query the |
578 repository to fill the entity) |
579 repository to fill the entity) |
579 |
580 |
580 :type skip_bytes: bool |
581 :type skip_bytes: bool |
581 :param skip_bytes: |
582 :param skip_bytes: |
582 if true, attribute of type Bytes won't be considered |
583 if true, attribute of type Bytes won't be considered |
583 """ |
584 """ |
584 assert self.has_eid() |
585 assert self.has_eid() |
|
586 if self._cw_completed: |
|
587 return |
|
588 if attributes is None: |
|
589 self._cw_completed = True |
585 varmaker = rqlvar_maker() |
590 varmaker = rqlvar_maker() |
586 V = varmaker.next() |
591 V = varmaker.next() |
587 rql = ['WHERE %s eid %%(x)s' % V] |
592 rql = ['WHERE %s eid %%(x)s' % V] |
588 selected = [] |
593 selected = [] |
589 for attr in (attributes or self.to_complete_attributes(skip_bytes)): |
594 for attr in (attributes or self.to_complete_attributes(skip_bytes)): |
862 else: |
867 else: |
863 assert role |
868 assert role |
864 self._related_cache.pop('%s_%s' % (rtype, role), None) |
869 self._related_cache.pop('%s_%s' % (rtype, role), None) |
865 |
870 |
866 def clear_all_caches(self): |
871 def clear_all_caches(self): |
|
872 """flush all caches on this entity. Further attributes/relations access |
|
873 will triggers new database queries to get back values. |
|
874 |
|
875 If you use custom caches on your entity class (take care to @cached!), |
|
876 you should override this method to clear them as well. |
|
877 """ |
|
878 # clear attributes cache |
867 haseid = 'eid' in self |
879 haseid = 'eid' in self |
|
880 self._cw_completed = False |
868 self.clear() |
881 self.clear() |
869 for rschema, _, role in self.e_schema.relation_definitions(): |
|
870 self.clear_related_cache(rschema.type, role) |
|
871 # set eid if it was in, else we may get nasty error while editing this |
882 # set eid if it was in, else we may get nasty error while editing this |
872 # entity if it's bound to a repo session |
883 # entity if it's bound to a repo session |
873 if haseid: |
884 if haseid: |
874 self['eid'] = self.eid |
885 self['eid'] = self.eid |
|
886 # clear relations cache |
|
887 for rschema, _, role in self.e_schema.relation_definitions(): |
|
888 self.clear_related_cache(rschema.type, role) |
875 |
889 |
876 # raw edition utilities ################################################### |
890 # raw edition utilities ################################################### |
877 |
891 |
878 def set_attributes(self, _cw_unsafe=False, **kwargs): |
892 def set_attributes(self, _cw_unsafe=False, **kwargs): |
879 assert kwargs |
893 assert kwargs |