blob: ebb1a5ce42c12292ae6348247aebc78750581f7b (
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
|
import logging
from rethinkdb import ReqlNonExistenceError
from werkzeug.exceptions import NotFound
from pysite.base_route import RouteView
from pysite.mixins import DBMixin, OAuthMixin
log = logging.getLogger(__name__)
class JamsTeamsListView(RouteView, DBMixin, OAuthMixin):
path = "/jams/team/<string:team_id>"
name = "jams.team_view"
table_name = "code_jam_teams"
def get(self, team_id: str):
try:
query = self.db.query(self.table_name).get(team_id).merge(
lambda team: {
"members":
self.db.query("users")
.filter(lambda user: team["members"].contains(user["user_id"]))
.merge(
lambda user: {
"gitlab_username": self.db.query("code_jam_participants").filter(
{"id": user["user_id"]}
).coerce_to("array")[0]["gitlab_username"]
}
).coerce_to("array"),
"jam":
self.db.query("code_jams").filter(
lambda jam: jam["teams"].contains(team["id"])
).coerce_to("array")[0]
}
)
team = self.db.run(query)
except ReqlNonExistenceError:
log.exception("Failed RethinkDB query")
raise NotFound()
return self.render(
"main/jams/team_view.html",
team=team
)
|