server/sources/datafeed.py
changeset 8573 ae0a567dff30
parent 8535 268b6349baf3
parent 8547 f23ac525ddd1
child 8674 001c1592060a
equal deleted inserted replaced
8570:e20057a9ceea 8573:ae0a567dff30
    28 from cookielib import CookieJar
    28 from cookielib import CookieJar
    29 
    29 
    30 from lxml import etree
    30 from lxml import etree
    31 
    31 
    32 from cubicweb import RegistryNotFound, ObjectNotFound, ValidationError, UnknownEid
    32 from cubicweb import RegistryNotFound, ObjectNotFound, ValidationError, UnknownEid
       
    33 from cubicweb.server.repository import preprocess_inlined_relations
    33 from cubicweb.server.sources import AbstractSource
    34 from cubicweb.server.sources import AbstractSource
    34 from cubicweb.appobject import AppObject
    35 from cubicweb.appobject import AppObject
    35 
    36 
    36 
    37 
    37 class DataFeedSource(AbstractSource):
    38 class DataFeedSource(AbstractSource):
   252 
   253 
   253     def after_entity_insertion(self, session, lid, entity, sourceparams):
   254     def after_entity_insertion(self, session, lid, entity, sourceparams):
   254         """called by the repository after an entity stored here has been
   255         """called by the repository after an entity stored here has been
   255         inserted in the system table.
   256         inserted in the system table.
   256         """
   257         """
       
   258         relations = preprocess_inlined_relations(session, entity)
   257         if session.is_hook_category_activated('integrity'):
   259         if session.is_hook_category_activated('integrity'):
   258             entity.cw_edited.check(creation=True)
   260             entity.cw_edited.check(creation=True)
   259         self.repo.system_source.add_entity(session, entity)
   261         self.repo.system_source.add_entity(session, entity)
   260         entity.cw_edited.saved = entity._cw_is_saved = True
   262         entity.cw_edited.saved = entity._cw_is_saved = True
   261         sourceparams['parser'].after_entity_copy(entity, sourceparams)
   263         sourceparams['parser'].after_entity_copy(entity, sourceparams)
       
   264         # call hooks for inlined relations
       
   265         call_hooks = self.repo.hm.call_hooks
       
   266         if self.should_call_hooks:
       
   267             for attr, value in relations:
       
   268                 call_hooks('before_add_relation', session,
       
   269                            eidfrom=entity.eid, rtype=attr, eidto=value)
       
   270                 call_hooks('after_add_relation', session,
       
   271                            eidfrom=entity.eid, rtype=attr, eidto=value)
   262 
   272 
   263     def source_cwuris(self, session):
   273     def source_cwuris(self, session):
   264         sql = ('SELECT extid, eid, type FROM entities, cw_source_relation '
   274         sql = ('SELECT extid, eid, type FROM entities, cw_source_relation '
   265                'WHERE entities.eid=cw_source_relation.eid_from '
   275                'WHERE entities.eid=cw_source_relation.eid_from '
   266                'AND cw_source_relation.eid_to=%s' % self.eid)
   276                'AND cw_source_relation.eid_to=%s' % self.eid)
   397                           if v != getattr(entity, k))
   407                           if v != getattr(entity, k))
   398             if attrs:
   408             if attrs:
   399                 entity.cw_set(**attrs)
   409                 entity.cw_set(**attrs)
   400                 self.notify_updated(entity)
   410                 self.notify_updated(entity)
   401 
   411 
       
   412 
   402 class DataFeedXMLParser(DataFeedParser):
   413 class DataFeedXMLParser(DataFeedParser):
   403 
   414 
   404     def process(self, url, raise_on_error=False):
   415     def process(self, url, raise_on_error=False):
   405         """IDataFeedParser main entry point"""
   416         """IDataFeedParser main entry point"""
   406         try:
   417         try: