diff options
author | 2018-06-23 17:48:43 -0400 | |
---|---|---|
committer | 2018-06-23 17:48:43 -0400 | |
commit | 6ce048d6b3c5518ada39022b164c4aec41c7f5c9 (patch) | |
tree | a5230460f720f5536f0c4ee8dacab82a8a105f56 /pysite | |
parent | [API] Check for DB-nuking empty data in users POST (diff) |
[Jams/Teams] Simplify getting the code jam for a team (team -> jam)
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/migrations/tables/code_jam_teams/__init__.py | 0 | ||||
-rw-r--r-- | pysite/migrations/tables/code_jam_teams/v1.py | 12 | ||||
-rw-r--r-- | pysite/tables.py | 3 | ||||
-rw-r--r-- | pysite/views/main/jams/team_edit_repo.py | 5 | ||||
-rw-r--r-- | pysite/views/main/jams/team_view.py | 5 | ||||
-rw-r--r-- | pysite/views/main/jams/user_team_list.py | 5 |
6 files changed, 17 insertions, 13 deletions
diff --git a/pysite/migrations/tables/code_jam_teams/__init__.py b/pysite/migrations/tables/code_jam_teams/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/pysite/migrations/tables/code_jam_teams/__init__.py diff --git a/pysite/migrations/tables/code_jam_teams/v1.py b/pysite/migrations/tables/code_jam_teams/v1.py new file mode 100644 index 00000000..563a146b --- /dev/null +++ b/pysite/migrations/tables/code_jam_teams/v1.py @@ -0,0 +1,12 @@ +def run(db, table, table_obj): + """ + Associate the ID of each team's code jam (team -> jam) + """ + + for document in db.get_all(table): + if "jam" not in document: + # find the code jam containing this team + for jam in db.get_all("code_jams"): + if document["id"] in jam["teams"]: + document["jam"] = jam["number"] + db.insert(table, document, conflict="update", durability="soft") diff --git a/pysite/tables.py b/pysite/tables.py index 191b52bd..c7072909 100644 --- a/pysite/tables.py +++ b/pysite/tables.py @@ -94,7 +94,8 @@ TABLES = { "id", # uuid "name", # str "members", # list[str] - "repo" # str + "repo", # str + "jam" # int ]) ), diff --git a/pysite/views/main/jams/team_edit_repo.py b/pysite/views/main/jams/team_edit_repo.py index 03f23f17..03e752bc 100644 --- a/pysite/views/main/jams/team_edit_repo.py +++ b/pysite/views/main/jams/team_edit_repo.py @@ -33,10 +33,7 @@ class JamsTeamEditRepo(APIView, DBMixin, OAuthMixin): try: query = self.db.query(self.table_name).get(team_id).merge( lambda team: { - "jam": - self.db.query("code_jams").filter( - lambda jam: jam["teams"].contains(team["id"]) - ).coerce_to("array")[0] + "jam": self.db.query("code_jams").get(team["jam"]) } ) diff --git a/pysite/views/main/jams/team_view.py b/pysite/views/main/jams/team_view.py index 2d99828c..68308934 100644 --- a/pysite/views/main/jams/team_view.py +++ b/pysite/views/main/jams/team_view.py @@ -29,10 +29,7 @@ class JamsTeamView(RouteView, DBMixin, OAuthMixin): ).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] + "jam": self.db.query("code_jams").get(team["jam"]) } ) diff --git a/pysite/views/main/jams/user_team_list.py b/pysite/views/main/jams/user_team_list.py index 272c0a74..226cc4b0 100644 --- a/pysite/views/main/jams/user_team_list.py +++ b/pysite/views/main/jams/user_team_list.py @@ -25,10 +25,7 @@ class JamsUserTeamListView(RouteView, DBMixin, OAuthMixin): 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] + "jam": self.db.query("code_jams").get(team["jam"]) } ).order_by(rethinkdb.desc("jam.number")) teams = self.db.run(query) |