Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: cms/converters.py

Issue 29979564: Issue 5452 - Improve CMS API for local link generation (Closed) Base URL: https://hg.adblockplus.org/cms/
Patch Set: Address comments on PS2 Created Jan. 14, 2019, 4:57 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/expected_output/common/en/global » ('j') | tests/expected_output/common/en/global » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/converters.py
===================================================================
--- a/cms/converters.py
+++ b/cms/converters.py
@@ -442,6 +442,8 @@
'get_page_content': self.get_page_content,
'get_pages_metadata': self.get_pages_metadata,
'get_canonical_url': self.get_canonical_url,
+ 'get_page_url': self.get_page_url,
+ 'page_has_locale': self.page_has_locale,
}
for dirname, dictionary in [('filters', filters),
@@ -588,6 +590,16 @@
stack.append(item)
return structured
+ def page_has_locale(self, page, locale):
+ return self._params['source'].has_locale(locale, page)
+
+ def get_page_url(self, page, locale=None, redirect=False):
+ if not locale:
+ locale = self._params['locale']
+ if self.page_has_locale(page, locale) or redirect:
+ return self._params['source'].resolve_link(page, locale)[1]
+ raise Exception('{} does not exist in {}'.format(page, locale))
+
converters = {
'html': RawConverter,
« no previous file with comments | « no previous file | tests/expected_output/common/en/global » ('j') | tests/expected_output/common/en/global » ('J')

Powered by Google App Engine
This is Rietveld