-
Notifications
You must be signed in to change notification settings - Fork 1
/
GamesEditHandler.py
45 lines (39 loc) · 1.28 KB
/
GamesEditHandler.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
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import login_required
from models import *
import os
import logging
class GamesEditHandler(webapp.RequestHandler):
@login_required
def get(self):
if not users.is_current_user_admin():
self.redirect('/')
else:
gameID = self.request.get("gameID")
game = db.get(db.Key(gameID))
template_stuff = {'gameID': gameID , 'game': game}
path = os.path.join(os.path.dirname(__file__), 'templates/editgame.html')
self.response.out.write(template.render(path, template_stuff))
def post(self):
user = users.get_current_user()
if not user:
self.error(401)
return
if not users.is_current_user_admin():
self.error(401)
return
try:
gameID = self.request.get("gameID")
homeGoals = int(self.request.get("homeGoals"))
awayGoals = int(self.request.get("awayGoals"))
game = db.get(db.Key(gameID))
game.homeGoals = homeGoals
game.awayGoals = awayGoals
game.played = True
game.put()
self.redirect("/")
except (TypeError, ValueError):
path = os.path.join(os.path.dirname(__file__), 'templates/editgame.html')
self.response.out.write(template.render(path, template_stuff))