mirror of https://gitlab.crans.org/bde/nk20
Edit and view teams
This commit is contained in:
parent
840376a4f5
commit
0bf958dbd6
|
@ -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, ))
|
||||
}
|
||||
|
|
|
@ -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/<int:pk>/', BusManageView.as_view(), name="manage_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('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('edit-registration/<int:pk>/', WEIUpdateRegistrationView.as_view(), name="wei_update_registration"),
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
<hr>
|
||||
|
||||
{% if teams.data or True %}
|
||||
{% if teams.data %}
|
||||
<div class="card">
|
||||
<div class="card-header position-relative" id="clubListHeading">
|
||||
<a class="btn btn-link stretched-link font-weight-bold">
|
||||
|
@ -31,3 +31,14 @@
|
|||
|
||||
<hr>
|
||||
{% 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 %}
|
||||
|
|
|
@ -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 %}
|
|
@ -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 %}
|
|
@ -114,16 +114,3 @@
|
|||
|
||||
<hr>
|
||||
{% 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 %}
|
||||
|
|
Loading…
Reference in New Issue