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

Unified Diff: cms/sources.py

Issue 5694103719247872: Issue 2133 - Allow to specify default translation inline in pages rather than in a separate file (Closed)
Patch Set: Created March 12, 2015, 7:34 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
Index: cms/sources.py
===================================================================
--- a/cms/sources.py
+++ b/cms/sources.py
@@ -37,17 +37,17 @@ class Source:
checked_page = page
if config.has_option("locale_overrides", page):
checked_page = config.get("locale_overrides", page)
if self.has_localizable_file(default_locale, checked_page):
if not self.has_localizable_file(locale, checked_page):
locale = default_locale
- elif self.has_locale(default_locale, checked_page):
+ elif self.has_page(checked_page):
if not self.has_locale(locale, checked_page):
locale = default_locale
else:
print >>sys.stderr, "Warning: Link to %s cannot be resolved" % page
if page == default_page:
page = ""
@@ -69,18 +69,25 @@ class Source:
return "pages/%s.%s" % (page, format)
def list_pages(self):
for filename in self.list_files("pages"):
root, ext = os.path.splitext(filename)
format = ext[1:].lower()
yield root, format
- def has_page(self, page, format):
- return self.has_file(self.page_filename(page, format))
+ def has_page(self, page, format=None):
+ if format is None:
+ from .converters import converters
Sebastian Noack 2015/03/12 20:33:46 From PEP-8: "Relative imports for intra-package im
Wladimir Palant 2015/03/12 20:57:02 Relative imports actually made moving this out of
Sebastian Noack 2015/03/12 21:08:19 Fair enough. I'm looking forward that change. :)
+ return any(
+ self.has_page(page, format)
+ for format in converters.iterkeys()
Sebastian Noack 2015/03/12 20:33:46 Nit: Do you know that you can lazily iterate over
Wladimir Palant 2015/03/12 20:57:02 Yes, I know that. However, I prefer to keep things
Sebastian Noack 2015/03/12 21:08:19 So you would also use .. for (let key of Object.k
Wladimir Palant 2015/03/12 21:15:27 These constructs aren't actually equivalent. Besid
+ )
+ else:
+ return self.has_file(self.page_filename(page, format))
def read_page(self, page, format):
return self.read_file(self.page_filename(page, format))
#
# Localizable files helpers
#

Powered by Google App Engine
This is Rietveld