# HG changeset patch # User Brian Neal # Date 1462237398 18000 # Node ID 16e190fa6ef86c16d536058eaf10a9efbc666a70 # Parent 5fa22ed8bfb261eea97c5c0a74fcf24b09bd505e Port contests app to V3 design. diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 contests/static/js/contests/contests.js --- 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); diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 contests/urls.py --- 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[\w-]+)/$', - DetailView.as_view( - context_object_name='contest', - queryset=Contest.public_objects.all().prefetch_related('winners')), + contests.views.ContestDetailView.as_view(), name='contests-contest'), ] diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 contests/views.py --- 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): """ diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 core/templatetags/core_tags.py --- 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): diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 sg101/templates/comments/comment_form.html --- 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 @@
{% csrf_token %} {{ form.as_p }} {% comment_dialogs %} - +
{% else %}

diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 sg101/templates/contests/contest_detail.html --- 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 %} {% endblock %} -{% block custom_js %} -{% if contest.is_active %} -{% script_tags "markitup jquery-ui" %} - -{% endif %} - - -{% endblock %} {% block content %}

Contests

-

{{ contest.title }}

+

{{ contest.title }} + + +

{{ contest.description|safe }}
@@ -33,63 +29,81 @@

Contest Dates

{% 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 %}

{% if contest.can_enter %} -

Contest Entry

-

-{% if user.is_authenticated %} - {% if user in contest.contestants.all %} - You are currently entered into this contest.
- +

Contest Entry

+
+ {% if user.is_authenticated %} + {% if user in contest.contestants.all %} +

You are currently entered into this contest.

+

+ +

+ {% else %} +

You are not participating in this contest.

+

+ +

+ {% endif %} {% else %} - You are not participating in this contest.
- + Please login + to enter this contest. {% endif %} -{% else %} - Please login - to enter this contest. -{% endif %} -

+
{% endif %}

Contest Winners

{% if contest.win_date %} -

-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 %} -

-
    - {% for winner in contest.winners.all %} -
  • {% profile_link winner.username %}
  • - {% endfor %} -
-

Congratulations to the winner{{ contest.num_winners|pluralize }}!

+

+ 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 %} +

+
    + {% for winner in contest.winners.all %} +
  • {% profile_link winner.username %}
  • + {% endfor %} +
+

Congratulations to the winner{{ contest.num_winners|pluralize }}!

{% else %} -

-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. -

+

+ 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. +

{% endif %} -
+ {% social_sharing contest.title contest.get_absolute_url %}
{% get_comment_count for contest as comment_count %}

This contest has {{ comment_count }} comment{{ comment_count|pluralize }}.

-
{% render_comment_list contest %} {% if contest.is_active %} -

Leave a comment?

-{% render_comment_form user contest %} +

Leave a comment?

+ {% render_comment_form user contest %} {% else %} -

Comments are closed for this contest. If you'd like to share your thoughts -on this contest with the site staff, you can contact us directly.

+

Comments are closed for this contest. If you'd like to share your thoughts + on this contest with the site staff, you can contact us directly.

{% endif %} {% endblock %} + +{% block custom_js %} +{% if contest.is_active %} + {% js_tags "markitup jquery-ui" %} + + + +{% endif %} +{% endblock %} diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 sg101/templates/contests/contest_list.html --- 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 @@

Contests

From time to time, SurfGuitar101.com may hold drawings and contests. This page lists the current and past contests on the site.

-{% if object_list %}
    {% for contest in contests %} -
  • {{ contest.title }} - - {{ contest.creation_date|date:"F d, Y" }} to {{ contest.end_date|date:"F d, Y" }} - {% if contest.is_active %} - New - {% else %} - {% if contest.win_date %} -
      - {% for winner in contest.winners.all %} -
    • Winner {% profile_link winner.username %}
    • - {% endfor %} -
    - {% else %} - Old +
  • {{ contest.title }} - + {{ contest.creation_date|date:"F d, Y" }} to {{ contest.end_date|date:"F d, Y" }} + {% if contest.is_active %} + {% endif %} - {% endif %} -
  • + + {% empty %} +

    No contests at this time.

    {% endfor %}
-{% else %} -

No contests at this time.

-{% endif %} {% endblock %} diff -r 5fa22ed8bfb2 -r 16e190fa6ef8 sg101/templates/core/v3/social_sharing_tag.html --- /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 %} +