Commit 184ab3b7 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[entity] Stop linking to external site for external entities

This behaviour was ok when we had "true" multi-sources but its rather painful
with datafeed sources. Also, it makes absolute_url() costlier than what it
should. Besides, it relies on cw_metainformation()['source'] that is pending for
removal.

Instead, add a link to the original object in the metadata view (the one that
displays eid and source at the bottom right corner of the primary view).

Related to #15538288.
parent 3f81636a75db
......@@ -655,26 +655,16 @@ class Entity(AppObject):
method = args[0]
else:
method = None
# in linksearch mode, we don't want external urls else selecting
# the object for use in the relation is tricky
# XXX search_state is web specific
use_ext_id = False
if 'base_url' not in kwargs and \
getattr(self._cw, 'search_state', ('normal',))[0] == 'normal':
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'):
kwargs['_restpath'] = self.rest_path(use_ext_id)
kwargs['_restpath'] = self.rest_path()
else:
kwargs['rql'] = 'Any X WHERE X eid %s' % self.eid
return self._cw.build_url(method, **kwargs)
def rest_path(self, use_ext_eid=False): # XXX cw_rest_path
def rest_path(self, *args, **kwargs): # XXX cw_rest_path
"""returns a REST-like (relative) path for this entity"""
if args or kwargs:
warn("[3.24] rest_path doesn't take parameters anymore", DeprecationWarning)
mainattr, needcheck = self.cw_rest_attr_info()
etype = str(self.e_schema)
path = etype.lower()
......@@ -696,10 +686,7 @@ class Entity(AppObject):
mainattr = 'eid'
path = None
if mainattr == 'eid':
if use_ext_eid:
value = self.cw_metainformation()['extid']
else:
value = self.eid
value = self.eid
if path is None:
# fallback url: <base-url>/<eid> url is used as cw entities uri,
# prefer it to <base-url>/<etype>/eid/<eid>
......@@ -889,9 +876,7 @@ class Entity(AppObject):
selected.append((attr, var))
# +1 since this doesn't include the main variable
lastattr = len(selected) + 1
# don't fetch extra relation if attributes specified or of the entity is
# coming from an external source (may lead to error)
if attributes is None and self.cw_metainformation()['source']['uri'] == 'system':
if attributes is None:
# fetch additional relations (restricted to 0..1 relations)
for rschema, role in self._cw_to_complete_relations():
rtype = rschema.type
......
......@@ -89,7 +89,6 @@ class DataFeedTC(CubicWebTC):
'source': {'uri': u'ô myfeed', 'type': 'datafeed', 'use-cwuri-as-url': True},
'extid': b'http://www.cubicweb.org/'}
)
self.assertEqual(entity.absolute_url(), 'http://www.cubicweb.org/')
# test repo cache keys
self.assertEqual(self.repo._type_source_cache[entity.eid],
('Card', b'http://www.cubicweb.org/', u'ô myfeed'))
......
......@@ -831,18 +831,13 @@ du :eid:`1:*ReST*`'''
note.cw_set(ecrit_par=person.eid)
self.assertEqual(len(person.reverse_ecrit_par), 2)
def test_metainformation_and_external_absolute_url(self):
def test_metainformation(self):
with self.admin_access.web_request() as req:
note = req.create_entity('Note', type=u'z')
metainf = note.cw_metainformation()
self.assertEqual(metainf, {'source': {'type': 'native', 'uri': 'system',
'use-cwuri-as-url': False},
'type': u'Note', 'extid': None})
self.assertEqual(note.absolute_url(), 'http://testing.fr/cubicweb/note/%s' % note.eid)
metainf['source'] = metainf['source'].copy()
metainf['source']['base-url'] = 'http://cubicweb2.com/'
metainf['extid'] = 1234
self.assertEqual(note.absolute_url(), 'http://cubicweb2.com/note/1234')
def test_absolute_url_empty_field(self):
with self.admin_access.web_request() as req:
......
......@@ -463,10 +463,13 @@ class MetaDataView(EntityView):
else:
self.w(u' <span>%s</span> ' % _('created_by'))
self.w(u'<span class="value">%s</span>' % entity.creator.name())
meta = entity.cw_metainformation()
if meta['source']['uri'] != 'system':
source = entity.cw_source[0]
if source.name != 'system':
self.w(u' (<span>%s</span>' % _('cw_source'))
self.w(u' <span class="value">%s</span>)' % meta['source']['uri'])
self.w(u' <span class="value">%s</span>)' % source.view('oneline'))
source_def = self._cw.source_defs()[source.name]
if source_def.get('use-cwuri-as-url'):
self.w(u' <a href="%s">%s</span>' % (entity.cwuri, self._cw._('view original')))
self.w(u'</div>')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment