Example #1
0
File: mainweb.py Project: sup6/pali
def commonPage(prefix, word, reqHandlerName, urlLocale=None):
  if type(prefix) is not unicode:
    prefix = prefix.decode('utf-8')

  if word:
    if type(word) is not unicode:
      word = word.decode('utf-8')

  if not isValidPrefixAndWord(prefix, word):
    raise web.notfound()

  template_values = commonTemplateValues(
      urlLocale, reqHandlerName, prefix, word)

  if reqHandlerName == 'WordPage':
    pageHtml = getWordHtml(prefix, word)
  elif reqHandlerName == 'PrefixPage':
    pageHtml = getPrefixHtml(prefix)
  else:
    raise Exception('invalid reqHandlerName: %s' % reqHandlerName)

  if pageHtml is None: raise web.notfound()
  template_values['pageHtml'] = pageHtml
  template = jinja_environment.get_template('index.html')
  return template.render(template_values)
Example #2
0
def commonPage(prefix, word, reqHandlerName, urlLocale=None):
  if web.ctx.host.split(':')[0] == "palidictionary.appspot.com":
    # redirect to new domain
    url = "http://dictionary.online-dhamma.net" + \
          urllib.quote(web.ctx.path.encode('utf-8')) + \
          web.ctx.query
    raise web.redirect(url)

  if type(prefix) is not unicode:
    prefix = prefix.decode('utf-8')

  if word:
    if type(word) is not unicode:
      word = word.decode('utf-8')

  if not isValidPrefixAndWord(prefix, word):
    raise web.notfound()

  template_values = commonTemplateValues(
      urlLocale, reqHandlerName, prefix, word)

  if reqHandlerName == 'WordPage':
    pageHtml = getWordHtml(prefix, word)
  elif reqHandlerName == 'PrefixPage':
    pageHtml = getPrefixHtml(prefix)
  else:
    raise Exception('invalid reqHandlerName: %s' % reqHandlerName)

  if pageHtml is None: raise web.notfound()
  template_values['pageHtml'] = pageHtml
  template = jinja_environment.get_template('index.html')
  return template.render(template_values)
Example #3
0
 def get(self, prefix, urlLocale=None):
     if not isValidPrefixAndWord(prefix, None):
         self.abort(404)
     template_values = getCommonTemplateValues(self, urlLocale, prefix)
     prefixHtml = getPrefixHtml(prefix)
     if prefixHtml is None:
         self.abort(404)
     template_values['pageHtml'] = prefixHtml
     template = jinja_environment.get_template('index.html')
     self.response.out.write(template.render(template_values))
Example #4
0
 def get(self, prefix,  urlLocale=None):
   if not isValidPrefixAndWord(prefix, None):
     self.abort(404)
   template_values = getCommonTemplateValues(self, urlLocale, prefix)
   prefixHtml = getPrefixHtml(prefix)
   if prefixHtml is None:
     self.abort(404)
   template_values['pageHtml'] = prefixHtml
   template = jinja_environment.get_template('index.html')
   self.response.out.write(template.render(template_values))