[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 22 Jun 2011 18:53:36 +0200
changeset 7552 82dde8276a5b
parent 7548 92fd4b777016
child 7553 935423529f45
[datafeed, entities] url for entities from a datafeed source should be on their origin site. Closes #1769391
entity.py
server/sources/__init__.py
server/sources/datafeed.py
server/test/unittest_datafeed.py
sobjects/test/unittest_parsers.py
--- a/entity.py	Wed Jun 22 12:31:55 2011 +0200
+++ b/entity.py	Wed Jun 22 18:53:36 2011 +0200
@@ -433,9 +433,11 @@
         use_ext_id = False
         if 'base_url' not in kwargs and \
                getattr(self._cw, 'search_state', ('normal',))[0] == 'normal':
-            baseurl = self.cw_metainformation()['source'].get('base-url')
-            if baseurl:
-                kwargs['base_url'] = baseurl
+            sourcemeta = self.cw_metainformation()['source']
+            if sourcemeta.get('use-cwuri-as-url'):
+                return self.cwuri # XXX consider kwargs?
+            if sourcemeta.get('base-url'):
+                kwargs['base_url'] = sourcemeta['base-url']
                 use_ext_id = True
         if method in (None, 'view'):
             try:
--- a/server/sources/__init__.py	Wed Jun 22 12:31:55 2011 +0200
+++ b/server/sources/__init__.py	Wed Jun 22 18:53:36 2011 +0200
@@ -110,6 +110,10 @@
     # force deactivation (configuration error for instance)
     disabled = False
 
+    # boolean telling if cwuri of entities from this source is the url that
+    # should be used as entity's absolute url
+    use_cwuri_as_url = False
+
     # source configuration options
     options = ()
 
@@ -119,6 +123,7 @@
         self.support_relations['identity'] = False
         self.eid = eid
         self.public_config = source_config.copy()
+        self.public_config.setdefault('use-cwuri-as-url', self.use_cwuri_as_url)
         self.remove_sensitive_information(self.public_config)
         self.uri = source_config.pop('uri')
         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
@@ -213,7 +218,7 @@
         """
         pass
 
-    PUBLIC_KEYS = ('type', 'uri')
+    PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
     def remove_sensitive_information(self, sourcedef):
         """remove sensitive information such as login / password from source
         definition
--- a/server/sources/datafeed.py	Wed Jun 22 12:31:55 2011 +0200
+++ b/server/sources/datafeed.py	Wed Jun 22 18:53:36 2011 +0200
@@ -35,6 +35,7 @@
 
 class DataFeedSource(AbstractSource):
     copy_based_source = True
+    use_cwuri_as_url = True
 
     options = (
         ('synchronize',
--- a/server/test/unittest_datafeed.py	Wed Jun 22 12:31:55 2011 +0200
+++ b/server/test/unittest_datafeed.py	Wed Jun 22 18:53:36 2011 +0200
@@ -67,6 +67,7 @@
                               'source': {'uri': 'myfeed', 'type': 'datafeed'},
                               'extid': 'http://www.cubicweb.org/'}
                              )
+            self.assertEqual(entity.absolute_url(), 'extid': 'http://www.cubicweb.org/')
             # test repo cache keys
             self.assertEqual(self.repo._type_source_cache[entity.eid],
                              ('Card', 'system', 'http://www.cubicweb.org/', 'myfeed'))
--- a/sobjects/test/unittest_parsers.py	Wed Jun 22 12:31:55 2011 +0200
+++ b/sobjects/test/unittest_parsers.py	Wed Jun 22 18:53:36 2011 +0200
@@ -164,11 +164,13 @@
         self.assertEqual(user.modification_date, datetime(2011, 01, 25, 14, 14, 06))
         self.assertEqual(user.cwuri, 'http://pouet.org/5')
         self.assertEqual(user.cw_source[0].name, 'myfeed')
+        self.assertEqual(user.absolute_url(), 'http://pouet.org/5')
         self.assertEqual(len(user.use_email), 1)
         # copy action
         email = user.use_email[0]
         self.assertEqual(email.address, 'syt@logilab.fr')
         self.assertEqual(email.cwuri, 'http://pouet.org/6')
+        self.assertEqual(email.absolute_url(), 'http://pouet.org/6')
         self.assertEqual(email.cw_source[0].name, 'myfeed')
         # link action
         self.assertFalse(self.execute('CWGroup X WHERE X name "unknown"'))
@@ -200,7 +202,8 @@
         self.assertEqual(len(rset), 1)
         e = rset.get_entity(0, 0)
         self.assertEqual(e.eid, email.eid)
-        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
+        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system',
+                                                             'use-cwuri-as-url': False},
                                                   'type': 'EmailAddress',
                                                   'extid': None})
         self.assertEqual(e.cw_source[0].name, 'system')
@@ -213,7 +216,8 @@
         self.assertEqual(len(rset), 1)
         e = rset.get_entity(0, 0)
         self.assertEqual(e.eid, email.eid)
-        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system'},
+        self.assertEqual(e.cw_metainformation(), {'source': {'type': u'native', 'uri': u'system',
+                                                             'use-cwuri-as-url': False},
                                                   'type': 'EmailAddress',
                                                   'extid': None})
         self.assertEqual(e.cw_source[0].name, 'system')