From 355e42e2b2244470ac6a5b9ad056e4a3f38f838c Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 17 Apr 2019 15:44:26 +0200 Subject: [PATCH] Changes in club payments. --- src/club/migrations/0008_membership_name.py | 20 ++++++ src/club/models.py | 4 +- src/club/templates/club/schedule.html | 69 ++++++++++++++++----- src/club/urls.py | 1 + src/club/views.py | 17 +++-- src/wolnelektury/urls.py | 4 ++ 6 files changed, 94 insertions(+), 21 deletions(-) create mode 100644 src/club/migrations/0008_membership_name.py diff --git a/src/club/migrations/0008_membership_name.py b/src/club/migrations/0008_membership_name.py new file mode 100644 index 000000000..ce30b25a1 --- /dev/null +++ b/src/club/migrations/0008_membership_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-04-17 13:39 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('club', '0007_auto_20190416_1625'), + ] + + operations = [ + migrations.AddField( + model_name='membership', + name='name', + field=models.CharField(blank=True, max_length=255), + ), + ] diff --git a/src/club/models.py b/src/club/models.py index f5cbf6e7f..1128070e7 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -102,6 +102,7 @@ class Membership(models.Model): """ Represents a user being recognized as a member of the club. """ user = models.OneToOneField(settings.AUTH_USER_MODEL, verbose_name=_('user'), on_delete=models.CASCADE) created_at = models.DateTimeField(_('created at'), auto_now_add=True) + name = models.CharField(max_length=255, blank=True) honorary = models.BooleanField(default=False) class Meta: @@ -183,7 +184,8 @@ class PayUOrder(payu_models.Order): def status_updated(self): if self.status == 'COMPLETED': - new_exp = self.schedule.plan.get_next_installment(now()) + since = self.schedule.expires_at or now() + new_exp = self.schedule.plan.get_next_installment(since) if self.schedule.expires_at is None or self.schedule.expires_at < new_exp: self.schedule.expires_at = new_exp self.schedule.save() diff --git a/src/club/templates/club/schedule.html b/src/club/templates/club/schedule.html index 6baa9a4fc..b1e190780 100644 --- a/src/club/templates/club/schedule.html +++ b/src/club/templates/club/schedule.html @@ -9,30 +9,69 @@

Plan płatności

-
{{ schedule.email }}
-
{{ schedule.amount }}
-
{{ schedule.plan.get_interval_display }}
- -
{{ schedule.is_active|yesno:"Aktywne,Nieaktywne" }}
+
E-mail: {{ schedule.email }}
+
Składka: {{ schedule.amount }} zł {{ schedule.plan.get_interval_display }}
+
Wybrana metoda płatności: {{ schedule.get_payment_method.name }}
+ +{% if schedule.is_active %} + {% if schedule.plan.is_perpetual %} + Opłacona na zawsze. + {% endif %} + Aktualnie opłacona do: {{ schedule.expires_at }} + + {% if schedule.get_payment_method.is_recurring %} +
+ {% csrf_token %} + +
+ {% else %} +
+ {% csrf_token %} + +
+ {% endif %} -
Start: {{ schedule.started_at }}
-
Opłacone do: {{ schedule.expires_at|default:"brak" }} {% if schedule.is_cancelled %}(anulowana){% endif %}
-{% if schedule.expires_at and not schedule.is_cancelled %} -
- {% csrf_token %} - -
+{% else %} + {% if schedule.is_expired %} + Członkostwo wygasło. +
+ {% csrf_token %} + +
+ + + {% else %} + Składka nie została jeszcze opłacona. + {% if schedule.payuorder_set.exists %} + Czekamy na potwierdzenie płatności. + {% else %} + +
+ {% csrf_token %} + +
+ + {% endif %} + {% endif %} {% endif %} -{% if schedule.is_expired %} - Płatność wygasła. Wykonaj nową płatność. -{% endif %} +
+ + {% if schedule.membership %}

Członek/członkini Towarzystwa nr {{ schedule.membership.id }} ({{ schedule.membership.user }}).

+ +
+ {% csrf_token %} + Imię i nazwisko na legitymację:
+
+ +
+ {% else %}

Płatność nie przypisana do członkostwa.
diff --git a/src/club/urls.py b/src/club/urls.py index f48966173..506f42b62 100644 --- a/src/club/urls.py +++ b/src/club/urls.py @@ -16,4 +16,5 @@ urlpatterns = [ url(r'notify/(?P\d+)/', views.PayUNotifyView.as_view(), name='club_payu_notify'), + url(r'czlonek/', views.MembershipView.as_view(), name='club_membership'), ] diff --git a/src/club/views.py b/src/club/views.py index af59b1e9a..9816b4b99 100644 --- a/src/club/views.py +++ b/src/club/views.py @@ -1,7 +1,7 @@ from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, render -from django.views.generic import FormView, CreateView, TemplateView, DetailView +from django.views.generic import FormView, CreateView, TemplateView, DetailView, UpdateView from django.views import View from .payu import POSS from .payu import views as payu_views @@ -67,10 +67,7 @@ class ScheduleView(DetailView): def post(self, request, key): schedule = self.get_object() - if not schedule.is_active(): - return HttpResponseRedirect(schedule.initiate_payment(request)) - else: - return HttpResponseRedirect(schedule.get_absolute_url()) + return HttpResponseRedirect(schedule.initiate_payment(request)) @login_required @@ -123,3 +120,13 @@ class PayURecPayment(payu_views.RecPayment): class PayUNotifyView(payu_views.NotifyView): order_model = models.PayUOrder + +class MembershipView(UpdateView): + fields = ['name'] + + def get_success_url(self): + # TODO: get only current schedule if multiple. + return self.object.schedule_set.first().get_absolute_url() + + def get_object(self): + return self.request.user.membership diff --git a/src/wolnelektury/urls.py b/src/wolnelektury/urls.py index 72a524915..8b02fda40 100644 --- a/src/wolnelektury/urls.py +++ b/src/wolnelektury/urls.py @@ -50,6 +50,10 @@ urlpatterns += [ url(r'^newsletter/', include('newsletter.urls')), url(r'^formularz/', include('contact.urls')), url(r'^isbn/', include('isbn.urls')), + + url(r'^paypal/app-form/$', RedirectView.as_view( + url='/towarzystwo/dolacz/?app=1', permanent=True)), + url(r'^paypal/', include('paypal.urls')), url(r'^powiadomienie/', include('push.urls')), url(r'^towarzystwo/', include('club.urls')), -- 2.20.1