diff --git a/apps/wei/models.py b/apps/wei/models.py index 1884308f..8a57863c 100644 --- a/apps/wei/models.py +++ b/apps/wei/models.py @@ -154,6 +154,8 @@ class WEIRegistration(models.Model): ) health_issues = models.TextField( + blank=True, + default="", verbose_name=_("health issues"), ) diff --git a/apps/wei/tables.py b/apps/wei/tables.py index 40d11b8d..0efbee34 100644 --- a/apps/wei/tables.py +++ b/apps/wei/tables.py @@ -3,13 +3,15 @@ import django_tables2 as tables from django.urls import reverse_lazy +from django.utils.translation import gettext_lazy as _ +from django_tables2 import A -from .models import WEIClub +from .models import WEIClub, WEIRegistration class WEITable(tables.Table): """ - List all clubs. + List all WEI. """ class Meta: attrs = { @@ -23,3 +25,61 @@ class WEITable(tables.Table): 'id': lambda record: "row-" + str(record.pk), 'data-href': lambda record: reverse_lazy('wei:wei_detail', args=(record.pk,)) } + + +class WEIRegistrationTable(tables.Table): + """ + List all WEI registrations. + """ + user = tables.LinkColumn( + 'member:user_detail', + args=[A('user.pk')], + ) + + edit = tables.LinkColumn( + 'wei:wei_detail', + args=[A('pk')], + verbose_name=_("Edit"), + text=_("Edit"), + attrs={ + 'a': { + 'class': 'btn btn-warning' + } + } + ) + validate = tables.LinkColumn( + 'wei:wei_detail', + args=[A('pk')], + verbose_name=_("Validate"), + text=_("Validate"), + attrs={ + 'a': { + 'class': 'btn btn-success' + } + } + ) + + delete = tables.LinkColumn( + 'wei:wei_detail', + args=[A('pk')], + verbose_name=_("delete"), + text=_("Delete"), + attrs={ + 'a': { + 'class': 'btn btn-danger' + } + }, + ) + + class Meta: + attrs = { + 'class': 'table table-condensed table-striped table-hover' + } + model = WEIRegistration + template_name = 'django_tables2/bootstrap4.html' + fields = ('user',) + row_attrs = { + 'class': 'table-row', + 'id': lambda record: "row-" + str(record.pk), + 'data-href': lambda record: record.pk + } diff --git a/apps/wei/views.py b/apps/wei/views.py index ef99f9c7..c5799902 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -16,9 +16,9 @@ from note.tables import HistoryTable from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin -from .models import WEIClub, WEIRegistration +from .models import WEIClub, WEIRegistration, WEIMembership from .forms import WEIForm, WEIRegistrationForm -from .tables import WEITable +from .tables import WEITable, WEIRegistrationTable class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): @@ -67,15 +67,30 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): history_table = HistoryTable(club_transactions, prefix="history-") history_table.paginate(per_page=20, page=self.request.GET.get('history-page', 1)) context['history_list'] = history_table - club_member = Membership.objects.filter( + + club_member = WEIMembership.objects.filter( club=club, date_end__gte=datetime.today(), - ).filter(PermissionBackend.filter_queryset(self.request.user, Membership, "view")) - + ).filter(PermissionBackend.filter_queryset(self.request.user, WEIMembership, "view")) membership_table = MembershipTable(data=club_member, prefix="membership-") membership_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1)) context['member_list'] = membership_table + WEIRegistrationTable.base_columns["delete"].visible = False + WEIRegistrationTable.base_columns["validate"].visible = False + all_registrations = WEIRegistration.objects.filter( + PermissionBackend.filter_queryset(self.request.user, WEIRegistration, "view")) + all_registrations_table = WEIRegistrationTable(data=all_registrations, prefix="all-registration-") + all_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1)) + context['all_registrations'] = all_registrations_table + + WEIRegistrationTable.base_columns["delete"].visible = True + WEIRegistrationTable.base_columns["validate"].visible = True + pre_registrations = all_registrations.filter(membership=None) + pre_registrations_table = WEIRegistrationTable(data=pre_registrations, prefix="pre-registration-") + pre_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1)) + context['pre_registrations'] = pre_registrations_table + # Check if the user has the right to create a membership, to display the button. empty_membership = Membership( club=club, @@ -115,9 +130,9 @@ class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): return form def form_valid(self, form): - ret = super().form_valid(form) - return ret + form.instance.wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"]) + return super().form_valid(form) def get_success_url(self): self.object.refresh_from_db() - return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk}) + return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk}) diff --git a/templates/wei/weiclub_tables.html b/templates/wei/weiclub_tables.html index bdd345c9..6fc72e81 100644 --- a/templates/wei/weiclub_tables.html +++ b/templates/wei/weiclub_tables.html @@ -57,6 +57,8 @@ +
+ {% if member_list.data %}
@@ -81,4 +83,34 @@ {% render_table history_list %}
+ +
+{% endif %} + +{% if pre_registrations.data %} +
+
+ + {% trans "Unvalidated registrations" %} + +
+
+ {% render_table pre_registrations %} +
+
+ +
+{% endif %} + +{% if all_registrations.data or True %} +
+
+ + {% trans "All registrations" %} + +
+
+ {% render_table all_registrations %} +
+
{% endif %}