mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
View detail of a WEI
This commit is contained in:
parent
31d2224b8f
commit
7ad32c2afd
@ -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)
|
||||
|
@ -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,))
|
||||
}
|
||||
|
@ -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/<int:pk>/', WEIDetailView.as_view(), name="wei_detail"),
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
{% if club.parent_club %}
|
||||
<dt class="col-xl-6"><a href="{% url 'member:club_detail' club.parent_club.pk %}">{% trans 'Club Parent'|capfirst %}</a></dt>
|
||||
<dd class="col-xl-6"> {{ club.parent_club.name}}</dd>
|
||||
<dd class="col-xl-6"> {{ club.parent_club.name }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if club.require_memberships %}
|
||||
@ -40,6 +40,11 @@
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if "note.view_note"|has_perm:club.note %}
|
||||
<dt class="col-xl-6">{% trans 'balance'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ object.note.balance | pretty_money }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt class="col-xl-6"><a href="{% url 'member:club_alias' club.pk %}">{% trans 'aliases'|capfirst %}</a></dt>
|
||||
<dd class="col-xl-6 text-truncate">{{ object.note.alias_set.all|join:", " }}</dd>
|
||||
|
||||
|
20
templates/wei/weiclub_detail.html
Normal file
20
templates/wei/weiclub_detail.html
Normal file
@ -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 %}
|
||||
<script>
|
||||
function refreshHistory() {
|
||||
$("#history_list").load("{% url 'member:club_detail' pk=object.pk %} #history_list");
|
||||
$("#profile_infos").load("{% url 'member:club_detail' pk=object.pk %} #profile_infos");
|
||||
}
|
||||
|
||||
window.history.replaceState({}, document.title, location.pathname);
|
||||
</script>
|
||||
{% endblock %}
|
61
templates/wei/weiclub_info.html
Normal file
61
templates/wei/weiclub_info.html
Normal file
@ -0,0 +1,61 @@
|
||||
{% load i18n static pretty_money perms %}
|
||||
<div class="card bg-light shadow">
|
||||
<div class="card-header text-center">
|
||||
<h4> Club {{ club.name }} </h4>
|
||||
</div>
|
||||
<div class="card-top text-center">
|
||||
<a href="{% url 'member:club_update_pic' club.pk %}">
|
||||
<img src="{{ club.note.display_image.url }}" class="img-thumbnail mt-2" >
|
||||
</a>
|
||||
</div>
|
||||
<div class="card-body" id="profile_infos">
|
||||
<dl class="row">
|
||||
<dt class="col-xl-6">{% trans 'name'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.name }}</dd>
|
||||
|
||||
{% if club.require_memberships %}
|
||||
<dt class="col-xl-6">{% trans 'date start'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.date_start }}</dd>
|
||||
|
||||
<dt class="col-xl-6">{% trans 'date end'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.date_end }}</dd>
|
||||
|
||||
<dt class="col-xl-6">{% trans 'year'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.year }}</dd>
|
||||
|
||||
{% if club.membership_fee_paid == club.membership_fee_unpaid %}
|
||||
<dt class="col-xl-6">{% trans 'membership fee'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.membership_fee_paid|pretty_money }}</dd>
|
||||
{% else %}
|
||||
<dt class="col-xl-6">{% trans 'fee (paid students)'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.membership_fee_paid|pretty_money }}</dd>
|
||||
|
||||
<dt class="col-xl-6">{% trans 'fee (unpaid students)'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ club.membership_fee_unpaid|pretty_money }}</dd>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if "note.view_note"|has_perm:club.note %}
|
||||
<dt class="col-xl-6">{% trans 'balance'|capfirst %}</dt>
|
||||
<dd class="col-xl-6">{{ object.note.balance | pretty_money }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dt class="col-xl-6"><a href="{% url 'member:club_alias' club.pk %}">{% trans 'aliases'|capfirst %}</a></dt>
|
||||
<dd class="col-xl-6 text-truncate">{{ object.note.alias_set.all|join:", " }}</dd>
|
||||
|
||||
<dt class="col-xl-4">{% trans 'email'|capfirst %}</dt>
|
||||
<dd class="col-xl-8"><a href="mailto:{{ club.email }}">{{ club.email }}</a></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
{% if can_add_members %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'member:club_add_member' club_pk=club.pk %}"> {% trans "Add member" %}</a>
|
||||
{% endif %}
|
||||
{% if ".change_"|has_perm:club %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{% url 'member:club_update' pk=club.pk %}"> {% trans "Edit" %}</a>
|
||||
{% endif %}
|
||||
{% url 'member:club_detail' club.pk as club_detail_url %}
|
||||
{%if request.path_info != club_detail_url %}
|
||||
<a class="btn btn-primary btn-sm my-1" href="{{ club_detail_url }}">{% trans 'View Profile' %}</a>
|
||||
{% endif %} </div>
|
||||
</div>
|
23
templates/wei/weiclub_tables.html
Normal file
23
templates/wei/weiclub_tables.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% load render_table from django_tables2 %}
|
||||
{% load i18n %}
|
||||
<div class="card">
|
||||
<div class="card-header position-relative" id="clubListHeading">
|
||||
<a class="btn btn-link stretched-link font-weight-bold">
|
||||
<i class="fa fa-users"></i> {% trans "Member of the Club" %}
|
||||
</a>
|
||||
</div>
|
||||
{% render_table member_list %}
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header position-relative" id="historyListHeading">
|
||||
<a class="btn btn-link stretched-link font-weight-bold">
|
||||
<i class="fa fa-euro"></i> {% trans "Transaction history" %}
|
||||
</a>
|
||||
</div>
|
||||
<div id="history_list">
|
||||
{% render_table history_list %}
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user