equal
deleted
inserted
replaced
144 0 if lt_role == 'subject' else 1] |
144 0 if lt_role == 'subject' else 1] |
145 if lt_card not in '?1': |
145 if lt_card not in '?1': |
146 continue |
146 continue |
147 pruned[(lt_rtype, lt_role)] = eids |
147 pruned[(lt_rtype, lt_role)] = eids |
148 return pruned |
148 return pruned |
|
149 |
149 |
150 |
150 class Entity(AppObject): |
151 class Entity(AppObject): |
151 """an entity instance has e_schema automagically set on |
152 """an entity instance has e_schema automagically set on |
152 the class and instances has access to their issuing cursor. |
153 the class and instances has access to their issuing cursor. |
153 |
154 |
531 return created |
532 return created |
532 |
533 |
533 def __init__(self, req, rset=None, row=None, col=0): |
534 def __init__(self, req, rset=None, row=None, col=0): |
534 AppObject.__init__(self, req, rset=rset, row=row, col=col) |
535 AppObject.__init__(self, req, rset=rset, row=row, col=col) |
535 self._cw_related_cache = {} |
536 self._cw_related_cache = {} |
|
537 self._cw_adapters_cache = {} |
536 if rset is not None: |
538 if rset is not None: |
537 self.eid = rset[row][col] |
539 self.eid = rset[row][col] |
538 else: |
540 else: |
539 self.eid = None |
541 self.eid = None |
540 self._cw_is_saved = True |
542 self._cw_is_saved = True |
568 def cw_adapt_to(self, interface): |
570 def cw_adapt_to(self, interface): |
569 """return an adapter the entity to the given interface name. |
571 """return an adapter the entity to the given interface name. |
570 |
572 |
571 return None if it can not be adapted. |
573 return None if it can not be adapted. |
572 """ |
574 """ |
573 try: |
575 cache = self._cw_adapters_cache |
574 cache = self._cw_adapters_cache |
|
575 except AttributeError: |
|
576 self._cw_adapters_cache = cache = {} |
|
577 try: |
576 try: |
578 return cache[interface] |
577 return cache[interface] |
579 except KeyError: |
578 except KeyError: |
580 adapter = self._cw.vreg['adapters'].select_or_none( |
579 adapter = self._cw.vreg['adapters'].select_or_none( |
581 interface, self._cw, entity=self) |
580 interface, self._cw, entity=self) |
1237 def cw_clear_relation_cache(self, rtype=None, role=None): |
1236 def cw_clear_relation_cache(self, rtype=None, role=None): |
1238 """clear cached values for the given relation or the entire cache if |
1237 """clear cached values for the given relation or the entire cache if |
1239 no relation is given |
1238 no relation is given |
1240 """ |
1239 """ |
1241 if rtype is None: |
1240 if rtype is None: |
1242 self._cw_related_cache = {} |
1241 self._cw_related_cache.clear() |
1243 self._cw_adapters_cache = {} |
1242 self._cw_adapters_cache.clear() |
1244 else: |
1243 else: |
1245 assert role |
1244 assert role |
1246 self._cw_related_cache.pop('%s_%s' % (rtype, role), None) |
1245 self._cw_related_cache.pop('%s_%s' % (rtype, role), None) |
1247 |
1246 |
1248 def cw_clear_all_caches(self): |
1247 def cw_clear_all_caches(self): |