diff --git a/bds/models.py b/bds/models.py
index 0ea46466..39540653 100644
--- a/bds/models.py
+++ b/bds/models.py
@@ -3,6 +3,7 @@ from os.path import splitext
from django.contrib.auth import get_user_model
from django.db import models
+from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from shared.utils import choices_length
@@ -93,6 +94,16 @@ class BDSProfile(models.Model):
),
)
+ @classmethod
+ def expired_members(cls):
+ now = timezone.now()
+ qs = cls.objects.filter(is_member=True)
+ if now.month > 1 and now.month < 7:
+ return qs.filter(cotisation_period="SE1")
+ elif now.month < 2 or now.month > 8:
+ return qs.none()
+ return qs
+
class Meta:
verbose_name = _("Profil BDS")
verbose_name_plural = _("Profils BDS")
diff --git a/bds/templates/bds/expired_members.html b/bds/templates/bds/expired_members.html
new file mode 100644
index 00000000..c5b53dbc
--- /dev/null
+++ b/bds/templates/bds/expired_members.html
@@ -0,0 +1,22 @@
+{% extends "bds/base.html" %}
+
+
+{% block content %}
+
+
Liste des adhésions expirées
+
+{% if object_list %}
+
+
+ {% for p in object_list %}
+ - {{ p.user.first_name }} {{ p.user.last_name }} ({{ p.user.username }}), {{ p.get_cotisation_period_display }}
+ {% endfor %}
+
+
+
+
+{% endif %}
+
+{% endblock %}
diff --git a/bds/templates/bds/home.html b/bds/templates/bds/home.html
index f689d2b5..aedbaa25 100644
--- a/bds/templates/bds/home.html
+++ b/bds/templates/bds/home.html
@@ -36,6 +36,8 @@
Télécharger la liste des membres (CSV)
+ Liste des adhésions expirées ({{ nb_expired }})
+
diff --git a/bds/templates/bds/user_update.html b/bds/templates/bds/user_update.html
index 5c0b76c5..1f54abe2 100644
--- a/bds/templates/bds/user_update.html
+++ b/bds/templates/bds/user_update.html
@@ -5,100 +5,100 @@
{% block content %}
{% for form in forms.values %}
- {% for error in form.non_field_errors %}
-
- {{ error }}
-
- {% endfor %}
+{% for error in form.non_field_errors %}
+
+ {{ error }}
+
+{% endfor %}
{% endfor %}
{% trans "Modification du profil " %}{{ view.user.username }}
-
+ {% for form in forms.values %}
+ {% include "bds/forms/form.html" with form=form errors=False %}
+ {% endfor %}
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
- Confirmer la suppression
-
-
-
- Voulez-vous réellement supprimer ce compte ? Attention, cette opération est irréversible !
-
-
-
+
+
+
+ Confirmer la suppression
+
+
+
+ Voulez-vous réellement supprimer ce compte ? Attention, cette opération est irréversible !
+
+
+
{% endblock %}
diff --git a/bds/urls.py b/bds/urls.py
index 93c60b0d..95065773 100644
--- a/bds/urls.py
+++ b/bds/urls.py
@@ -15,4 +15,10 @@ urlpatterns = [
),
path("user/delete/
", views.UserDeleteView.as_view(), name="user.delete"),
path("members", views.export_members, name="export.members"),
+ path(
+ "members/expired",
+ views.ResetMembershipListView.as_view(),
+ name="members.expired",
+ ),
+ path("members/reset", views.ResetMembershipView.as_view(), name="members.reset"),
]
diff --git a/bds/views.py b/bds/views.py
index 4b279836..5fc4f316 100644
--- a/bds/views.py
+++ b/bds/views.py
@@ -8,7 +8,7 @@ from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
-from django.views.generic import DeleteView, TemplateView
+from django.views.generic import DeleteView, ListView, RedirectView, TemplateView
from bds.autocomplete import bds_search
from bds.forms import ProfileForm, UserForm, UserFromClipperForm, UserFromScratchForm
@@ -30,6 +30,7 @@ class Home(StaffRequiredMixin, TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["member_count"] = BDSProfile.objects.filter(is_member=True).count()
+ context["nb_expired"] = BDSProfile.expired_members().count()
return context
@@ -143,6 +144,28 @@ class UserDeleteView(StaffRequiredMixin, DeleteView):
return super().delete(request, *args, **kwargs)
+class ResetMembershipListView(StaffRequiredMixin, ListView):
+ model = BDSProfile
+ template_name = "bds/expired_members.html"
+
+ def get_queryset(self):
+ return BDSProfile.expired_members()
+
+
+class ResetMembershipView(StaffRequiredMixin, RedirectView):
+ url = reverse_lazy("bds:members.expired")
+
+ def get(self, request, *args, **kwargs):
+ qs = BDSProfile.expired_members()
+ nb = qs.count()
+
+ qs.update(cotisation_period="NO", is_member=False, mails_bds=False)
+
+ messages.success(request, f"{nb} adhésions réinitialisées")
+
+ return super().get(request, *args, **kwargs)
+
+
@permission_required("bds.is_team")
def export_members(request):
response = HttpResponse(content_type="text/csv")