aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar momothereal <[email protected]>2018-06-23 18:08:16 -0400
committerGravatar momothereal <[email protected]>2018-06-23 18:08:16 -0400
commit2734934c3c21e46c22a967a9a69713d418269e55 (patch)
tree8921e33ab5ab7bf64cfb7f9aa6e2c8db749d9fe7
parent[Jams/Teams] Simplify getting the code jam for a team (team -> jam) (diff)
[Jams/Teams] De-associate delete teams from jams
-rw-r--r--pysite/migrations/tables/code_jam_teams/v1.py1
-rw-r--r--pysite/migrations/tables/code_jams/v2.py10
-rw-r--r--pysite/views/staff/jams/actions.py15
3 files changed, 25 insertions, 1 deletions
diff --git a/pysite/migrations/tables/code_jam_teams/v1.py b/pysite/migrations/tables/code_jam_teams/v1.py
index 563a146b..165d3100 100644
--- a/pysite/migrations/tables/code_jam_teams/v1.py
+++ b/pysite/migrations/tables/code_jam_teams/v1.py
@@ -10,3 +10,4 @@ def run(db, table, table_obj):
if document["id"] in jam["teams"]:
document["jam"] = jam["number"]
db.insert(table, document, conflict="update", durability="soft")
+ db.sync(table)
diff --git a/pysite/migrations/tables/code_jams/v2.py b/pysite/migrations/tables/code_jams/v2.py
new file mode 100644
index 00000000..df4752c8
--- /dev/null
+++ b/pysite/migrations/tables/code_jams/v2.py
@@ -0,0 +1,10 @@
+def run(db, table, table_obj):
+ """
+ Clean list of teams from teams that do not exist anymore.
+ """
+ for document in db.get_all(table):
+ for team_id in document["teams"]:
+ if db.get("code_jam_teams", team_id) is None:
+ document["teams"].remove(team_id)
+ db.insert(table, document, conflict="update", durability="soft")
+ db.sync(table)
diff --git a/pysite/views/staff/jams/actions.py b/pysite/views/staff/jams/actions.py
index 3f8b4c20..c97f0d8c 100644
--- a/pysite/views/staff/jams/actions.py
+++ b/pysite/views/staff/jams/actions.py
@@ -221,7 +221,8 @@ class ActionView(APIView, DBMixin, RMQMixin):
team = {
"name": f"{adjective} {noun}".title(),
- "members": []
+ "members": [],
+ "jam": jam
}
result = self.db.insert(self.teams_table, team)
@@ -538,6 +539,18 @@ class ActionView(APIView, DBMixin, RMQMixin):
ErrorCodes.incorrect_parameters, "Team ID required"
)
+ team_obj = self.db.get(self.teams_table, team)
+
+ if not team_obj:
+ return self.error(
+ ErrorCodes.incorrect_parameters, "Unknown team ID"
+ )
+
+ jam_obj = self.db.get(self.table_name, team_obj["jam"])
+ if jam_obj:
+ jam_obj["teams"].remove(team)
+ self.db.insert(self.table_name, jam_obj, conflict="update")
+
self.db.delete(self.teams_table, team)
return jsonify({"result": True})