aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/views/staff/jams/actions.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-05-18 16:00:31 +0100
committerGravatar Gareth Coles <[email protected]>2018-05-18 16:00:31 +0100
commite1846928439aa2a7e660d870a083872c415c274d (patch)
treee716f3466ca3914f80b2ca102d5d345658af7bc8 /pysite/views/staff/jams/actions.py
parentUpdate wiki footer in line with main site (diff)
[Jams] Huge amount of work on code jam admin area
Diffstat (limited to 'pysite/views/staff/jams/actions.py')
-rw-r--r--pysite/views/staff/jams/actions.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/pysite/views/staff/jams/actions.py b/pysite/views/staff/jams/actions.py
new file mode 100644
index 00000000..93a7f2c7
--- /dev/null
+++ b/pysite/views/staff/jams/actions.py
@@ -0,0 +1,36 @@
+from flask import jsonify, request
+
+from pysite.base_route import APIView
+from pysite.constants import ALL_STAFF_ROLES, ErrorCodes
+from pysite.decorators import csrf, require_roles
+from pysite.mixins import DBMixin
+
+ACTIONS = ["state"]
+KEYS = ["action"]
+
+
+class ActionView(APIView, DBMixin):
+ path = "/jams/action/"
+ name = "jams.action"
+ table_name = "code_jams"
+
+ @csrf
+ @require_roles(*ALL_STAFF_ROLES)
+ def post(self):
+ action = request.args.get("action")
+
+ if action not in ACTIONS:
+ return self.error(ErrorCodes.incorrect_parameters)
+
+ if action == "state":
+ jam = int(request.args.get("jam"))
+ state = request.args.get("state")
+
+ if not all((jam, state)):
+ return self.error(ErrorCodes.incorrect_parameters)
+
+ jam_obj = self.db.get(self.table_name, jam)
+ jam_obj["state"] = state
+ self.db.insert(self.table_name, jam_obj, conflict="update")
+
+ return jsonify({})