diff options
| author | 2018-06-19 14:53:49 -0400 | |
|---|---|---|
| committer | 2018-06-19 14:53:49 -0400 | |
| commit | ca900f7a8e363dbc832cb77149a980adcd225102 (patch) | |
| tree | c43d003f488136aa5457f13cf868d610321e9a80 | |
| parent | [Jams] EasyList was blocking the JetBrains logo (diff) | |
Disable the join button if the user has already applied to a code jam
| -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 8d34fa50..f05f6b79 100644 --- a/pysite/views/main/jams/index.py +++ b/pysite/views/main/jams/index.py @@ -17,5 +17,19 @@ class JamsIndexView(RouteView, DBMixin):              .limit(5)          ) +        def has_applied_to_jam(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"]) +          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=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 diff --git a/templates/main/jams/index.html b/templates/main/jams/index.html index e2201398..8e6985c6 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 %}                                  <a class="uk-button uk-button-default" target="_blank" href="{{ jam.repo }}">                                      <i class="uk-icon fa-fw fab fa-gitlab"></i>  Repository | 
