Fix intrasite links for non-'summary' metadata

Only the summary gets its intrasite links processed, has its value
is either generated from the content (calling self._update_content
at some point) or self._update_content is explicitly called if
summary is passed as metadata.

This patch expands the paths as soon as possible in (Content init)
for metadata defined in FORMATTED_FIELDS.
This commit is contained in:
Charles Flèche 2017-10-14 02:31:44 +07:00
commit a4b65ac09f
2 changed files with 19 additions and 5 deletions

View file

@ -140,6 +140,16 @@ class Content(object):
if not hasattr(self, 'status'): if not hasattr(self, 'status'):
self.status = getattr(self, 'default_status', None) self.status = getattr(self, 'default_status', None)
for key in self.settings['FORMATTED_FIELDS']:
if key in self.metadata:
value = self._update_content(
self.metadata[key],
self.get_siteurl()
)
self.metadata[key] = value
setattr(self, key.lower(), value)
# store the summary metadata if it is set # store the summary metadata if it is set
if 'summary' in metadata: if 'summary' in metadata:
self._summary = metadata['summary'] self._summary = metadata['summary']

View file

@ -319,17 +319,21 @@ class TestPage(LoggedTestCase):
) )
# also test for summary in metadata # also test for summary in metadata
args['metadata']['summary'] = ( parsed = (
'A simple summary test, with a ' 'A simple summary test, with a '
'<a href="|filename|article.rst">link</a>' '<a href="|filename|article.rst">link</a>'
) )
args['context']['localsiteurl'] = 'http://notmyidea.org' linked = (
p = Page(**args)
self.assertEqual(
p.summary,
'A simple summary test, with a ' 'A simple summary test, with a '
'<a href="http://notmyidea.org/article.html">link</a>' '<a href="http://notmyidea.org/article.html">link</a>'
) )
args['settings']['FORMATTED_FIELDS'] = ['summary', 'custom']
args['metadata']['summary'] = parsed
args['metadata']['custom'] = parsed
args['context']['localsiteurl'] = 'http://notmyidea.org'
p = Page(**args)
self.assertEqual(p.summary, linked)
self.assertEqual(p.custom, linked)
def test_intrasite_link_more(self): def test_intrasite_link_more(self):
# type does not take unicode in PY2 and bytes in PY3, which in # type does not take unicode in PY2 and bytes in PY3, which in