From ef118c2445b1ab132cedecb4a6fe5cece16402d2 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 13 Sep 2021 19:02:54 +0200 Subject: [PATCH] [WEI] Avoid errors if the survey is not ended Signed-off-by: Yohann D'ANELLO --- apps/wei/tables.py | 5 ++--- apps/wei/views.py | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/wei/tables.py b/apps/wei/tables.py index d9e095c9..687f8f07 100644 --- a/apps/wei/tables.py +++ b/apps/wei/tables.py @@ -190,13 +190,12 @@ class WEIRegistration1ATable(tables.Table): attrs = { 'class': 'table table-condensed table-striped table-hover' } - model = WEIMembership + model = WEIRegistration template_name = 'django_tables2/bootstrap4.html' fields = ('user', 'user__last_name', 'user__first_name', 'gender', 'user__profile__department', 'preferred_bus', 'membership__bus', ) row_attrs = { - 'class': 'table-row', - 'id': lambda record: "row-" + str(record.pk), + 'class': lambda record: '' if 'selected_bus_pk' in record.information else 'bg-danger', } diff --git a/apps/wei/views.py b/apps/wei/views.py index 0f08e06f..23ab8485 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -1195,6 +1195,12 @@ class WEIAttributeBus1AView(ProtectQuerysetMixin, DetailView): qs = qs.filter(first_year=True) return qs + def dispatch(self, request, *args, **kwargs): + obj = self.get_object() + if 'selected_bus_pk' not in obj.information: + return redirect(reverse_lazy('wei:wei_survey', args=(obj.pk,))) + return super().dispatch(request, *args, **kwargs) + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['club'] = self.object.wei @@ -1209,6 +1215,7 @@ class WEIAttributeBus1ANextView(LoginRequiredMixin, RedirectView): raise Http404 wei = wei.get() qs = WEIRegistration.objects.filter(wei=wei, membership__isnull=False, membership__bus__isnull=True) + qs = qs.filter(information_json__contains='selected_bus_pk') # not perfect, but works... if qs.exists(): return reverse_lazy('wei:wei_bus_1A', args=(qs.first().pk, )) return reverse_lazy('wei_1A_list', args=(wei.pk, ))