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
63
64
65
66
67
68
69
70
71
|
from flask import redirect, request, url_for
from werkzeug.exceptions import BadRequest
from pysite.base_route import RouteView
from pysite.decorators import csrf
from pysite.mixins import DBMixin, OAuthMixin
class JamsProfileView(RouteView, DBMixin, OAuthMixin):
path = "/jams/profile"
name = "jams.profile"
table_name = "code_jam_participants"
def get(self):
if not self.user_data:
return self.redirect_login()
participant = self.db.get(self.table_name, self.user_data["user_id"])
existing = True
if not participant:
participant = {"id": self.user_data["user_id"]}
existing = False
form = request.args.get("form")
if form:
try:
form = int(form)
except ValueError:
pass # Someone trying to have some fun I guess
return self.render(
"main/jams/profile.html", participant=participant, form=form, existing=existing
)
@csrf
def post(self):
if not self.user_data:
return self.redirect_login()
participant = self.db.get(self.table_name, self.user_data["user_id"])
if not participant:
participant = {"id": self.user_data["user_id"]}
github_username = request.form.get("github_username")
timezone = request.form.get("timezone")
if not github_username or not timezone:
return BadRequest()
participant["github_username"] = github_username
participant["timezone"] = timezone
self.db.insert(self.table_name, participant, conflict="replace")
form = request.args.get("form")
if form:
try:
form = int(form)
except ValueError:
pass # Someone trying to have some fun I guess
else:
return redirect(url_for("main.jams.join", jam=form))
return self.render(
"main/jams/profile.html", participant=participant, done=True, existing=True
)
|