From 7fdb1a914f332dd2609445d8ce1e98173ecea04a Mon Sep 17 00:00:00 2001
From: imperosol
Date: Tue, 22 Sep 2026 11:37:38 +0200
Subject: [PATCH] remove date selection from subscription stats view
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Ca n'a jamais marché depuis 2017
---
subscription/forms.py | 13 +---
.../templates/subscription/stats.jinja | 75 ++++++++-----------
subscription/views.py | 25 +------
3 files changed, 36 insertions(+), 77 deletions(-)
diff --git a/subscription/forms.py b/subscription/forms.py
index 7f8cd7d7..29a70b8d 100644
--- a/subscription/forms.py
+++ b/subscription/forms.py
@@ -8,22 +8,11 @@ from django.utils.translation import gettext_lazy as _
from core.models import User
from core.utils import get_last_promo
-from core.views.forms import SelectDate, SelectDateTime
+from core.views.forms import SelectDate
from core.views.widgets.ajax_select import AutoCompleteSelectUser
from subscription.models import Subscription
-class SelectionDateForm(forms.Form):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields["start_date"] = forms.DateTimeField(
- label=_("Start date"), widget=SelectDateTime, required=True
- )
- self.fields["end_date"] = forms.DateTimeField(
- label=_("End date"), widget=SelectDateTime, required=True
- )
-
-
class SubscriptionForm(forms.ModelForm):
allowed_payment_methods = ["CARD", "CASH", "AE_ACCOUNT"]
diff --git a/subscription/templates/subscription/stats.jinja b/subscription/templates/subscription/stats.jinja
index eb124032..c695d996 100644
--- a/subscription/templates/subscription/stats.jinja
+++ b/subscription/templates/subscription/stats.jinja
@@ -11,51 +11,38 @@
{% block content %}
-
-
-
-
-
- {% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}
- {% trans %}Subscriptions by type{% endtrans %}
- {% for location in locations %}
- {{ location[1] }} : {{ subscriptions_total.filter(location=location[0]).count() }}
+ {% trans %}Total subscriptions{% endtrans %} : {{ subscriptions_total.count() }}
+ {% trans %}Subscriptions by type{% endtrans %}
+ {% for location in locations %}
+ {{ location[1] }} : {{ subscriptions_total.filter(location=location[0]).count() }}
+ {% endfor %}
+
+
+
+
+ | {% trans %}Subscription type{% endtrans %} |
+ {% for location in locations %}
+ {{ location[1] }} |
+ {% endfor %}
+ {% trans %}Total{% endtrans %} |
+
+ {% for type in subscriptions_types %}
+
+ | {{ subscriptions_types[type]['name'] }} |
+ {% set subscriptions_total_type = subscriptions_total.filter(subscription_type=type) %}
+ {% for location in locations %}
+
+ {% set subscriptions_total_type_location = subscriptions_total_type.filter(location=location[0]) %}
+ {% trans %}Total{% endtrans %} : {{ subscriptions_total_type_location.count()}}
+ {% for p_type in payment_types %}
+ {{ p_type[1] }} : {{ subscriptions_total_type_location.filter(payment_method=p_type[0]).count()}}
+ {% endfor %}
+ |
+ {% endfor %}
+ {{subscriptions_total_type.count()}} |
+
{% endfor %}
-
-
-
-
-
-
- | {% trans %}Subscription type{% endtrans %} |
- {% for location in locations %}
- {{ location[1] }} |
- {% endfor %}
- {% trans %}Total{% endtrans %} |
- {% for type in subscriptions_types %}
-
- | {{ subscriptions_types[type]['name'] }} |
- {% set subscriptions_total_type = subscriptions_total.filter(subscription_type=type) %}
- {% for location in locations %}
-
- {% set subscriptions_total_type_location = subscriptions_total_type.filter(location=location[0]) %}
- {% trans %}Total{% endtrans %} : {{ subscriptions_total_type_location.count()}}
- {% for p_type in payment_types %}
- {{ p_type[1] }} : {{ subscriptions_total_type_location.filter(payment_method=p_type[0]).count()}}
- {% endfor %}
- |
- {% endfor %}
- {{subscriptions_total_type.count()}}
- |
- {% endfor %}
-
-
+
{% endblock %}
diff --git a/subscription/views.py b/subscription/views.py
index 505f9614..8c790647 100644
--- a/subscription/views.py
+++ b/subscription/views.py
@@ -17,16 +17,14 @@ from django.conf import settings
from django.contrib.auth.forms import PasswordResetForm
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import PermissionDenied
-from django.urls import reverse, reverse_lazy
+from django.urls import reverse
from django.utils.timezone import localdate
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, TemplateView
-from django.views.generic.edit import FormView
from core.views import FragmentMixin, UseFragmentsMixin
from core.views.group import PermissionGroupsUpdateView
from subscription.forms import (
- SelectionDateForm,
SubscriptionExistingUserForm,
SubscriptionNewUserForm,
)
@@ -93,34 +91,19 @@ class SubscriptionPermissionView(PermissionGroupsUpdateView):
extra_context = {"object_name": _("the groups that can create subscriptions")}
-class SubscriptionsStatsView(FormView):
+class SubscriptionsStatsView(TemplateView):
template_name = "subscription/stats.jinja"
- form_class = SelectionDateForm
- success_url = reverse_lazy("subscriptions:stats")
def dispatch(self, request, *arg, **kwargs):
- self.start_date = localdate()
- self.end_date = self.start_date
if request.user.is_root or request.user.is_board_member:
return super().dispatch(request, *arg, **kwargs)
raise PermissionDenied
- def post(self, request, *args, **kwargs):
- self.form = self.get_form()
- self.start_date = self.form["start_date"]
- self.end_date = self.form["end_date"]
- return super().post(request, *args, **kwargs)
-
- def get_initial(self):
- return {
- "start_date": self.start_date.strftime("%Y-%m-%d %H:%M:%S"),
- "end_date": self.end_date.strftime("%Y-%m-%d %H:%M:%S"),
- }
-
def get_context_data(self, **kwargs):
kwargs = super().get_context_data(**kwargs)
+ today = localdate()
kwargs["subscriptions_total"] = Subscription.objects.filter(
- subscription_end__gte=self.end_date, subscription_start__lte=self.start_date
+ subscription_end__gte=today, subscription_start__lte=today
)
kwargs["subscriptions_types"] = settings.SITH_SUBSCRIPTIONS
kwargs["payment_types"] = settings.SITH_SUBSCRIPTION_PAYMENT_METHOD