Source

wodewish / main.py

# -*- coding: utf-8 -*-

import kcbuser
from kcbuser import kcb,kcbuser,kcbterm
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import db
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
############__________________________________________________________________________
import re


class MainPage(webapp.RequestHandler):
  def get(self):
	  User=None
	  template_values = {

	  'USER':User,
      }
	  path = os.path.join(os.path.dirname(__file__), 'tpl','mainpage.html')
	  self.response.out.write(template.render(path, template_values))

class AboutPage(webapp.RequestHandler):
  def get(self):
	  User=None
	  template_values = {

	  'USER':User,
      }
	  path = os.path.join(os.path.dirname(__file__), 'tpl','aboutpage.html')
	  self.response.out.write(template.render(path, template_values))

class ShortUrlHandler(webapp.RequestHandler):
  def get(self,url):
	  try:
		USER=db.GqlQuery('SELECT __key__ FROM kcbuser WHERE url = :1', url.lower())
		user=USER[0]
		if db.get(user).public==1 :
			try:
				NowTerm=db.get(db.get(user).nowterm)
				NoTerm=None
			except:
				NowTerm=None
				NoTerm=u'''当前没有列表'''
			try:
				TERMS=db.get(user).kcbterm_set.order("weight")
			except AttributeError:
				TERMS=None



			template_values = {
			'TERMS':TERMS,
			'USER':users.get_current_user(),
			'NAME':db.get(user).name,
			}

			path = os.path.join(os.path.dirname(__file__), 'tpl','bingo.html')
			self.response.out.write(template.render(path, template_values))
		else:
			self.redirect('/signin')
	  except IndexError:
		self.redirect('/signin')

application = webapp.WSGIApplication([
('/', MainPage),
('/about', AboutPage),
('/(.*)', ShortUrlHandler),

],debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()