blob: 6b95db76365f1d2636d24c40335fc2d338d275ba (
plain) (
blame)
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
|
from rethinkdb import ReqlNonExistenceError
from werkzeug.exceptions import NotFound
from pysite.base_route import RouteView
from pysite.constants import ALL_STAFF_ROLES
from pysite.decorators import require_roles
from pysite.mixins import DBMixin
REQUIRED_KEYS = ["title", "date_start", "date_end"]
class StaffView(RouteView, DBMixin):
path = "/jams/participants/<int:jam>"
name = "jams.participants"
forms_table = "code_jam_forms"
participants_table = "code_jam_participants"
questions_table = "code_jam_questions"
responses_table = "code_jam_responses"
table_name = "code_jams"
users_table = "users"
@require_roles(*ALL_STAFF_ROLES)
def get(self, jam: int):
try:
query = self.db.query(self.table_name).get(jam).merge(
lambda jam_obj: {
"participants":
self.db.query(self.responses_table)
.filter({"jam": jam_obj["number"]})
.eq_join("snowflake", self.db.query(self.users_table))
.without({"left": "snowflake"})
.zip()
.coerce_to("array")
}
)
jam_data = self.db.run(query)
except ReqlNonExistenceError:
raise NotFound()
form_obj = self.db.get(self.forms_table, jam)
questions = {}
if form_obj:
for question in form_obj["questions"]:
questions[question] = self.db.get(self.questions_table, question)
return self.render(
"staff/jams/participants.html",
jam=jam_data, form=form_obj, questions=questions
)
|