cubicweb/entities/adapters.py
changeset 12891 eb0cd6060062
parent 12880 59d4ad7e7df3
child 12892 0df0db725f07
equal deleted inserted replaced
12890:0cd5b9057202 12891:eb0cd6060062
    21 from cubicweb import _
    21 from cubicweb import _
    22 
    22 
    23 from itertools import chain
    23 from itertools import chain
    24 
    24 
    25 from logilab.mtconverter import TransformError
    25 from logilab.mtconverter import TransformError
    26 from logilab.common.decorators import cached
    26 from logilab.common.decorators import cached, cachedproperty
    27 
    27 
    28 from cubicweb.entity import EntityAdapter
    28 from cubicweb.entity import EntityAdapter
    29 from cubicweb import (Unauthorized, ValidationError, ViolatedConstraint,
    29 from cubicweb import (Unauthorized, ValidationError, ViolatedConstraint,
    30                       UniqueTogetherError)
    30                       UniqueTogetherError)
    31 from cubicweb.schema import constraint_name_for
    31 from cubicweb.schema import constraint_name_for
    32 from cubicweb.predicates import is_instance, relation_possible, match_exception
    32 from cubicweb.predicates import is_instance, relation_possible, match_exception
       
    33 
       
    34 
       
    35 class EntityRDFAdapter(EntityAdapter):
       
    36     """EntityRDFAdapter is to be specialized for each entity that wants to
       
    37     be converted to RDF using the mechanism from cubicweb.rdf
       
    38     """
       
    39     __abstract__ = True
       
    40 
       
    41     def __init__(self, _cw, **kwargs):
       
    42         super().__init__(_cw, **kwargs)
       
    43         self.entity.complete()
       
    44 
       
    45     @cachedproperty
       
    46     def uri(self):
       
    47         return self.entity.cwuri
       
    48 
       
    49     def triples(self):
       
    50         """return sequence of 3-tuple of rdflib identifiers"""
       
    51         raise NotImplementedError()
    33 
    52 
    34 
    53 
    35 class IDublinCoreAdapter(EntityAdapter):
    54 class IDublinCoreAdapter(EntityAdapter):
    36     __regid__ = 'IDublinCore'
    55     __regid__ = 'IDublinCore'
    37     __select__ = is_instance('Any')
    56     __select__ = is_instance('Any')