Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix to redirect url

  • Loading branch information...
commit d0d567d6fc45365c66c29e0b91876e5656e6bb33 1 parent c76d77e
@dean-m dean-m authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 main.py
View
17 main.py
@@ -82,6 +82,7 @@ class MainHandler(webapp.RequestHandler):
def get(self, pagename, site = PB_WIKI):
skip_cache = self.request.get('cache') == '0'
version = os.environ['CURRENT_VERSION_ID']
+ shouldRedirect = False
redirect_urls = {
# From: To
@@ -101,19 +102,25 @@ def get(self, pagename, site = PB_WIKI):
if CDN_ENABLED:
cdn = CDN_HOSTNAME
try:
+ pageKey = 'page:%s' % pagename.lower()
if not(pagename):
pagename = 'FrontPage'
page = _request(PB_API_URL % (site, pagename), cache_ttl=604800, force=skip_cache)
# fetch a page where a lowercase version may exist
- if not(page):
- pagename = memcache.get(pagename.lower())
- page = _request(PB_API_URL % (site, pagename), cache_ttl=604800, force=skip_cache)
+ if not(page and "name" in page):
+ if memcache.get(pageKey):
+ pagename = memcache.get(pageKey)
+ page = _request(PB_API_URL % (site, pagename), cache_ttl=604800, force=skip_cache)
+ shouldRedirect = True
# Convert quasi-camel-case to spaced words
title = re.sub('([a-z]|[A-Z])([A-Z])', r'\1 \2', pagename)
if page and "name" in page:
fiveDays = 432000
- memcache.set(pagename.lower(), pagename, fiveDays)
- self.response.out.write(template.render('templates/content.html', locals()))
+ memcache.set(pageKey, pagename, fiveDays)
+ if shouldRedirect:
+ self.redirect(pagename, permanent=True)
+ else:
+ self.response.out.write(template.render('templates/content.html', locals()))
else:
raise LookupError
except LookupError:
Please sign in to comment.
Something went wrong with that request. Please try again.