diff --git a/apps/wei/tables.py b/apps/wei/tables.py index 9bb27bc2..69c7babd 100644 --- a/apps/wei/tables.py +++ b/apps/wei/tables.py @@ -6,7 +6,7 @@ from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from django_tables2 import A -from .models import WEIClub, WEIRegistration, Bus, BusTeam +from .models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership class WEITable(tables.Table): @@ -88,22 +88,58 @@ class WEIRegistrationTable(tables.Table): } +class WEIMembershipTable(tables.Table): + class Meta: + attrs = { + 'class': 'table table-condensed table-striped table-hover' + } + model = WEIMembership + template_name = 'django_tables2/bootstrap4.html' + fields = ('user', ) + row_attrs = { + 'class': 'table-row', + 'id': lambda record: "row-" + str(record.pk), + } + + class BusTable(tables.Table): + name = tables.LinkColumn( + 'wei:manage_bus', + args=[A('pk')], + ) + + teams = tables.Column( + accessor=A("teams"), + verbose_name=_("Teams"), + attrs={ + "td": { + "class": "text-truncate", + } + } + ) + + def render_teams(self, value): + return ", ".join(team.name for team in value.all()) + class Meta: attrs = { 'class': 'table table-condensed table-striped table-hover' } model = Bus template_name = 'django_tables2/bootstrap4.html' - fields = ('name', 'teams',) + fields = ('name', 'teams', ) row_attrs = { 'class': 'table-row', 'id': lambda record: "row-" + str(record.pk), - 'data-href': lambda record: record.pk } class BusTeamTable(tables.Table): + name = tables.LinkColumn( + 'wei:manage_bus_team', + args=[A('pk')], + ) + color = tables.Column( attrs={ "td": { @@ -126,5 +162,5 @@ class BusTeamTable(tables.Table): row_attrs = { 'class': 'table-row', 'id': lambda record: "row-" + str(record.pk), - 'data-href': lambda record: record.pk + 'data-href': lambda record: reverse_lazy('wei:manage_bus_team', args=(record.pk, )) } diff --git a/apps/wei/urls.py b/apps/wei/urls.py index 25779c5b..ade2bae8 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -4,7 +4,7 @@ from django.urls import path from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\ - BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView,\ + BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView,\ WEIRegisterView, WEIUpdateRegistrationView @@ -18,6 +18,8 @@ urlpatterns = [ path('manage-bus//', BusManageView.as_view(), name="manage_bus"), path('update-bus//', BusUpdateView.as_view(), name="update_bus"), path('add-bus-team//', BusTeamCreateView.as_view(), name="add_team"), + path('manage-bus-team//', BusTeamManageView.as_view(), name="manage_bus_team"), + path('update-bus-team//', BusTeamUpdateView.as_view(), name="update_bus_team"), path('register//', WEIRegisterView.as_view(), name="wei_register"), path('edit-registration//', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"), ] diff --git a/apps/wei/views.py b/apps/wei/views.py index 7f245dfd..5ecd4195 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -10,7 +10,6 @@ from django.urls import reverse_lazy from django.views.generic import DetailView, UpdateView, CreateView from django_tables2 import SingleTableView from member.models import Membership, Club -from member.tables import MembershipTable from note.models import Transaction, NoteClub from note.tables import HistoryTable from permission.backends import PermissionBackend @@ -18,7 +17,7 @@ from permission.views import ProtectQuerysetMixin from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm -from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable +from .tables import WEITable, WEIRegistrationTable, BusTable, BusTeamTable, WEIMembershipTable class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): @@ -72,21 +71,12 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): club=club, date_end__gte=datetime.today(), ).filter(PermissionBackend.filter_queryset(self.request.user, WEIMembership, "view")) - membership_table = MembershipTable(data=club_member, prefix="membership-") + membership_table = WEIMembershipTable(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 = WEIRegistration.objects.filter( + PermissionBackend.filter_queryset(self.request.user, WEIRegistration, "view")).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 @@ -179,9 +169,15 @@ class BusManageView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): bus = self.object teams = BusTeam.objects.filter(PermissionBackend.filter_queryset(self.request.user, BusTeam, "view"))\ .filter(bus=bus) - teams_table = BusTeamTable(data=teams, prefix="teams-") + teams_table = BusTeamTable(data=teams, prefix="team-") context["teams"] = teams_table + memberships = WEIMembership.objects.filter(PermissionBackend.filter_queryset( + self.request.user, WEIMembership, "view")).filter(bus=bus) + memberships_table = WEIMembershipTable(data=memberships, prefix="membership-") + memberships_table.paginate(per_page=20, page=self.request.GET.get("membership-page", 1)) + context["memberships"] = memberships_table + return context @@ -208,6 +204,49 @@ class BusTeamCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): return reverse_lazy("wei:manage_bus", kwargs={"pk": self.object.bus.pk}) +class BusTeamUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView): + """ + Update Bus team + """ + model = BusTeam + form_class = BusTeamForm + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["club"] = self.object.bus.wei + context["bus"] = self.object.bus + return context + + def get_form(self, form_class=None): + form = super().get_form(form_class) + form.fields["bus"].disabled = True + return form + + def get_success_url(self): + self.object.refresh_from_db() + return reverse_lazy("wei:manage_bus_team", kwargs={"pk": self.object.pk}) + + +class BusTeamManageView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): + """ + Manage Bus team + """ + model = BusTeam + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context["bus"] = self.object.bus + context["club"] = self.object.bus.wei + + memberships = WEIMembership.objects.filter(PermissionBackend.filter_queryset( + self.request.user, WEIMembership, "view")).filter(team=self.object) + memberships_table = WEIMembershipTable(data=memberships, prefix="membership-") + memberships_table.paginate(per_page=20, page=self.request.GET.get("membership-page", 1)) + context["memberships"] = memberships_table + + return context + + class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView): """ Register to the WEI diff --git a/templates/wei/bus_tables.html b/templates/wei/bus_tables.html index e567c5f3..63f8b56e 100644 --- a/templates/wei/bus_tables.html +++ b/templates/wei/bus_tables.html @@ -19,7 +19,7 @@
-{% if teams.data or True %} +{% if teams.data %}
@@ -31,3 +31,14 @@
{% endif %} + +{% if memberships.data %} +
+ + {% render_table memberships %} +
+{% endif %} diff --git a/templates/wei/busteam_detail.html b/templates/wei/busteam_detail.html new file mode 100644 index 00000000..481e24ea --- /dev/null +++ b/templates/wei/busteam_detail.html @@ -0,0 +1,9 @@ +{% extends "member/noteowner_detail.html" %} + +{% block profile_info %} +{% include "wei/weiclub_info.html" %} +{% endblock %} + +{% block profile_content %} +{% include "wei/busteam_tables.html" %} +{% endblock %} diff --git a/templates/wei/busteam_tables.html b/templates/wei/busteam_tables.html new file mode 100644 index 00000000..2b4deacb --- /dev/null +++ b/templates/wei/busteam_tables.html @@ -0,0 +1,48 @@ +{% load render_table from django_tables2 %} +{% load i18n %} + +
+
+

{{ bus.name }}

+
+ + +
+ {{ bus.description }} +
+ + +
+ +
+ +
+
+

{{ object.name }}

+
+ + +
+ {{ object.description }} +
+ + +
+ +
+ +{% if memberships.data or True %} +
+ + {% render_table memberships %} +
+{% endif %} diff --git a/templates/wei/weiclub_tables.html b/templates/wei/weiclub_tables.html index 3f513d2f..4dd2a0de 100644 --- a/templates/wei/weiclub_tables.html +++ b/templates/wei/weiclub_tables.html @@ -114,16 +114,3 @@
{% endif %} - -{% if all_registrations.data %} -
- -
- {% render_table all_registrations %} -
-
-{% endif %}