diff options
author | 2018-07-02 13:02:08 +0000 | |
---|---|---|
committer | 2018-07-02 13:02:08 +0000 | |
commit | f4b71a32ee210f049025962e790c080b976945e1 (patch) | |
tree | 417db0c4f3ada7a5a23a444b797d1bab74413333 | |
parent | [Jams/Teams] Show pushes creating new branches in GitLab activity (diff) | |
parent | Fix typo from last commit (diff) |
Merge branch 'momo/enhance-jam-index' into 'master'
Disable the join button if the user has already applied to a code jam
See merge request python-discord/projects/site!7
-rw-r--r-- | pysite/views/main/jams/index.py | 16 | ||||
-rw-r--r-- | templates/main/jams/index.html | 12 |
2 files changed, 24 insertions, 4 deletions
diff --git a/pysite/views/main/jams/index.py b/pysite/views/main/jams/index.py index abe2859f..652779b2 100644 --- a/pysite/views/main/jams/index.py +++ b/pysite/views/main/jams/index.py @@ -29,4 +29,18 @@ class JamsIndexView(RouteView, DBMixin): ) jams = self.db.run(query, coerce=list) - return self.render("main/jams/index.html", jams=jams) + return self.render("main/jams/index.html", jams=jams, has_applied_to_jam=self.has_applied_to_jam) + + def get_jam_response(self, jam, user_id): + query = self.db.query("code_jam_responses").filter({"jam": jam, "snowflake": user_id}) + result = self.db.run(query, coerce=list) + + if result: + return result[0] + return None + + def has_applied_to_jam(self, jam): + # whether the user has applied to this jam + if not self.logged_in: + return False + return self.get_jam_response(jam, self.user_data["user_id"]) diff --git a/templates/main/jams/index.html b/templates/main/jams/index.html index b2ffa1af..9a228b74 100644 --- a/templates/main/jams/index.html +++ b/templates/main/jams/index.html @@ -62,9 +62,15 @@ Code Jam {{ jam.number }}: {{ jam.title }} <span class="uk-float-right"> {% if jam.state == "announced" %} - <a class="uk-button uk-button-primary" href="{{ url_for("main.jams.join", jam=jam.number) }}"> - <i class="uk-icon fa-fw far fa-plus"></i> Join - </a> + {% if has_applied_to_jam(jam) %} + <a class="uk-button uk-button-default uk-disabled" href="#"> + <i class="uk-icon fa-fw far fa-check"></i> Applied + </a> + {% else %} + <a class="uk-button uk-button-primary" href="{{ url_for("main.jams.join", jam=jam.number) }}"> + <i class="uk-icon fa-fw far fa-plus"></i> Join + </a> + {% endif %} {% else %} {% if jam.teams and jam.teams | length > 0 %} <a class="uk-button uk-button-primary" href="{{ url_for('main.jams.jam_team_list', jam_id=jam.number) }}"> |