cubicweb/entities/adapters.py
changeset 12891 eb0cd6060062
parent 12880 59d4ad7e7df3
child 12892 0df0db725f07
--- a/cubicweb/entities/adapters.py	Wed Feb 12 13:58:17 2020 +0100
+++ b/cubicweb/entities/adapters.py	Fri Feb 14 18:15:55 2020 +0100
@@ -23,7 +23,7 @@
 from itertools import chain
 
 from logilab.mtconverter import TransformError
-from logilab.common.decorators import cached
+from logilab.common.decorators import cached, cachedproperty
 
 from cubicweb.entity import EntityAdapter
 from cubicweb import (Unauthorized, ValidationError, ViolatedConstraint,
@@ -32,6 +32,25 @@
 from cubicweb.predicates import is_instance, relation_possible, match_exception
 
 
+class EntityRDFAdapter(EntityAdapter):
+    """EntityRDFAdapter is to be specialized for each entity that wants to
+    be converted to RDF using the mechanism from cubicweb.rdf
+    """
+    __abstract__ = True
+
+    def __init__(self, _cw, **kwargs):
+        super().__init__(_cw, **kwargs)
+        self.entity.complete()
+
+    @cachedproperty
+    def uri(self):
+        return self.entity.cwuri
+
+    def triples(self):
+        """return sequence of 3-tuple of rdflib identifiers"""
+        raise NotImplementedError()
+
+
 class IDublinCoreAdapter(EntityAdapter):
     __regid__ = 'IDublinCore'
     __select__ = is_instance('Any')