-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
49 lines (38 loc) · 1.07 KB
/
admin.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
import os
import cgi
import urllib
import datetime
import pytz
from pytz import timezone
from google.appengine.api import users
from google.appengine.ext import ndb
import jinja2
import webapp2
import data_model
JINJA_ENVIRONMENT = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'views')),
extensions = ['jinja2.ext.autoescape'],
autoescape = True)
def getUsers():
users_query = data_model.User.query()
return (users_query.fetch())
class MainPage(webapp2.RequestHandler):
def get(self):
users = getUsers()
template_values = {
'users': users,
}
template = JINJA_ENVIRONMENT.get_template('admin.html')
self.response.write(template.render(template_values))
class AddUser(webapp2.RequestHandler):
def post(self):
nickname = self.request.get('nickname')
user_key = ndb.Key('User', nickname)
user = data_model.User(key = user_key)
user.nickname = nickname
user.put()
self.redirect('/admin/')
application = webapp2.WSGIApplication([
('/admin/', MainPage),
('/admin/add_user', AddUser),
], debug=True)