From: Radek Czajka Date: Tue, 2 Dec 2025 15:15:09 +0000 (+0100) Subject: Change donation form X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/55d94d75dff5d3a30dd0cce7554e68d23627376d?ds=sidebyside Change donation form --- diff --git a/src/club/forms.py b/src/club/forms.py index b75877d49..e0963036a 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -35,6 +35,8 @@ class DonationStep1Form(forms.ModelForm): self.referer = referer super().__init__(*args, **kwargs) club = models.Club.objects.first() + if self.instance.is_custom_amount(): + self.fields['custom_amount'].initial = int(self.instance.amount) if club is not None: self.fields['custom_amount'].widget.attrs['min'] = club.min_amount @@ -50,7 +52,8 @@ class DonationStep1Form(forms.ModelForm): return state def save(self, *args, **kwargs): - self.instance.source = self.referer + if self.referer is not None: + self.instance.source = self.referer return super().save(*args, **kwargs) diff --git a/src/club/models.py b/src/club/models.py index c40428def..77154954b 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -161,6 +161,15 @@ class Schedule(models.Model): club = Club.objects.first() return club.get_description_for_amount(self.amount, self.monthly) + def is_custom_amount(self): + club = Club.objects.first() + if not self.amount: + return False + if self.monthly: + return not club.monthlyamount_set.filter(amount=self.amount).exists() + else: + return not club.singleamount_set.filter(amount=self.amount).exists() + def initiate_payment(self, request): return self.get_payment_method().initiate(request, self) diff --git a/src/club/templates/club/donation_infobox.html b/src/club/templates/club/donation_infobox.html new file mode 100644 index 000000000..6008f0719 --- /dev/null +++ b/src/club/templates/club/donation_infobox.html @@ -0,0 +1,8 @@ +
+
+ Dziękujemy za wybranie comiesięcznej wpłaty. +
+
+ Czy na pewno nie comiesięczna? Zmień na comiesięczną wpłatę. +
+
diff --git a/src/club/templates/club/donation_step1_form.html b/src/club/templates/club/donation_step1_form.html index 033b0ea3f..655febe07 100644 --- a/src/club/templates/club/donation_step1_form.html +++ b/src/club/templates/club/donation_step1_form.html @@ -1,7 +1,7 @@ {% load static %} {% load i18n %} -
+ {% csrf_token %} {{ form.errors }} @@ -23,12 +23,11 @@ {% for amount in amounts.single %}
-

{{ amount.amount }} zł

{% if amount.description %}

{{ amount.description|safe }}

{% endif %} - +
{% endfor %} @@ -42,12 +41,11 @@
{% for amount in amounts.monthly %}
-

{{ amount.amount }} zł {% trans "/mies." context "kwota na miesiąc" %}

{% if amount.description %}

{{ amount.description|safe }}

{% endif %} - +
{% endfor %} @@ -58,7 +56,7 @@
- + {{ form.custom_amount }}
diff --git a/src/club/templates/club/donation_step2.html b/src/club/templates/club/donation_step2.html index 3864ad5a5..562bb40b9 100644 --- a/src/club/templates/club/donation_step2.html +++ b/src/club/templates/club/donation_step2.html @@ -8,26 +8,26 @@ {% block donation-step-content %} -
+

{{ schedule.amount|floatformat }} zł - {% if schedule.monthly %} - {% trans "/mies." context "kwota na miesiąc" %} - {% endif %} + {% trans "/mies." context "kwota na miesiąc" %}

+ {% if schedule.get_description %}

{{ schedule.get_description }}

+ {% endif %}
+ {% include "club/donation_infobox.html" %} + {% csrf_token %} {{ form.errors }} - {{ form.amount }} - {{ form.monthly }}
diff --git a/src/club/templates/club/donation_step3.html b/src/club/templates/club/donation_step3.html index baeee9f80..622252738 100644 --- a/src/club/templates/club/donation_step3.html +++ b/src/club/templates/club/donation_step3.html @@ -8,7 +8,7 @@ {% block donation-step-content %} -
+

@@ -20,9 +20,19 @@

+ {% include "club/donation_infobox.html" %} + + {% if schedule.monthly %} +

Comiesięczna darowizna będzie pobierana automatycznie

+

Możesz z niej zrezygnować w dowolnej chwili, korzystając z linku który dostaniesz mailem.

+ {% endif %} +
-
+ + +
+ {% for method in schedule.get_payment_methods %} {% invite_payment method schedule %} {% endfor %} diff --git a/src/club/templates/club/donation_step_base.html b/src/club/templates/club/donation_step_base.html index cede1b4ca..df5e805cb 100644 --- a/src/club/templates/club/donation_step_base.html +++ b/src/club/templates/club/donation_step_base.html @@ -43,7 +43,7 @@ {% endif %}
1 -

{% trans "Rodzaj wsparcia" %}

+

{% trans "Kwota wsparcia" %}

{% if view.step > 1 and view.step != 4 %} diff --git a/src/club/templates/club/payment/paypal_invite.html b/src/club/templates/club/payment/paypal_invite.html index 5ac0c4cd5..baaf09d81 100644 --- a/src/club/templates/club/payment/paypal_invite.html +++ b/src/club/templates/club/payment/paypal_invite.html @@ -1,5 +1,11 @@ {% load i18n static %} -

{% trans "Wolisz wpłacić przez PayPal?" %}

+

+ {% if schedule.monthly %} + {% trans "Wolisz ustawić comiesięczną darowiznę przez PayPal?" %} + {% else %} + {% trans "Wolisz wpłacić przez PayPal?" %} + {% endif %} +

PayPal diff --git a/src/club/templates/payu/rec_widget.html b/src/club/templates/payu/rec_widget.html index 13cf53b6b..be61a5366 100644 --- a/src/club/templates/payu/rec_widget.html +++ b/src/club/templates/payu/rec_widget.html @@ -1,5 +1,5 @@ {% load i18n %} -

{% trans "Podaj dane karty płatniczej" %}

+

{% trans "Podaj dane karty płatniczej do comiesięcznej darowizny" %}

{% csrf_token %} diff --git a/src/club/urls.py b/src/club/urls.py index 87bfa5a90..c7bab6aee 100644 --- a/src/club/urls.py +++ b/src/club/urls.py @@ -18,6 +18,7 @@ urlpatterns = [ path('plan//zestawienie//', banner_exempt(views.YearSummaryView.as_view()), name='club_year_summary'), path('plan//rodzaj/', banner_exempt(views.DonationStep1.as_view()), name='donation_step1'), path('plan//dane/', banner_exempt(views.DonationStep2.as_view()), name='donation_step2'), + path('plan//ustaw-miesiecznie/', views.set_monthly, name='donation_set_monthly'), path('przylacz//', views.claim, name='club_claim'), path('anuluj//', views.cancel, name='club_cancel'), diff --git a/src/club/views.py b/src/club/views.py index b2657e62f..a55f28481 100644 --- a/src/club/views.py +++ b/src/club/views.py @@ -4,7 +4,7 @@ from django.conf import settings from django.contrib.auth.decorators import login_required, permission_required from django.db.models import Sum -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.utils.decorators import method_decorator @@ -59,6 +59,17 @@ class DonationStep2(UpdateView): return c +def set_monthly(request, key): + schedule = get_object_or_404(models.Schedule, payed_at=None, key=key) + if request.POST: + schedule.monthly = True + schedule.save(update_fields=['monthly']) + return JsonResponse({ + "amount": schedule.amount, + "monthly": schedule.monthly, + }) + + class JoinView(CreateView): form_class = forms.DonationStep1Form template_name = 'club/donation_step1.html' diff --git a/src/wolnelektury/static/2022/styles/layout/_checkout.scss b/src/wolnelektury/static/2022/styles/layout/_checkout.scss index 593794b5b..636580a1a 100644 --- a/src/wolnelektury/static/2022/styles/layout/_checkout.scss +++ b/src/wolnelektury/static/2022/styles/layout/_checkout.scss @@ -349,26 +349,35 @@ } } button { - height: 56px; + margin: 0; + font-family: "Source Sans Pro",sans-serif; + font-weight: bold; + font-size: 44px; + line-height: 130%; + letter-spacing: -0.01em; + height: 90px; + display: flex; + align-items: center; + justify-content: center; + transition: all $ease-out 250ms; + background: #FFFFFF; border: 1px solid #92BD39; border-radius: 3px; width: 100%; outline: 0; cursor: pointer; - font-weight: 600; - font-size: 16px; - line-height: 24px; - display: flex; - align-items: center; - justify-content: center; text-align: center; color: #083F4D; - transition: background $ease-out 250ms; - @include rwd($break-flow) { - font-size: 20px; - line-height: 25px; + span { + font-weight: 600; + font-size: 25px; + line-height: 200%; + letter-spacing: -0.01em; + color: #92BD39; + margin-left: 10px; + transition: opacity $ease-out 250ms; } &:hover { @@ -397,6 +406,9 @@ &:hover { background: #83AD2B; } + span { + color: white; + } } } @@ -1046,3 +1058,14 @@ } } } + + +.if-monthly { display: none; } +.is-monthly { + .if-monthly { + display: block; + } + .if-not-monthly { + display: none; + } +} diff --git a/src/wolnelektury/static/js/main.js b/src/wolnelektury/static/js/main.js index 45a41970c..a27d97171 100644 --- a/src/wolnelektury/static/js/main.js +++ b/src/wolnelektury/static/js/main.js @@ -338,8 +338,25 @@ $('input', container).val($(this).val()); $('.is-active', container).removeClass('is-active'); $(this).closest('.l-checkout__payments__box').addClass('is-active'); - $('#kwota').val(''); - return false; + $('#id_custom_amount').val(''); + }); + + $('.donation-mod-monthly').on('click', function() { + $.ajax({ + method: 'POST', + data: { + csrfmiddlewaretoken: $("[name=csrfmiddlewaretoken]").val(), + }, + url: $(this).data('url'), + success: function(data) { + if ($(".q-reload-is-monthly").length) { + window.location.reload() + } else { + $(".q-is-monthly").toggleClass('is-monthly', data.monthly); + } + } + }); + return false; }); })();