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

Unified Diff: cms/sources.py

Issue 5217703262420992: Issue 2181 - [cms] Test server should accept default page for subdirectories as well (Closed)
Patch Set: Created March 19, 2015, 10:31 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
« no previous file with comments | « cms/bin/test_server.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/sources.py
===================================================================
--- a/cms/sources.py
+++ b/cms/sources.py
@@ -22,39 +22,45 @@ from ConfigParser import SafeConfigParse
class Source:
def resolve_link(self, url, locale):
parsed = urlparse.urlparse(url)
page = parsed.path
if parsed.scheme != "" or page.startswith("/") or page.startswith("."):
# Not a page link
return None, None
- if parsed.path == "" and url != "":
+ if page == "" and url != "":
# Page-relative link
return None, None
+ def has_locale(locale, page):
+ if config.has_option("locale_overrides", page):
Sebastian Noack 2015/03/20 09:47:41 I'd prefer to call config.get() without prior chec
Wladimir Palant 2015/03/20 15:42:36 Done.
+ page = config.get("locale_overrides", page)
+ return self.has_locale(locale, page)
+
config = self.read_config()
default_locale = config.get("general", "defaultlocale")
default_page = config.get("general", "defaultpage")
+ alternative_page = "/".join([page, default_page]).lstrip("/")
- checked_page = page
- if config.has_option("locale_overrides", page):
- checked_page = config.get("locale_overrides", page)
Wladimir Palant 2015/03/19 22:33:53 Sorry about the marginally related changes but thi
-
- if self.has_localizable_file(default_locale, checked_page):
- if not self.has_localizable_file(locale, checked_page):
+ if self.has_localizable_file(default_locale, page):
+ if not self.has_localizable_file(locale, page):
locale = default_locale
- elif self.has_page(checked_page):
- if not self.has_locale(locale, checked_page):
+ elif self.has_page(page):
+ if not has_locale(locale, page):
+ locale = default_locale
+ elif self.has_page(alternative_page):
+ if not has_locale(locale, alternative_page):
locale = default_locale
else:
print >>sys.stderr, "Warning: Link to %s cannot be resolved" % page
- if page == default_page:
- page = ""
+ parts = page.split("/")
+ if parts[-1] == default_page:
+ page = "/".join(parts[:-1])
path = "/%s/%s" % (locale, page)
return locale, urlparse.urlunparse(parsed[0:2] + (path,) + parsed[3:])
def read_config(self):
configdata = self.read_file("settings.ini")
config = SafeConfigParser()
config.readfp(StringIO(configdata))
« no previous file with comments | « cms/bin/test_server.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld