From: Radek Czajka Date: Mon, 23 Mar 2026 11:32:32 +0000 (+0100) Subject: Simpler payments and introduce seasonal banner. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/f59de09387c7ceb7d6ab2ccf6ea25cb4be8dacb5 Simpler payments and introduce seasonal banner. --- diff --git a/src/annoy/models.py b/src/annoy/models.py index 6af1cc045..638da5e86 100644 --- a/src/annoy/models.py +++ b/src/annoy/models.py @@ -120,20 +120,26 @@ class Banner(models.Model): return int(self.progress_percent) def update_progress(self): - # Total of new payments during the action. - # This definition will need to change for longer timespans. if not self.since or not self.until or not self.target: return Schedule = apps.get_model('club', 'Schedule') - self.progress = Schedule.objects.filter( - payed_at__gte=self.since, - payed_at__lte=self.until, - ).aggregate(c=models.Sum('amount'))['c'] + PayUOrder = apps.get_model('club', 'PayUOrder') + progress = PayUOrder.objects.filter( + completed_at__gte=self.since, + completed_at__lte=self.until, + ).aggregate(c=models.Sum('schedule__amount'))['c'] + + for schedule in Schedule.objects.filter( + method='paypal', + expires_at__gt=self.since + ): + progress += schedule.n_paypal_payments(self.since, self.until) * schedule.amount + self.progress = progress self.save(update_fields=['progress']) @classmethod def update_all_progress(cls): - for obj in cls.objects.exclude(target=None): + for obj in cls.objects.exclude(target=None).exclude(until__lt=now()): obj.update_progress() diff --git a/src/annoy/places.py b/src/annoy/places.py index 0de0483b9..2fbd34ca3 100644 --- a/src/annoy/places.py +++ b/src/annoy/places.py @@ -13,6 +13,7 @@ PLACE_DEFINITIONS = [ ('quiet', 'Spokojny'), ('loud', 'Ostry'), )), + ('seasonal', 'Sezonowa', False), ] PLACE_CHOICES = [p[:2] for p in PLACE_DEFINITIONS] diff --git a/src/annoy/templates/annoy/banner_seasonal.html b/src/annoy/templates/annoy/banner_seasonal.html new file mode 100644 index 000000000..a3a8a1aae --- /dev/null +++ b/src/annoy/templates/annoy/banner_seasonal.html @@ -0,0 +1,71 @@ +{% load l10n %} +{% load time_tags %} + +{% if banner %} +
+
+ {% if not banner.action_label %} + + {% endif %} + + {% if not banner.action_label %} + + {% endif %} + +
+
+
+
+ +
+
+
+
+
+   +
+ {% if banner.target %} + {{ banner.target }} zł + {% endif %} +
+
+ + +
+
+{% endif %} diff --git a/src/annoy/templatetags/annoy.py b/src/annoy/templatetags/annoy.py index cdf4dbc5d..602fb3cef 100644 --- a/src/annoy/templatetags/annoy.py +++ b/src/annoy/templatetags/annoy.py @@ -45,3 +45,11 @@ def annoy_banner_crisis(context): 'banner': banners.first(), 'closable': True, } + +@register.inclusion_tag('annoy/banner_seasonal.html', takes_context=True) +def annoy_banner_seasonal(context): + banners = Banner.choice('seasonal', request=context['request'], exemptions=False) + return { + 'banner': banners.first(), + 'closable': False, + } diff --git a/src/club/forms.py b/src/club/forms.py index e0963036a..ceda8d5b1 100644 --- a/src/club/forms.py +++ b/src/club/forms.py @@ -62,9 +62,7 @@ class DonationStep2Form(forms.ModelForm, NewsletterForm): model = models.Schedule fields = [ 'first_name', 'last_name', - 'email', 'phone', - 'postal', - 'postal_code', 'postal_town', 'postal_country', + 'email', ] widgets = { 'amount': forms.HiddenInput, @@ -74,16 +72,14 @@ class DonationStep2Form(forms.ModelForm, NewsletterForm): def __init__(self, **kwargs): super().__init__(**kwargs) - self.fields['first_name'].required = True - self.fields['last_name'].required = True - self.consent = [] for c in models.Consent.objects.filter(active=True).order_by('order'): key = f'consent{c.id}' - self.fields[key] = forms.BooleanField( - label=c.text, - required=c.required - ) + if not c.required: + self.fields[key] = forms.BooleanField( + label=c.text, + required=c.required + ) self.consent.append(( c, key, (lambda k: lambda: self[k])(key) )) diff --git a/src/club/models.py b/src/club/models.py index de2d3c62b..eb1439084 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -201,6 +201,20 @@ class Schedule(models.Model): def is_recurring(self): return self.monthly or self.yearly + def n_paypal_payments(self, since, until): + # TODO: pull BA payments. + t = self.payed_at + if t is None: return 0 + c = 0 + until = min(until, now()) + t += timedelta(days=1) + while t < until: + if t >= since: + c += 1 + m = datetime(t.year, t.month, 1) + t += ((m + timedelta(days=31)).replace(day=1)) - m + return c + def set_payed(self): since = self.expires_at n = now() diff --git a/src/club/templates/club/donation_step1.html b/src/club/templates/club/donation_step1.html index c9f5ed211..d01e69364 100644 --- a/src/club/templates/club/donation_step1.html +++ b/src/club/templates/club/donation_step1.html @@ -1,5 +1,13 @@ {% extends 'club/donation_step_base.html' %} +{% load chunks %} {% block donation-step-content %} {% include "club/donation_step1_form.html" %} {% endblock %} + +{% block donate-bottom %} + +
+ {% chunk "donate-bottom" %} +
+{% endblock %} diff --git a/src/club/templates/club/donation_step2.html b/src/club/templates/club/donation_step2.html index 5d602135d..0a4cba521 100644 --- a/src/club/templates/club/donation_step2.html +++ b/src/club/templates/club/donation_step2.html @@ -30,70 +30,46 @@ {% csrf_token %} {{ form.errors }}
-
-
- - {{ form.first_name }} - {{ form.first_name.errors }} -
-
- - {{ form.last_name }} - {{ form.last_name.errors }} -
-
-
-
+
+
{{ form.email }} {{ form.email.errors }}
-
- - {{ form.phone }} - {{ form.phone.errors }} -
-
-
-
- - {{ form.postal }} - {{ form.postal.errors }} -
- - {{ form.postal_code }} - {{ form.postal_code.errors }} -
-
- - {{ form.postal_town }} - {{ form.postal_town.errors }} + + {{ form.first_name }} + {{ form.first_name.errors }}
-
-
- - {{ form.postal_country }} - {{ form.postal_country.errors }} + + {{ form.last_name }} + {{ form.last_name.errors }}
+
{% for consent, key, field in form.consent %} - {{ field.errors }} + {% if not consent.required %} + {{ field.errors }} + {% endif %}
+ {% if consent.required %} + + {% else %} {{ field }} + {% endif %}
{% endfor %}
{{ form.agree_newsletter }}
diff --git a/src/club/templates/club/donation_step_base.html b/src/club/templates/club/donation_step_base.html index 388932488..0c99d3ca9 100644 --- a/src/club/templates/club/donation_step_base.html +++ b/src/club/templates/club/donation_step_base.html @@ -84,8 +84,9 @@