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: Created Jan. 11, 2019, 11:46 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/dynamic/en/get_page_url » ('j') | no next file with comments »
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,18 @@
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):
Vasily Kuznetsov 2019/01/14 13:29:27 The redirect argument is great, but it's not descr
rhowell 2019/01/14 14:56:47 Done.
+ if not locale:
+ locale = self._params['locale']
+ if self.page_has_locale(page, locale):
Vasily Kuznetsov 2019/01/14 13:29:27 Since the body of this if is the same as that of t
rhowell 2019/01/14 14:56:47 Yeah, I agree. Done.
+ return self._params['source'].resolve_link(page, locale)[1]
+ if 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/dynamic/en/get_page_url » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld