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

Delta Between Two Patch Sets: cms/utils.py

Issue 5148261828526080: Issue 2119 - Add get_page_content template function. (Closed)
Left Patch Set: Use for, break, else control flow for page format guessing. Created April 8, 2015, 8:46 a.m.
Right Patch Set: Use .iterkeys() instead of .keys() Created April 8, 2015, 9:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « cms/converters.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 from .converters import converters, TemplateConverter 18 from .converters import converters, TemplateConverter
19 19
20 def get_page_params(source, locale, page, format=None, site_url_override=None): 20 def get_page_params(source, locale, page, format=None, site_url_override=None):
21 # Guess page format if omitted, but default to Markdown for friendlier excepti ons 21 # Guess page format if omitted, but default to Markdown for friendlier excepti ons
22 if format is None: 22 if format is None:
23 for format in converters.keys(): 23 for format in converters.iterkeys():
Sebastian Noack 2015/04/08 09:09:32 Nit: This creates a new list with all the keys in
kzar 2015/04/08 09:32:11 Done.
24 if source.has_page(page, format): 24 if source.has_page(page, format):
25 break 25 break
26 else: 26 else:
27 format = "md" 27 format = "md"
28 28
29 params = { 29 params = {
30 "source": source, 30 "source": source,
31 "template": "default", 31 "template": "default",
32 "locale": locale, 32 "locale": locale,
33 "page": page, 33 "page": page,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 params["available_locales"] = locales 69 params["available_locales"] = locales
70 70
71 params["head"], params["body"] = converter() 71 params["head"], params["body"] = converter()
72 return params 72 return params
73 73
74 def process_page(source, locale, page, format, site_url_override=None): 74 def process_page(source, locale, page, format, site_url_override=None):
75 return TemplateConverter( 75 return TemplateConverter(
76 get_page_params(source, locale, page, format, site_url_override), 76 get_page_params(source, locale, page, format, site_url_override),
77 key="templatedata" 77 key="templatedata"
78 )() 78 )()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld