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

Side by Side Diff: cms/utils.py

Issue 29933596: Issue 5333 - Allow cms to generate relative pages (Closed) Base URL: https://hg.adblockplus.org/cms/
Patch Set: Address comments on PS2, rearrange test files (again) Created Nov. 7, 2018, 4:14 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
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-present eyeo GmbH 2 # Copyright (C) 2006-present 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
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 if length > 0: 120 if length > 0:
121 # Need to preserve line numbers for jinja2 tracebacks 121 # Need to preserve line numbers for jinja2 tracebacks
122 cutoff = m.end() if m else length 122 cutoff = m.end() if m else length
123 source = '\n' * source.count('\n', 0, cutoff) + source[cutoff:] 123 source = '\n' * source.count('\n', 0, cutoff) + source[cutoff:]
124 124
125 return metadata, source 125 return metadata, source
126 126
127 127
128 def get_page_params(source, locale, page, format=None, site_url_override=None, 128 def get_page_params(source, locale, page, format=None, site_url_override=None,
129 localized_string_callback=None): 129 localized_string_callback=None, relative=None):
130 from cms.converters import converters 130 from cms.converters import converters
131 131
132 # Guess page format if omitted, but default to Markdown for friendlier excep tions 132 # Guess page format if omitted, but default to Markdown for friendlier excep tions
133 if format is None: 133 if format is None:
134 for format in converters.iterkeys(): 134 for format in converters.iterkeys():
135 if source.has_page(page, format): 135 if source.has_page(page, format):
136 break 136 break
137 else: 137 else:
138 format = 'md' 138 format = 'md'
139 139
140 params = { 140 params = {
141 'source': source, 141 'source': source,
142 'template': 'default', 142 'template': 'default',
143 'locale': locale, 143 'locale': locale,
144 'page': page, 144 'page': page,
145 'config': source.read_config(), 145 'config': source.read_config(),
146 'localized_string_callback': localized_string_callback, 146 'localized_string_callback': localized_string_callback,
147 'relative': relative,
147 } 148 }
148 149
149 params['localedata'] = source.read_locale(params['locale'], page) 150 params['localedata'] = source.read_locale(params['locale'], page)
150 defaultlocale = params['config'].get('general', 'defaultlocale') 151 defaultlocale = params['config'].get('general', 'defaultlocale')
151 params['defaultlocale'] = defaultlocale 152 params['defaultlocale'] = defaultlocale
152 params['default_localedata'] = source.read_locale(defaultlocale, page) 153 params['default_localedata'] = source.read_locale(defaultlocale, page)
153 154
154 if params['config'].has_option('general', 'siteurl'): 155 if params['config'].has_option('general', 'siteurl'):
155 if site_url_override: 156 if site_url_override:
156 params['site_url'] = site_url_override 157 params['site_url'] = site_url_override
(...skipping 26 matching lines...) Expand all
183 params['translation_ratio'] = ( 184 params['translation_ratio'] = (
184 1 - float(converter.missing_translations) / converter.total_translat ions 185 1 - float(converter.missing_translations) / converter.total_translat ions
185 ) 186 )
186 else: 187 else:
187 params['translation_ratio'] = 1 188 params['translation_ratio'] = 1
188 189
189 return params 190 return params
190 191
191 192
192 def process_page(source, locale, page, format=None, site_url_override=None, 193 def process_page(source, locale, page, format=None, site_url_override=None,
193 localized_string_callback=None): 194 localized_string_callback=None, relative=False):
194 from cms.converters import TemplateConverter 195 from cms.converters import TemplateConverter
195 196
196 params = get_page_params(source, locale, page, format, site_url_override, 197 params = get_page_params(source, locale, page, format, site_url_override,
197 localized_string_callback) 198 localized_string_callback)
199 params['relative'] = relative
198 return TemplateConverter(*params['templatedata'], params=params)() 200 return TemplateConverter(*params['templatedata'], params=params)()
OLDNEW

Powered by Google App Engine
This is Rietveld