changeset 1085:16e190fa6ef8

Port contests app to V3 design.
author Brian Neal <bgneal@gmail.com>
date Mon, 02 May 2016 20:03:18 -0500
parents 5fa22ed8bfb2
children aa43db10c565
files contests/static/js/contests/contests.js contests/urls.py contests/views.py core/templatetags/core_tags.py sg101/templates/comments/comment_form.html sg101/templates/contests/contest_detail.html sg101/templates/contests/contest_list.html sg101/templates/core/v3/social_sharing_tag.html
diffstat 8 files changed, 124 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/contests/static/js/contests/contests.js	Wed Apr 27 20:04:05 2016 -0500
+++ b/contests/static/js/contests/contests.js	Mon May 02 20:03:18 2016 -0500
@@ -12,7 +12,7 @@
          },
          dataType: 'json',
          success: function (data, textStatus) {
-            var classname = data.entered ? 'success' : 'info';
+            var classname = 'success callout';
             var $p = $('#contest-entry');
             $p.hide();
             $p.addClass(classname);
--- a/contests/urls.py	Wed Apr 27 20:04:05 2016 -0500
+++ b/contests/urls.py	Mon May 02 20:03:18 2016 -0500
@@ -3,17 +3,13 @@
 
 """
 from django.conf.urls import url
-from django.views.generic import DetailView, ListView
 
-from contests.models import Contest
 import contests.views
 
 
 urlpatterns = [
    url(r'^$',
-       ListView.as_view(
-           context_object_name='contests',
-           queryset=Contest.public_objects.all().prefetch_related('winners')),
+       contests.views.ContestListView.as_view(),
        name='contests-index'),
 
    url(r'^enter/$',
@@ -21,8 +17,6 @@
        name='contests-enter'),
 
    url(r'^c/(?P<slug>[\w-]+)/$',
-       DetailView.as_view(
-           context_object_name='contest',
-           queryset=Contest.public_objects.all().prefetch_related('winners')),
+       contests.views.ContestDetailView.as_view(),
        name='contests-contest'),
 ]
--- a/contests/views.py	Wed Apr 27 20:04:05 2016 -0500
+++ b/contests/views.py	Mon May 02 20:03:18 2016 -0500
@@ -8,10 +8,31 @@
         HttpResponseBadRequest)
 from django.shortcuts import get_object_or_404
 from django.views.decorators.http import require_POST
+from django.views.generic import DetailView, ListView
 
 from contests.models import Contest
 
 
+class ContestListView(ListView):
+    context_object_name = 'contests'
+    queryset=Contest.public_objects.all()
+
+    def get_context_data(self, **kwargs):
+        context = super(ContestListView, self).get_context_data(**kwargs)
+        context['V3_DESIGN'] = True
+        return context
+
+
+class ContestDetailView(DetailView):
+    context_object_name = 'contest'
+    queryset=Contest.public_objects.all().prefetch_related('winners')
+
+    def get_context_data(self, **kwargs):
+        context = super(ContestDetailView, self).get_context_data(**kwargs)
+        context['V3_DESIGN'] = True
+        return context
+
+
 @require_POST
 def enter(request):
     """
--- a/core/templatetags/core_tags.py	Wed Apr 27 20:04:05 2016 -0500
+++ b/core/templatetags/core_tags.py	Mon May 02 20:03:18 2016 -0500
@@ -61,8 +61,8 @@
     }
 
 
-@register.inclusion_tag('core/social_sharing_tag.html')
-def social_sharing(title, url):
+@register.simple_tag(takes_context=True)
+def social_sharing(context, title, url):
     """
     Displays social media sharing buttons.
 
@@ -70,10 +70,14 @@
     site = Site.objects.get_current()
     url = _fully_qualify(url, site.domain)
 
-    return {
-        'title': title,
-        'url': url,
-    }
+    template_name = ('core/v3/social_sharing_tag.html'
+        if 'V3_DESIGN' in context else 'core/social_sharing_tag.html')
+    t = template.loader.get_template(template_name)
+
+    with context.push():
+        context['title'] = title
+        context['url'] = url
+        return t.render(context)
 
 
 def _fully_qualify(url, domain):
--- a/sg101/templates/comments/comment_form.html	Wed Apr 27 20:04:05 2016 -0500
+++ b/sg101/templates/comments/comment_form.html	Mon May 02 20:03:18 2016 -0500
@@ -3,7 +3,7 @@
 <form action="{% url 'comments-post' %}" method="post" id="comment-form">{% csrf_token %}
 {{ form.as_p }}
 {% comment_dialogs %}
-<input type="submit" name="post" value="Post Comment" id="comment-form-post"/>
+<input type="submit" name="post" value="Post Comment" id="comment-form-post" class="primary button"/>
 </form>
 {% else %}
 <p>
--- a/sg101/templates/contests/contest_detail.html	Wed Apr 27 20:04:05 2016 -0500
+++ b/sg101/templates/contests/contest_detail.html	Mon May 02 20:03:18 2016 -0500
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'v3/base.html' %}
 {% load bio_tags %}
 {% load core_tags %}
 {% load comment_tags %}
@@ -8,23 +8,19 @@
 {% open_graph_meta_tags contest %}
 {% endblock %}
 {% block title %}Contests: {{ contest.title }}{% endblock %}
+{% block pre_custom_css %}
+{% css_tags 'jquery-ui markitup' %}
+{% endblock %}
 {% block custom_css %}
 <link rel="stylesheet" type="text/css" href="{% static "css/comments.css" %}" />
 {% endblock %}
-{% block custom_js %}
-{% if contest.is_active %}
-{% script_tags "markitup jquery-ui" %}
-<script type="text/javascript" src="{% static "js/comments.js" %}"></script>
-{% endif %}
-<script type="text/javascript">
-   var contest_id = {{ contest.id }};
-</script>
-<script type="text/javascript" src="{% static "js/contests/contests.js" %}"></script>
-{% endblock %}
 
 {% block content %}
 <h2><a href="{% url 'contests-index' %}">Contests</a></h2>
-<h3><a href="{% url 'contests-contest' slug=contest.slug %}">{{ contest.title }}</a></h3>
+<h3>{{ contest.title }}
+   <a href="{% url 'contests-contest' slug=contest.slug %}" rel="nofollow">
+      <i class="fi-link size-36" title="permalink"></i></a>
+</h3>
 <div>
    {{ contest.description|safe }}
    <br clear="all" />
@@ -33,63 +29,81 @@
 <h4>Contest Dates</h4>
 <p>
 {% if contest.is_active %}
-This contest began on {{ contest.creation_date|date:"F d, Y" }} and ends on
-{{ contest.end_date|date:"F d, Y" }}.
+   This contest began on {{ contest.creation_date|date:"F d, Y" }} and ends on
+   {{ contest.end_date|date:"F d, Y" }}.
 {% else %}
-This contest ran from {{ contest.creation_date|date:"F d, Y" }} to
-{{ contest.end_date|date:"F d, Y" }}.
+   This contest ran from {{ contest.creation_date|date:"F d, Y" }} to
+   {{ contest.end_date|date:"F d, Y" }}.
 {% endif %}
 </p>
 
 {% if contest.can_enter %}
-<h4>Contest Entry</h4>
-<p id="contest-entry">
-{% if user.is_authenticated %}
-   {% if user in contest.contestants.all %}
-      You are currently entered into this contest.<br />
-      <button id="contest-button">Withdraw from this contest</button>
+   <h4>Contest Entry</h4>
+   <div id="contest-entry">
+   {% if user.is_authenticated %}
+      {% if user in contest.contestants.all %}
+         <p>You are currently entered into this contest.</p>
+         <p>
+            <button type="button" class="alert button" id="contest-button">
+               Withdraw from this contest
+            </button>
+         </p>
+      {% else %}
+         <p>You are not participating in this contest.</p>
+         <p>
+            <button type="button" class="success button" id="contest-button">
+               Please enter me into this contest!
+            </button>
+         </p>
+      {% endif %}
    {% else %}
-      You are not participating in this contest.<br />
-      <button id="contest-button">Please enter me into this contest!</button>
+      Please <a href="{% url 'accounts-login' %}?next={{ contest.get_absolute_url }}">login</a>
+      to enter this contest.
    {% endif %}
-{% else %}
-   Please <a href="{% url 'accounts-login' %}?next={{ contest.get_absolute_url }}">login</a>
-   to enter this contest.
-{% endif %}
-</p>
+   </div>
 {% endif %}
 
 <h4>Contest Winners</h4>
 {% if contest.win_date %}
-<p>
-The winner{{ contest.num_winners|pluralize }} of this contest, selected on {{ contest.win_date|date:"l, F d, Y" }},
-{% if contest.num_winners == 1 %}is:{% else %}are:{% endif %}
-</p>
-<ul>
-   {% for winner in contest.winners.all %}
-   <li>{% profile_link winner.username %}</li>
-   {% endfor %}
-</ul>
-<p>Congratulations to the winner{{ contest.num_winners|pluralize }}!</p>
+   <p>
+   The winner{{ contest.num_winners|pluralize }} of this contest, selected on {{ contest.win_date|date:"l, F d, Y" }},
+   {% if contest.num_winners == 1 %}is:{% else %}are:{% endif %}
+   </p>
+   <ul>
+      {% for winner in contest.winners.all %}
+         <li>{% profile_link winner.username %}</li>
+      {% endfor %}
+   </ul>
+   <p>Congratulations to the winner{{ contest.num_winners|pluralize }}!</p>
 {% else %}
-<p>
-We will randomly choose {{ contest.num_winners }} winner{{ contest.num_winners|pluralize }}
-sometime on or after {{ contest.end_date|date:"l, F d, Y" }}. Please check back later.
-</p>
+   <p>
+   We will randomly choose {{ contest.num_winners }} winner{{ contest.num_winners|pluralize }}
+   sometime on or after {{ contest.end_date|date:"l, F d, Y" }}. Please check back later.
+   </p>
 {% endif %}
-<hr />
+
 {% social_sharing contest.title contest.get_absolute_url %}
 
 <hr />
 {% get_comment_count for contest as comment_count %}
 <p>This contest has <span id="comment-count">{{ comment_count }}</span> comment{{ comment_count|pluralize }}.</p>
-<hr />
 {% render_comment_list contest %}
 {% if contest.is_active %}
-<p>Leave a comment?</p>
-{% render_comment_form user contest %}
+   <p>Leave a comment?</p>
+   {% render_comment_form user contest %}
 {% else %}
-<p>Comments are closed for this contest. If you'd like to share your thoughts
-on this contest with the site staff, you can <a href="{% url 'contact-form' %}?subject={{ contest.title|urlencode }}">contact us directly</a>.</p>
+   <p>Comments are closed for this contest. If you'd like to share your thoughts
+   on this contest with the site staff, you can <a href="{% url 'contact-form' %}?subject={{ contest.title|urlencode }}">contact us directly</a>.</p>
 {% endif %}
 {% endblock %}
+
+{% block custom_js %}
+{% if contest.is_active %}
+   {% js_tags "markitup jquery-ui" %}
+   <script type="text/javascript" src="{% static "js/comments.js" %}"></script>
+   <script type="text/javascript">
+      var contest_id = {{ contest.id }};
+   </script>
+   <script type="text/javascript" src="{% static "js/contests/contests.js" %}"></script>
+{% endif %}
+{% endblock %}
--- a/sg101/templates/contests/contest_list.html	Wed Apr 27 20:04:05 2016 -0500
+++ b/sg101/templates/contests/contest_list.html	Mon May 02 20:03:18 2016 -0500
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'v3/base.html' %}
 {% load bio_tags %}
 {% load static from staticfiles %}
 {% block title %}Contests{% endblock %}
@@ -6,28 +6,16 @@
 <h2>Contests</h2>
 <p>From time to time, SurfGuitar101.com may hold drawings and contests. This page lists
 the current and past contests on the site.</p>
-{% if object_list %}
 <ul>
    {% for contest in contests %}
-   <li><a href="{{ contest.get_absolute_url }}">{{ contest.title }}</a> -
-   {{ contest.creation_date|date:"F d, Y" }} to {{ contest.end_date|date:"F d, Y" }}
-   {% if contest.is_active %}
-      <img src="{% static "icons/new.png" %}" alt="New" />
-   {% else %}
-      {% if contest.win_date %}
-         <ul>
-         {% for winner in contest.winners.all %}
-            <li><img src="{% static "icons/rosette.png" %}" alt="Winner" /> {% profile_link winner.username %}</li>
-         {% endfor %}
-         </ul>
-      {% else %}
-         <img src="{% static "icons/lock.png" %}" alt="Old" />
+      <li><a href="{{ contest.get_absolute_url }}">{{ contest.title }}</a> -
+      {{ contest.creation_date|date:"F d, Y" }} to {{ contest.end_date|date:"F d, Y" }}
+      {% if contest.is_active %}
+         <i class="fi-burst-new size-48"></i>
       {% endif %}
-   {% endif %}
-   </li>
+      </li>
+   {% empty %}
+      <p>No contests at this time.</p>
    {% endfor %}
 </ul>
-{% else %}
-<p>No contests at this time.</p>
-{% endif %}
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/core/v3/social_sharing_tag.html	Mon May 02 20:03:18 2016 -0500
@@ -0,0 +1,18 @@
+{% load static from staticfiles %}
+<ul class="menu">
+   <li>
+      <a href="https://twitter.com/intent/tweet?text={{ title|urlencode }}&amp;url={{ url|urlencode }}&amp;via=SurfGuitar101">
+         <img src="{% static "icons/button-twitter.png" %}" alt="Tweet"/>
+      </a>
+   </li>
+   <li>
+      <a href="https://plus.google.com/share?url={{ url|urlencode }}">
+         <img src="{% static "icons/button-googleplus.png" %}" alt="Share on Google Plus"/>
+      </a>
+   </li>
+   <li>
+      <a href="https://www.facebook.com/sharer/sharer.php?u={{ url|urlencode }}">
+         <img src="{% static "icons/button-facebook.png" %}" alt="Share on Facebook"/>
+      </a>
+   </li>
+</ul>