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

Delta Between Two Patch Sets: cms/utils.py

Issue 5242593268989952: Issue 2340 - Don`t generate pages if less than 30% have been translated (Closed)
Left Patch Set: Created April 17, 2015, 5:19 p.m.
Right Patch Set: Addressed comments Created May 6, 2015, 5:20 p.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/sources.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 cms.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.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
(...skipping 24 matching lines...) Expand all
53 53
54 # Note: The converter might change some parameters so we can only read in 54 # Note: The converter might change some parameters so we can only read in
55 # template data here. 55 # template data here.
56 params["templatedata"] = source.read_template(params["template"]) 56 params["templatedata"] = source.read_template(params["template"])
57 57
58 defaultlocale = params["config"].get("general", "defaultlocale") 58 defaultlocale = params["config"].get("general", "defaultlocale")
59 params["defaultlocale"] = defaultlocale 59 params["defaultlocale"] = defaultlocale
60 60
61 locales = [ 61 locales = [
62 l 62 l
63 for l in source.list_locales() 63 for l in source.list_locales()
Wladimir Palant 2015/04/17 17:22:31 Parameter being overwritten here isn't quite relat
64 if source.has_locale(locale, localefile) 64 if source.has_locale(locale, localefile)
65 ] 65 ]
66 if defaultlocale not in locales: 66 if defaultlocale not in locales:
67 locales.append(defaultlocale) 67 locales.append(defaultlocale)
68 locales.sort() 68 locales.sort()
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 if converter.total_translations: 72 if converter.total_translations > 0:
Sebastian Noack 2015/04/17 17:32:27 Nit: total_translation > 0 I know 0 evaluates to
73 params["translation_ratio"] = (1 - 73 params["translation_ratio"] = (1 -
74 float(converter.missing_translations) / converter.total_translations) 74 float(converter.missing_translations) / converter.total_translations)
75 else: 75 else:
76 params["translation_ratio"] = 1 76 params["translation_ratio"] = 1
Wladimir Palant 2015/04/17 17:22:31 Note that having this in params means that default
77 77
78 return params 78 return params
79 79
80 def process_page(source, locale, page, format, site_url_override=None, min_trans lated=0): 80 def process_page(source, locale, page, format=None, site_url_override=None):
81 params = get_page_params(source, locale, page, format, site_url_override) 81 return TemplateConverter(
82 if params["translation_ratio"] < min_translated: 82 get_page_params(source, locale, page, format, site_url_override),
83 return None 83 key="templatedata"
84 else: 84 )()
Sebastian Noack 2015/04/17 17:32:27 Nit: Redundant else statement.
Wladimir Palant 2015/04/17 18:21:15 I thought you would object to this, but I actually
85 return TemplateConverter(
86 params,
87 key="templatedata"
88 )()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld