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

Side by Side Diff: cms/utils.py

Issue 29345291: Noissue - Adapt quotes for compliance with our coding style in the CMS (Closed)
Patch Set: Created May 29, 2016, 1:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cms/sources.py ('k') | runserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 from cms.converters import converters, TemplateConverter 16 from cms.converters import converters, TemplateConverter
17 17
18 18
19 def get_page_params(source, locale, page, format=None, site_url_override=None, 19 def get_page_params(source, locale, page, format=None, site_url_override=None,
20 localized_string_callback=None): 20 localized_string_callback=None):
21 # Guess page format if omitted, but default to Markdown for friendlier excep tions 21 # Guess page format if omitted, but default to Markdown for friendlier excep tions
22 if format is None: 22 if format is None:
23 for format in converters.iterkeys(): 23 for format in converters.iterkeys():
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,
34 "pagedata": source.read_page(page, format), 34 'pagedata': source.read_page(page, format),
35 "config": source.read_config(), 35 'config': source.read_config(),
36 "localized_string_callback": localized_string_callback, 36 'localized_string_callback': localized_string_callback,
37 } 37 }
38 38
39 localefile = page 39 localefile = page
40 if params["config"].has_option("locale_overrides", page): 40 if params['config'].has_option('locale_overrides', page):
41 localefile = params["config"].get("locale_overrides", page) 41 localefile = params['config'].get('locale_overrides', page)
42 params["localedata"] = source.read_locale(params["locale"], localefile) 42 params['localedata'] = source.read_locale(params['locale'], localefile)
43 43
44 if params["config"].has_option("general", "siteurl"): 44 if params['config'].has_option('general', 'siteurl'):
45 if site_url_override: 45 if site_url_override:
46 params["site_url"] = site_url_override 46 params['site_url'] = site_url_override
47 else: 47 else:
48 params["site_url"] = params["config"].get("general", "siteurl") 48 params['site_url'] = params['config'].get('general', 'siteurl')
49 49
50 try: 50 try:
51 converter_class = converters[format] 51 converter_class = converters[format]
52 except KeyError: 52 except KeyError:
53 raise Exception("Page %s uses unknown format %s" % (page, format)) 53 raise Exception('Page %s uses unknown format %s' % (page, format))
54 54
55 converter = converter_class(params) 55 converter = converter_class(params)
56 56
57 # Note: The converter might change some parameters so we can only read in 57 # Note: The converter might change some parameters so we can only read in
58 # template data here. 58 # template data here.
59 params["templatedata"] = source.read_template(params["template"]) 59 params['templatedata'] = source.read_template(params['template'])
60 60
61 defaultlocale = params["config"].get("general", "defaultlocale") 61 defaultlocale = params['config'].get('general', 'defaultlocale')
62 params["defaultlocale"] = defaultlocale 62 params['defaultlocale'] = defaultlocale
63 63
64 locales = [ 64 locales = [
65 l 65 l
66 for l in source.list_locales() 66 for l in source.list_locales()
67 if source.has_locale(l, localefile) 67 if source.has_locale(l, localefile)
68 ] 68 ]
69 if defaultlocale not in locales: 69 if defaultlocale not in locales:
70 locales.append(defaultlocale) 70 locales.append(defaultlocale)
71 locales.sort() 71 locales.sort()
72 params["available_locales"] = locales 72 params['available_locales'] = locales
73 73
74 params["head"], params["body"] = converter() 74 params['head'], params['body'] = converter()
75 if converter.total_translations > 0: 75 if converter.total_translations > 0:
76 params["translation_ratio"] = ( 76 params['translation_ratio'] = (
77 1 - float(converter.missing_translations) / converter.total_translat ions 77 1 - float(converter.missing_translations) / converter.total_translat ions
78 ) 78 )
79 else: 79 else:
80 params["translation_ratio"] = 1 80 params['translation_ratio'] = 1
81 81
82 return params 82 return params
83 83
84 84
85 def process_page(source, locale, page, format=None, site_url_override=None, 85 def process_page(source, locale, page, format=None, site_url_override=None,
86 localized_string_callback=None): 86 localized_string_callback=None):
87 return TemplateConverter( 87 return TemplateConverter(
88 get_page_params(source, locale, page, format, 88 get_page_params(source, locale, page, format,
89 site_url_override, localized_string_callback), 89 site_url_override, localized_string_callback),
90 key="templatedata" 90 key='templatedata'
91 )() 91 )()
OLDNEW
« no previous file with comments | « cms/sources.py ('k') | runserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld