From 1a6ad5b9b48a5efa90410fd324c256f59f57e08f Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 18 Dec 2019 14:11:43 +0000 Subject: [PATCH] Club-related fixes. --- src/annoy/static/annoy/banner.js | 10 +++++----- .../admin/club/schedule/change_list.html | 7 +++++++ src/club/templates/club/membership_form.html | 7 +++++++ src/club/templatetags/club.py | 13 ++++++++++++ src/club/views.py | 20 ++++++++++++------- 5 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 src/club/templates/admin/club/schedule/change_list.html diff --git a/src/annoy/static/annoy/banner.js b/src/annoy/static/annoy/banner.js index ad5dd66f8..44a1d0223 100644 --- a/src/annoy/static/annoy/banner.js +++ b/src/annoy/static/annoy/banner.js @@ -12,32 +12,32 @@ $target.slideDown('fast'); $on.hide(); if (Modernizr.localstorage) localStorage.removeItem(tag); - _paq.push(['trackEvent', 'banner', 'unhide', $on.attr('data-target')]); + _paq.push(['trackEvent', 'banner', 'banner-unhide', $target.attr('id')]); }); $off.click(function() { $target.slideUp('fast'); $on.show(); if (Modernizr.localstorage) localStorage[tag] = true; - _paq.push(['trackEvent', 'banner', 'hide', $on.attr('data-target')]); + _paq.push(['trackEvent', 'banner', 'banner-hide', $target.attr('id')]); }); if (Modernizr.localstorage) { if (!localStorage[tag]) { $on.hide(); $target.show(); - _paq.push(['trackEvent', 'banner', 'show', $on.attr('data-target')]); + _paq.push(['trackEvent', 'banner', 'banner-show', $target.attr('id')]); } } }); $(document).on('click', ".annoy-banner a", function() { banner = $(this).closest('.annoy-banner'); - _paq.push(['trackEvent', 'banner', 'click', banner.attr('id')]); + _paq.push(['trackEvent', 'banner', 'banner-click', banner.attr('id')]); }); $(document).on('click', ".dynamic-insert a", function() { banner = $(this).closest('.dynamic-insert'); - _paq.push(['trackEvent', 'dynamic-insert', 'click', banner.attr('data-paragraphs'), banner.attr('data-textid')]); + _paq.push(['trackEvent', 'dynamic-insert', 'dynamic-insert-click', 'insert-' + banner.attr('data-paragraphs') + '-pars-text-' + banner.attr('data-textid')]); }); }); diff --git a/src/club/templates/admin/club/schedule/change_list.html b/src/club/templates/admin/club/schedule/change_list.html new file mode 100644 index 000000000..ff08cfbde --- /dev/null +++ b/src/club/templates/admin/club/schedule/change_list.html @@ -0,0 +1,7 @@ +{% extends "admin/change_list.html" %} +{% load club %} + +{% block content %} +

Aktywne miesięczne wpłaty: {% club_active_monthly_count %} sztuk, {% club_active_monthly_sum %} zł.

+ {{ block.super }} +{% endblock content %} diff --git a/src/club/templates/club/membership_form.html b/src/club/templates/club/membership_form.html index 2e0c2c50e..8ad0387e6 100644 --- a/src/club/templates/club/membership_form.html +++ b/src/club/templates/club/membership_form.html @@ -1,6 +1,7 @@ {% extends request.session.from_app|yesno:"base/app.html,base/base.html" %} {% load chunks %} {% load thumbnail %} +{% load club %} {% block titleextra %}Uwalniaj książki razem z nami!{% endblock %} {% block metadescription %}„Wolne Lektury należy wspierać, bo są” - Filip Springer{% endblock %} @@ -123,6 +124,12 @@

{% if membership %}Dziękujemy za Twoje dotychczasowe zaangażowanie! Wesprzyj nas ponownie!{% else %}Dziękujemy, że chcesz razem z nami uwalniać książki!{% endif %}

+ {% with schedule=request.user|active_schedule %} + {% if schedule %} +

Zobacz swoje dotychczasowe wsparcie.

+ {% endif %} + {% endwith %} + {% chunk 'club_form_top' %}
diff --git a/src/club/templatetags/club.py b/src/club/templatetags/club.py index 65dcd6847..7e8bc038c 100644 --- a/src/club/templatetags/club.py +++ b/src/club/templatetags/club.py @@ -1,8 +1,11 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from django.db.models import Sum from django import template +from django.utils.timezone import now from ..helpers import get_active_schedule +from ..models import Schedule register = template.Library() @@ -11,3 +14,13 @@ register = template.Library() @register.filter def active_schedule(user): return get_active_schedule(user) + + +@register.simple_tag +def club_active_monthly_count(): + return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).count() + +@register.simple_tag +def club_active_monthly_sum(): + return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).aggregate(s=Sum('amount'))['s'] + diff --git a/src/club/views.py b/src/club/views.py index 32daffde1..920180a49 100644 --- a/src/club/views.py +++ b/src/club/views.py @@ -42,11 +42,11 @@ class JoinView(CreateView): request.session['from_app'] = True elif request.session and 'from_app' in request.session: del request.session['from_app'] - schedule = get_active_schedule(request.user) - if schedule is not None: - return HttpResponseRedirect(schedule.get_absolute_url()) - else: - return super(JoinView, self).get(request) + #schedule = get_active_schedule(request.user) + #if schedule is not None: + # return HttpResponseRedirect(schedule.get_absolute_url()) + #else: + return super(JoinView, self).get(request) def get_context_data(self, **kwargs): c = super(JoinView, self).get_context_data(**kwargs) @@ -119,8 +119,14 @@ class DummyPaymentView(TemplateView): return HttpResponseRedirect(schedule.get_absolute_url()) -class PayUPayment(payu_views.Payment): - pass +class PayUPayment(DetailView): + model = models.Schedule + slug_field = slug_url_kwarg = 'key' + + def get(self, request, key): + schedule = self.get_object() + return HttpResponseRedirect(schedule.initiate_payment(request)) + class PayURecPayment(payu_views.RecPayment): -- 2.20.1