From 7ad32c2afd699538479dc08342d84266c04f59f0 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sun, 12 Apr 2020 00:06:20 +0200 Subject: [PATCH] View detail of a WEI --- apps/wei/api/urls.py | 2 +- apps/wei/tables.py | 2 +- apps/wei/urls.py | 3 +- apps/wei/views.py | 53 +++++++++++++++++++++++++++ templates/member/club_info.html | 7 +++- templates/wei/weiclub_detail.html | 20 ++++++++++ templates/wei/weiclub_info.html | 61 +++++++++++++++++++++++++++++++ templates/wei/weiclub_tables.html | 23 ++++++++++++ 8 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 templates/wei/weiclub_detail.html create mode 100644 templates/wei/weiclub_info.html create mode 100644 templates/wei/weiclub_tables.html diff --git a/apps/wei/api/urls.py b/apps/wei/api/urls.py index f5836b8c..7d39e8da 100644 --- a/apps/wei/api/urls.py +++ b/apps/wei/api/urls.py @@ -8,4 +8,4 @@ def register_wei_urls(router, path): """ Configure router for Member REST API. """ - router.register(path + '/club', WEIClubViewSet) + router.register(path + '/club/', WEIClubViewSet) diff --git a/apps/wei/tables.py b/apps/wei/tables.py index 3c1bd3af..8cb23ef2 100644 --- a/apps/wei/tables.py +++ b/apps/wei/tables.py @@ -21,5 +21,5 @@ class WEITable(tables.Table): row_attrs = { 'class': 'table-row', 'id': lambda record: "row-" + str(record.pk), - 'data-href': lambda record: reverse_lazy('member:club_detail', args=(record.pk,)) + 'data-href': lambda record: reverse_lazy('wei:wei_detail', args=(record.pk,)) } diff --git a/apps/wei/urls.py b/apps/wei/urls.py index 9c898139..71af9cb7 100644 --- a/apps/wei/urls.py +++ b/apps/wei/urls.py @@ -3,10 +3,11 @@ from django.urls import path -from .views import WEIListView +from .views import WEIListView, WEIDetailView app_name = 'wei' urlpatterns = [ path('list/', WEIListView.as_view(), name="wei_list"), + path('detail//', WEIDetailView.as_view(), name="wei_detail"), ] diff --git a/apps/wei/views.py b/apps/wei/views.py index 7d7fc01f..eb66a74f 100644 --- a/apps/wei/views.py +++ b/apps/wei/views.py @@ -1,8 +1,19 @@ # Copyright (C) 2018-2020 by BDE ENS Paris-Saclay # SPDX-License-Identifier: GPL-3.0-or-later +from datetime import datetime + from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.auth.models import User +from django.db.models import Q +from django.views.generic import DetailView from django_tables2 import SingleTableView + +from member.models import Membership +from member.tables import MembershipTable +from note.models import Transaction +from note.tables import HistoryTable +from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin from wei.models import WEIClub @@ -15,3 +26,45 @@ class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): """ model = WEIClub table_class = WEITable + + +class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView): + """ + View WEI information + """ + model = WEIClub + context_object_name = "club" + + def get_context_data(self, **kwargs): + 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') + 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=club, + date_end__gte=datetime.today(), + ).filter(PermissionBackend.filter_queryset(self.request.user, Membership, "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 + + # Check if the user has the right to create a membership, to display the button. + empty_membership = Membership( + club=club, + user=User.objects.first(), + date_start=datetime.now().date(), + date_end=datetime.now().date(), + fee=0, + ) + context["can_add_members"] = PermissionBackend() \ + .has_perm(self.request.user, "member.add_membership", empty_membership) + + return context diff --git a/templates/member/club_info.html b/templates/member/club_info.html index 135862d9..eeebc823 100644 --- a/templates/member/club_info.html +++ b/templates/member/club_info.html @@ -15,7 +15,7 @@ {% if club.parent_club %}
{% trans 'Club Parent'|capfirst %}
-
{{ club.parent_club.name}}
+
{{ club.parent_club.name }}
{% endif %} {% if club.require_memberships %} @@ -39,6 +39,11 @@
{{ club.membership_fee_unpaid|pretty_money }}
{% endif %} {% endif %} + + {% if "note.view_note"|has_perm:club.note %} +
{% trans 'balance'|capfirst %}
+
{{ object.note.balance | pretty_money }}
+ {% endif %}
{% trans 'aliases'|capfirst %}
{{ object.note.alias_set.all|join:", " }}
diff --git a/templates/wei/weiclub_detail.html b/templates/wei/weiclub_detail.html new file mode 100644 index 00000000..7ccd8dea --- /dev/null +++ b/templates/wei/weiclub_detail.html @@ -0,0 +1,20 @@ +{% extends "member/noteowner_detail.html" %} + +{% block profile_info %} +{% include "wei/weiclub_info.html" %} +{% endblock %} + +{% block profile_content %} +{% include "member/club_tables.html" %} +{% endblock %} + +{% block extrajavascript %} + +{% endblock %} diff --git a/templates/wei/weiclub_info.html b/templates/wei/weiclub_info.html new file mode 100644 index 00000000..03cb69f2 --- /dev/null +++ b/templates/wei/weiclub_info.html @@ -0,0 +1,61 @@ +{% load i18n static pretty_money perms %} +
+
+

Club {{ club.name }}

+
+
+ + + +
+
+
+
{% trans 'name'|capfirst %}
+
{{ club.name }}
+ + {% if club.require_memberships %} +
{% trans 'date start'|capfirst %}
+
{{ club.date_start }}
+ +
{% trans 'date end'|capfirst %}
+
{{ club.date_end }}
+ +
{% trans 'year'|capfirst %}
+
{{ club.year }}
+ + {% if club.membership_fee_paid == club.membership_fee_unpaid %} +
{% trans 'membership fee'|capfirst %}
+
{{ club.membership_fee_paid|pretty_money }}
+ {% else %} +
{% trans 'fee (paid students)'|capfirst %}
+
{{ club.membership_fee_paid|pretty_money }}
+ +
{% trans 'fee (unpaid students)'|capfirst %}
+
{{ club.membership_fee_unpaid|pretty_money }}
+ {% endif %} + {% endif %} + + {% if "note.view_note"|has_perm:club.note %} +
{% trans 'balance'|capfirst %}
+
{{ object.note.balance | pretty_money }}
+ {% endif %} + +
{% trans 'aliases'|capfirst %}
+
{{ object.note.alias_set.all|join:", " }}
+ +
{% trans 'email'|capfirst %}
+
{{ club.email }}
+
+
+ +
diff --git a/templates/wei/weiclub_tables.html b/templates/wei/weiclub_tables.html new file mode 100644 index 00000000..32be9bd4 --- /dev/null +++ b/templates/wei/weiclub_tables.html @@ -0,0 +1,23 @@ +{% load render_table from django_tables2 %} +{% load i18n %} +
+ + {% render_table member_list %} +
+ +
+ +
+ +
+ {% render_table history_list %} +
+