Edit and view teams

This commit is contained in:
Yohann D'ANELLO 2020-04-13 21:16:52 +02:00
parent 840376a4f5
commit 0bf958dbd6
7 changed files with 166 additions and 34 deletions

View File

@ -6,7 +6,7 @@ from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django_tables2 import A from django_tables2 import A
from .models import WEIClub, WEIRegistration, Bus, BusTeam from .models import WEIClub, WEIRegistration, Bus, BusTeam, WEIMembership
class WEITable(tables.Table): 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): 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: class Meta:
attrs = { attrs = {
'class': 'table table-condensed table-striped table-hover' 'class': 'table table-condensed table-striped table-hover'
} }
model = Bus model = Bus
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
fields = ('name', 'teams',) fields = ('name', 'teams', )
row_attrs = { row_attrs = {
'class': 'table-row', 'class': 'table-row',
'id': lambda record: "row-" + str(record.pk), 'id': lambda record: "row-" + str(record.pk),
'data-href': lambda record: record.pk
} }
class BusTeamTable(tables.Table): class BusTeamTable(tables.Table):
name = tables.LinkColumn(
'wei:manage_bus_team',
args=[A('pk')],
)
color = tables.Column( color = tables.Column(
attrs={ attrs={
"td": { "td": {
@ -126,5 +162,5 @@ class BusTeamTable(tables.Table):
row_attrs = { row_attrs = {
'class': 'table-row', 'class': 'table-row',
'id': lambda record: "row-" + str(record.pk), '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, ))
} }

View File

@ -4,7 +4,7 @@
from django.urls import path from django.urls import path
from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\ from .views import WEIListView, WEICreateView, WEIDetailView, WEIUpdateView,\
BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView,\ BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView,\
WEIRegisterView, WEIUpdateRegistrationView WEIRegisterView, WEIUpdateRegistrationView
@ -18,6 +18,8 @@ urlpatterns = [
path('manage-bus/<int:pk>/', BusManageView.as_view(), name="manage_bus"), path('manage-bus/<int:pk>/', BusManageView.as_view(), name="manage_bus"),
path('update-bus/<int:pk>/', BusUpdateView.as_view(), name="update_bus"), path('update-bus/<int:pk>/', BusUpdateView.as_view(), name="update_bus"),
path('add-bus-team/<int:pk>/', BusTeamCreateView.as_view(), name="add_team"), path('add-bus-team/<int:pk>/', BusTeamCreateView.as_view(), name="add_team"),
path('manage-bus-team/<int:pk>/', BusTeamManageView.as_view(), name="manage_bus_team"),
path('update-bus-team/<int:pk>/', BusTeamUpdateView.as_view(), name="update_bus_team"),
path('register/<int:wei_pk>/', WEIRegisterView.as_view(), name="wei_register"), path('register/<int:wei_pk>/', WEIRegisterView.as_view(), name="wei_register"),
path('edit-registration/<int:pk>/', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"), path('edit-registration/<int:pk>/', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"),
] ]

View File

@ -10,7 +10,6 @@ from django.urls import reverse_lazy
from django.views.generic import DetailView, UpdateView, CreateView from django.views.generic import DetailView, UpdateView, CreateView
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from member.models import Membership, Club from member.models import Membership, Club
from member.tables import MembershipTable
from note.models import Transaction, NoteClub from note.models import Transaction, NoteClub
from note.tables import HistoryTable from note.tables import HistoryTable
from permission.backends import PermissionBackend from permission.backends import PermissionBackend
@ -18,7 +17,7 @@ from permission.views import ProtectQuerysetMixin
from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam from .models import WEIClub, WEIRegistration, WEIMembership, Bus, BusTeam
from .forms import WEIForm, WEIRegistrationForm, BusForm, BusTeamForm 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): class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
@ -72,21 +71,12 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
club=club, club=club,
date_end__gte=datetime.today(), date_end__gte=datetime.today(),
).filter(PermissionBackend.filter_queryset(self.request.user, WEIMembership, "view")) ).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)) membership_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1))
context['member_list'] = membership_table context['member_list'] = membership_table
WEIRegistrationTable.base_columns["delete"].visible = False pre_registrations = WEIRegistration.objects.filter(
WEIRegistrationTable.base_columns["validate"].visible = False PermissionBackend.filter_queryset(self.request.user, WEIRegistration, "view")).filter(membership=None)
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 = WEIRegistrationTable(data=pre_registrations, prefix="pre-registration-")
pre_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1)) pre_registrations_table.paginate(per_page=20, page=self.request.GET.get('membership-page', 1))
context['pre_registrations'] = pre_registrations_table context['pre_registrations'] = pre_registrations_table
@ -179,9 +169,15 @@ class BusManageView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
bus = self.object bus = self.object
teams = BusTeam.objects.filter(PermissionBackend.filter_queryset(self.request.user, BusTeam, "view"))\ teams = BusTeam.objects.filter(PermissionBackend.filter_queryset(self.request.user, BusTeam, "view"))\
.filter(bus=bus) .filter(bus=bus)
teams_table = BusTeamTable(data=teams, prefix="teams-") teams_table = BusTeamTable(data=teams, prefix="team-")
context["teams"] = teams_table 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 return context
@ -208,6 +204,49 @@ class BusTeamCreateView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
return reverse_lazy("wei:manage_bus", kwargs={"pk": self.object.bus.pk}) 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): class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
""" """
Register to the WEI Register to the WEI

View File

@ -19,7 +19,7 @@
<hr> <hr>
{% if teams.data or True %} {% if teams.data %}
<div class="card"> <div class="card">
<div class="card-header position-relative" id="clubListHeading"> <div class="card-header position-relative" id="clubListHeading">
<a class="btn btn-link stretched-link font-weight-bold"> <a class="btn btn-link stretched-link font-weight-bold">
@ -31,3 +31,14 @@
<hr> <hr>
{% endif %} {% endif %}
{% if memberships.data %}
<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-bus"></i> {% trans "Members" %}
</a>
</div>
{% render_table memberships %}
</div>
{% endif %}

View File

@ -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 %}

View File

@ -0,0 +1,48 @@
{% load render_table from django_tables2 %}
{% load i18n %}
<div class="card">
<div class="card-header text-center">
<h4>{{ bus.name }}</h4>
</div>
<div class="card-body">
{{ bus.description }}
</div>
<div class="card-footer text-center">
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:update_bus' pk=bus.pk %}">{% trans "Edit" %}</a>
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:add_team' pk=bus.pk %}">{% trans "Add team" %}</a>
</div>
</div>
<hr>
<div class="card">
<div class="card-header text-center" style="background-color: #{{ object.color|stringformat:"06X" }}; color: #{{ -16777215|add:object.color|stringformat:"06X"|slice:"1:" }};">
<h4>{{ object.name }}</h4>
</div>
<div class="card-body">
{{ object.description }}
</div>
<div class="card-footer text-center">
<a class="btn btn-primary btn-sm my-1" href="{% url 'wei:update_bus_team' pk=object.pk %}">{% trans "Edit" %}</a>
</div>
</div>
<hr>
{% if memberships.data or True %}
<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-bus"></i> {% trans "Teams" %}
</a>
</div>
{% render_table memberships %}
</div>
{% endif %}

View File

@ -114,16 +114,3 @@
<hr> <hr>
{% endif %} {% endif %}
{% if all_registrations.data %}
<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-user-plus"></i> {% trans "All registrations" %}
</a>
</div>
<div id="history_list">
{% render_table all_registrations %}
</div>
</div>
{% endif %}