-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubcron.py
62 lines (48 loc) · 1.51 KB
/
pubcron.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
import webapp2
from google.appengine.api import users
import utils
import models
class TermException(Exception):
"""Exception to notify term error."""
pass
def get_user_data(parent):
"""Make sure user is logged in and get their account data."""
# Get user login status.
user = users.get_current_user()
if user is None:
# User is not logged in... Go log in then.
parent.redirect(users.create_login_url(parent.request.uri))
return None
# User is logged in.
data = models.UserData.get_by_key_name(user.user_id())
if data is None:
# First time logged in. Welcome then.
data = models.init_data(user)
return data
class TemplateServer(webapp2.RequestHandler):
def get(self, query):
if not query: query = 'index'
template = {
'index': 'base.html',
'about': 'about.html',
'FAQE': 'FAQE.html',
}.get(query, '404.html')
self.response.out.write(utils.render(template))
class QueryPageServer(webapp2.RequestHandler):
def get(self):
data = get_user_data(self)
self.response.out.write(utils.render(
'query.html',
{'data':data}
))
class QueryUpdateServer(webapp2.RequestHandler):
def post(self):
data = get_user_data(self)
updated = utils.try_to_update_term(data, self.request.get('term'))
self.redirect('/query')
app = webapp2.WSGIApplication([
('/query', QueryPageServer),
('/update', QueryUpdateServer),
('/(.*)', TemplateServer),
])