Protect all from update if the WEI is ended (or not started), remove useless fixture

This commit is contained in:
Yohann D'ANELLO 2020-04-20 04:53:26 +02:00
parent 16af9ac0ea
commit 47b9b53591
5 changed files with 124 additions and 83 deletions

View File

@ -1,76 +0,0 @@
[
{
"model": "member.club",
"pk": 3,
"fields": {
"name": "A[WEI] from Home",
"email": "gc.wei@example.com",
"parent_club": 2,
"require_memberships": true,
"membership_fee_paid": 16500,
"membership_fee_unpaid": 9500,
"membership_duration": 30,
"membership_start": "2019-09-01",
"membership_end": "2019-09-16"
}
},
{
"model": "wei.weiclub",
"pk": 1,
"fields": {
"club_ptr_id": 3,
"year": 2019,
"date_start": "2019-09-14",
"date_end": "2019-09-16"
}
},
{
"model": "note.note",
"pk": 7,
"fields": {
"polymorphic_ctype": [
"note",
"noteclub"
],
"balance": 0,
"last_negative": null,
"is_active": true,
"display_image": "pic/default.png",
"created_at": "2020-02-20T20:16:14.753Z"
}
},
{
"model": "note.noteclub",
"pk": 7,
"fields": {
"club": 3
}
},
{
"model": "note.alias",
"pk": 7,
"fields": {
"name": "A[WEI] from Home",
"normalized_name": "aweifromhome",
"note": 7
}
},
{
"model": "note.alias",
"pk": 8,
"fields": {
"name": "WEI 2019",
"normalized_name": "wei2019",
"note": 7
}
},
{
"model": "note.alias",
"pk": 9,
"fields": {
"name": "WEI",
"normalized_name": "wei",
"note": 7
}
}
]

View File

@ -29,6 +29,9 @@ class WEIClub(Club):
@property
def is_current_wei(self):
"""
We consider that this is the current WEI iff there is no future WEI planned.
"""
return not WEIClub.objects.filter(date_start__gt=self.date_start).exists()
def update_membership_dates(self):

View File

@ -6,7 +6,7 @@ from django.urls import path
from .views import CurrentWEIDetailView, WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\
BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView,\
WEIRegister1AView, WEIRegister2AView, WEIUpdateRegistrationView, WEIValidateRegistrationView,\
WEISurveyView, WEISurveyEndView
WEISurveyView, WEISurveyEndView, WEIClosedView
app_name = 'wei'
@ -30,4 +30,5 @@ urlpatterns = [
path('validate/<int:pk>/', WEIValidateRegistrationView.as_view(), name="validate_registration"),
path('survey/<int:pk>/', WEISurveyView.as_view(), name="wei_survey"),
path('survey/<int:pk>/end/', WEISurveyEndView.as_view(), name="wei_survey_end"),
path('detail/<int:pk>/closed/', WEIClosedView.as_view(), name="wei_closed"),
]

View File

@ -25,7 +25,7 @@ from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIM
class CurrentWEIDetailView(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs):
wei = WEIClub.objects.order_by('date_start').last()
wei = WEIClub.objects.filter(membership_start__lte=date.today()).order_by('date_start').last()
return reverse_lazy('wei:wei_detail', args=(wei.pk,))
@ -68,8 +68,6 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
context = super().get_context_data(**kwargs)
club = context["club"]
if PermissionBackend.check_perm(self.request.user, "member.change_club_membership_start", club):
club.update_membership_dates()
club_transactions = Transaction.objects.all().filter(Q(source=club.note) | Q(destination=club.note)) \
.filter(PermissionBackend.filter_queryset(self.request.user, Transaction, "view")).order_by('-id')
@ -106,7 +104,7 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
bus_table = BusTable(data=buses, prefix="bus-")
context['buses'] = bus_table
# Check if the user has the right to create a membership, to display the button.
# Check if the user has the right to create a membership with a random user, to display the button.
empty_membership = Membership(
club=club,
user=User.objects.first(),
@ -136,6 +134,15 @@ class WEIUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
context_object_name = "club"
form_class = WEIForm
def dispatch(self, request, *args, **kwargs):
wei = self.get_object()
today = date.today()
# We can't update a past WEI
# But we can update it while it is not officially opened
if today > wei.membership_end:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_success_url(self):
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk})
@ -147,6 +154,14 @@ class BusCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
model = Bus
form_class = BusForm
def dispatch(self, request, *args, **kwargs):
wei = WEIClub.objects.get(pk=self.kwargs["pk"])
today = date.today()
# We can't add a bus once the WEI is started
if today >= wei.date_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["club"] = WEIClub.objects.get(pk=self.kwargs["pk"])
@ -169,6 +184,14 @@ class BusUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
model = Bus
form_class = BusForm
def dispatch(self, request, *args, **kwargs):
wei = self.get_object().wei
today = date.today()
# We can't update a bus once the WEI is started
if today >= wei.date_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["club"] = self.object.wei
@ -216,6 +239,14 @@ class BusTeamCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
model = BusTeam
form_class = BusTeamForm
def dispatch(self, request, *args, **kwargs):
wei = WEIClub.objects.get(buses__pk=self.kwargs["pk"])
today = date.today()
# We can't add a team once the WEI is started
if today >= wei.date_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
bus = Bus.objects.get(pk=self.kwargs["pk"])
@ -239,6 +270,14 @@ class BusTeamUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
model = BusTeam
form_class = BusTeamForm
def dispatch(self, request, *args, **kwargs):
wei = self.get_object().bus.wei
today = date.today()
# We can't update a bus once the WEI is started
if today >= wei.date_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["club"] = self.object.bus.wei
@ -282,6 +321,14 @@ class WEIRegister1AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
model = WEIRegistration
form_class = WEIRegistrationForm
def dispatch(self, request, *args, **kwargs):
wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"])
today = date.today()
# We can't register someone once the WEI is started and before the membership start date
if today >= wei.date_start or today < wei.membership_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = _("Register 1A")
@ -315,6 +362,14 @@ class WEIRegister2AView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
model = WEIRegistration
form_class = WEIRegistrationForm
def dispatch(self, request, *args, **kwargs):
wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"])
today = date.today()
# We can't register someone once the WEI is started and before the membership start date
if today >= wei.date_start or today < wei.membership_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = _("Register 2A+")
@ -355,6 +410,14 @@ class WEIUpdateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Update
model = WEIRegistration
form_class = WEIRegistrationForm
def dispatch(self, request, *args, **kwargs):
wei = self.get_object().wei
today = date.today()
# We can't update a registration once the WEI is started and before the membership start date
if today >= wei.date_start or today < wei.membership_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["club"] = self.object.wei
@ -378,6 +441,14 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, LoginRequiredMixin, Crea
model = WEIMembership
form_class = WEIMembershipForm
def dispatch(self, request, *args, **kwargs):
wei = WEIRegistration.objects.get(pk=self.kwargs["pk"]).wei
today = date.today()
# We can't validate anyone once the WEI is started and before the membership start date
if today >= wei.date_start or today < wei.membership_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -468,8 +539,15 @@ class WEISurveyView(BaseFormView, DetailView):
template_name = "wei/survey.html"
survey = None
def get(self, request, *args, **kwargs):
def dispatch(self, request, *args, **kwargs):
obj = self.get_object()
wei = obj.wei
today = date.today()
# We can't access to the WEI survey once the WEI is started and before the membership start date
if today >= wei.date_start or today < wei.membership_start:
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
if not self.survey:
self.survey = CurrentSurvey(obj)
# If the survey is complete, then display the end page.
@ -478,7 +556,7 @@ class WEISurveyView(BaseFormView, DetailView):
# Non first year members don't have a survey
if not obj.first_year:
return redirect(reverse_lazy('wei:wei_survey_end', args=(self.survey.registration.pk,)))
return super().get(request, *args, **kwargs)
return super().dispatch(request, *args, **kwargs)
def get_form_class(self):
"""
@ -519,3 +597,13 @@ class WEISurveyEndView(TemplateView):
context["club"] = WEIRegistration.objects.get(pk=self.kwargs["pk"]).wei
context["title"] = _("Survey WEI")
return context
class WEIClosedView(TemplateView):
template_name = "wei/survey_closed.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["club"] = WEIClub.objects.get(pk=self.kwargs["pk"])
context["title"] = _("Survey WEI")
return context

View File

@ -0,0 +1,25 @@
{% extends "member/noteowner_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block profile_info %}
{% include "wei/weiclub_info.html" %}
{% endblock %}
{% block profile_content %}
<div class="card">
<div class="card-header text-center">
<h4>{% trans "Survey WEI" %}</h4>
</div>
<div class="card-body">
<p>
{% blocktrans %}
The inscription for this WEI are now closed.
{% endblocktrans %}
</p>
</div>
<div class="card-footer text-center">
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:wei_detail' pk=club.pk %}">{% trans "Return to WEI detail" %}</a>
</div>
</div>
{% endblock %}