auto-pluggable ClassifiableMixIn
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 22 Sep 2009 11:49:30 +0200
changeset 64 1cefc6b8bb8f
parent 63 fdb298a5503a
child 65 0049b8d1375c
auto-pluggable ClassifiableMixIn
entities.py
--- a/entities.py	Tue Sep 22 11:48:54 2009 +0200
+++ b/entities.py	Tue Sep 22 11:49:30 2009 +0200
@@ -6,7 +6,7 @@
 """
 __docformat__ = "restructuredtext en"
 
-from cubicweb.common.mixins import TreeMixIn
+from cubicweb.common.mixins import MI_REL_TRIGGERS, TreeMixIn
 from cubicweb.entities import AnyEntity, fetch_config
 from cubicweb.interfaces import ITree
 
@@ -75,3 +75,16 @@
 
     def dc_title(self):
         return u'%s - %s' % (self.code, self.name)
+
+
+class ClassifiableMixIn(object):
+    """mixin automatically plugged to entity types supporting the applied_to
+    relation
+    """
+    def classification_keywords(self, name):
+        """return keywords of the given classification linked to this entity"""
+        return self.req.execute('Any K, KN WHERE K applied_to X, X eid %(x)s, '
+                                'K name KN, K included_in CS, CS name %(name)s',
+                                {'x': self.eid, 'name': name}, 'x')
+
+MI_REL_TRIGGERS[('applied_to', 'object')] = ClassifiableMixIn