diff options
-rw-r--r-- | pysite/tables.py | 3 | ||||
-rw-r--r-- | pysite/views/main/jams/join.py | 14 | ||||
-rw-r--r-- | pysite/views/main/jams/profile.py | 59 | ||||
-rw-r--r-- | templates/main/jams/profile.html | 106 | ||||
-rw-r--r-- | templates/staff/jams/edit_basics.html | 1 |
5 files changed, 178 insertions, 5 deletions
diff --git a/pysite/tables.py b/pysite/tables.py index c68feba0..25e630b2 100644 --- a/pysite/tables.py +++ b/pysite/tables.py @@ -110,8 +110,7 @@ TABLES = { primary_key="id", keys=sorted([ "id", # str - "skill_level", # str - "age", # str + "dob", # str "github_username", # str "timezone" # str ]) diff --git a/pysite/views/main/jams/join.py b/pysite/views/main/jams/join.py index eeae1f76..83013a01 100644 --- a/pysite/views/main/jams/join.py +++ b/pysite/views/main/jams/join.py @@ -1,7 +1,7 @@ from email.utils import parseaddr -from flask import request, redirect, url_for -from werkzeug.exceptions import NotFound, BadRequest +from flask import redirect, request, url_for +from werkzeug.exceptions import BadRequest, NotFound from pysite.base_route import RouteView from pysite.decorators import csrf @@ -48,6 +48,11 @@ class JamsJoinView(RouteView, DBMixin, OauthMixin): # They already tried to apply for this jam return self.render("main/jams/banned.html", infraction=infraction, jam=jam_obj) + participant = self.db.get(self.participants_table, self.user_data["user_id"]) + + if not participant: + return redirect(url_for("info.jams.profile")) + if self.get_response(jam, self.user_data["user_id"]): return self.render("main/jams/already.html", jam=jam_obj) @@ -93,6 +98,11 @@ class JamsJoinView(RouteView, DBMixin, OauthMixin): # They already tried to apply for this jam return self.render("main/jams/banned.html", infraction=infraction, jam=jam_obj) + participant = self.db.get(self.participants_table, self.user_data["user_id"]) + + if not participant: + return redirect(url_for("info.jams.profile")) + if self.get_response(jam, self.user_data["user_id"]): return self.render("main/jams/already.html", jam=jam_obj) diff --git a/pysite/views/main/jams/profile.py b/pysite/views/main/jams/profile.py new file mode 100644 index 00000000..407f842e --- /dev/null +++ b/pysite/views/main/jams/profile.py @@ -0,0 +1,59 @@ +import datetime + +from flask import redirect, request, url_for +from werkzeug.exceptions import BadRequest + +from pysite.base_route import RouteView +from pysite.decorators import csrf +from pysite.mixins import DBMixin, OauthMixin + + +class JamsProfileView(RouteView, DBMixin, OauthMixin): + path = "/jams/profile" + name = "jams.profile" + + table_name = "code_jam_participants" + + def get(self): + if not self.user_data: + return redirect(url_for("discord.login")) + + participant = self.db.get(self.table_name, self.user_data["user_id"]) + + if not participant: + participant = {"id": self.user_data["user_id"]} + + return self.render( + "main/jams/profile.html", participant=participant + ) + + @csrf + def post(self): + if not self.user_data: + return redirect(url_for("discord.login")) + + participant = self.db.get(self.table_name, self.user_data["user_id"]) + + if not participant: + participant = {"id": self.user_data["user_id"]} + + dob = request.form.get("dob") + github_username = request.form.get("github_username") + timezone = request.form.get("timezone") + + if not dob or not github_username or not timezone: + return BadRequest() + + # Convert given datetime strings into actual objects, adding timezones to keep rethinkdb happy + dob = datetime.datetime.strptime(dob, "%Y-%m-%d") + dob = dob.replace(tzinfo=datetime.timezone.utc) + + participant["dob"] = dob + participant["github_username"] = github_username + participant["timezone"] = timezone + + self.db.insert(self.table_name, participant, conflict="replace") + + return self.render( + "main/jams/profile.html", participant=participant, done=True + ) diff --git a/templates/main/jams/profile.html b/templates/main/jams/profile.html new file mode 100644 index 00000000..6cf315d0 --- /dev/null +++ b/templates/main/jams/profile.html @@ -0,0 +1,106 @@ +{% extends "main/base.html" %} +{% block title %}Code Jams | Banned{% endblock %} +{% block og_title %}Code Jams | Banned{% endblock %} + +{% block extra_head %} + <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js" type="application/javascript"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.17/moment-timezone.min.js" type="application/javascript"></script> +{% endblock %} + +{% block content %} +<div class="uk-section"> + <div class="uk-container uk-container-small"> + <h1 class="uk-header uk-article-title"> + Code Jams: My Profile + </h1> + + {% if done %} + <p class="uk-alert uk-alert-success"> + Thanks - your data has been saved! + </p> + {% else %} + <p class="uk-alert uk-alert-primary"> + Please make sure you've filled this out correctly, as we do use this data when evaluating your code jam + application. + <br /> + <br /> + You may come back here and edit your data at any time. + </p> + {% endif %} + + <form class="uk-form-horizontal" action="{{ url_for("main.jams.profile") }}" method="post"> + <div> + <div class="uk-form-label"> + <label class="uk-form-label" for="dob">Date of Birth</label> + </div> + <div class="uk-form-controls-text uk-form-controls"> + <input class="uk-input" type="text" name="dob" id="dob" value="{{ participant.dob }}" required> + </div> + </div> + <div> + <div class="uk-form-label"> + <label class="uk-form-label" for="github_username">GitHub Username</label> + </div> + <div class="uk-form-controls-text uk-form-controls"> + <input class="uk-input" type="text" name="github_username" id="github_username" value="{{ participant.github_username }}" required> + </div> + </div> + <div> + <div class="uk-form-label"> + <label class="uk-form-label" for="timezone">Timezone</label> + </div> + <div class="uk-form-controls-text uk-form-controls"> + <input class="uk-input" type="text" name="timezone" id="timezone" value="{{ participant.timezone }}" required> + </div> + </div> + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> + <br /> + + <div class="uk-text-center"> + <a class="uk-button uk-button-default" href="{{ url_for("main.jams.index") }}"> + <i class="uk-icon fa-fw far fa-arrow-left"></i> Back + </a> + <button type="submit" class="uk-button uk-button-primary" id="submit"> + <i class="uk-icon fa-fw far fa-check"></i> Save + </button> + </div> + </form> + </div> +</div> + + + +<script type="application/javascript"> + const date = flatpickr("#dob", {enableTime: false, altInput: true}); + const tz = moment().format("Z"); + + const dob_input = document.getElementById("dob"); + const github_input = document.getElementById("github_username"); + const tz_input = document.getElementById("timezone"); + + const submit_button = document.getElementById("submit"); + + function checkInputs() { + if (dob_input.value.length < 1) + return submit_button.disabled = true; + + if (github_input.value.length < 1) + return submit_button.disabled = true; + + if (tz_input.value.length < 1) + return submit_button.disabled = true; + + submit_button.disabled = false; + } + + dob_input.oninput = checkInputs; + github_input.oninput = checkInputs; + tz_input.oninput = checkInputs; + + if (tz_input.value.length < 1) { + document.getElementById("timezone").value = "UTC" + tz; + } + + checkInputs(); +</script> +{% endblock %} diff --git a/templates/staff/jams/edit_basics.html b/templates/staff/jams/edit_basics.html index 59d69b77..e9bc69e1 100644 --- a/templates/staff/jams/edit_basics.html +++ b/templates/staff/jams/edit_basics.html @@ -66,7 +66,6 @@ </button> </div> </form> - </div> <script type="application/javascript"> |