List pre-registrations (TODO: filter)

This commit is contained in:
Yohann D'ANELLO 2020-04-12 04:29:44 +02:00
parent 6b8e9d45fd
commit bdb0f677e5
4 changed files with 119 additions and 10 deletions

View File

@ -154,6 +154,8 @@ class WEIRegistration(models.Model):
)
health_issues = models.TextField(
blank=True,
default="",
verbose_name=_("health issues"),
)

View File

@ -3,13 +3,15 @@
import django_tables2 as tables
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django_tables2 import A
from .models import WEIClub
from .models import WEIClub, WEIRegistration
class WEITable(tables.Table):
"""
List all clubs.
List all WEI.
"""
class Meta:
attrs = {
@ -23,3 +25,61 @@ class WEITable(tables.Table):
'id': lambda record: "row-" + str(record.pk),
'data-href': lambda record: reverse_lazy('wei:wei_detail', args=(record.pk,))
}
class WEIRegistrationTable(tables.Table):
"""
List all WEI registrations.
"""
user = tables.LinkColumn(
'member:user_detail',
args=[A('user.pk')],
)
edit = tables.LinkColumn(
'wei:wei_detail',
args=[A('pk')],
verbose_name=_("Edit"),
text=_("Edit"),
attrs={
'a': {
'class': 'btn btn-warning'
}
}
)
validate = tables.LinkColumn(
'wei:wei_detail',
args=[A('pk')],
verbose_name=_("Validate"),
text=_("Validate"),
attrs={
'a': {
'class': 'btn btn-success'
}
}
)
delete = tables.LinkColumn(
'wei:wei_detail',
args=[A('pk')],
verbose_name=_("delete"),
text=_("Delete"),
attrs={
'a': {
'class': 'btn btn-danger'
}
},
)
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
model = WEIRegistration
template_name = 'django_tables2/bootstrap4.html'
fields = ('user',)
row_attrs = {
'class': 'table-row',
'id': lambda record: "row-" + str(record.pk),
'data-href': lambda record: record.pk
}

View File

@ -16,9 +16,9 @@ from note.tables import HistoryTable
from permission.backends import PermissionBackend
from permission.views import ProtectQuerysetMixin
from .models import WEIClub, WEIRegistration
from .models import WEIClub, WEIRegistration, WEIMembership
from .forms import WEIForm, WEIRegistrationForm
from .tables import WEITable
from .tables import WEITable, WEIRegistrationTable
class WEIListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
@ -67,15 +67,30 @@ class WEIDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
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_member = WEIMembership.objects.filter(
club=club,
date_end__gte=datetime.today(),
).filter(PermissionBackend.filter_queryset(self.request.user, Membership, "view"))
).filter(PermissionBackend.filter_queryset(self.request.user, WEIMembership, "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
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_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
# Check if the user has the right to create a membership, to display the button.
empty_membership = Membership(
club=club,
@ -115,9 +130,9 @@ class WEIRegisterView(ProtectQuerysetMixin, LoginRequiredMixin, CreateView):
return form
def form_valid(self, form):
ret = super().form_valid(form)
return ret
form.instance.wei = WEIClub.objects.get(pk=self.kwargs["wei_pk"])
return super().form_valid(form)
def get_success_url(self):
self.object.refresh_from_db()
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.pk})
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.wei.pk})

View File

@ -57,6 +57,8 @@
</div>
</div>
<hr>
{% if member_list.data %}
<div class="card">
<div class="card-header position-relative" id="clubListHeading">
@ -81,4 +83,34 @@
{% render_table history_list %}
</div>
</div>
<hr>
{% endif %}
{% if pre_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 "Unvalidated registrations" %}
</a>
</div>
<div id="history_list">
{% render_table pre_registrations %}
</div>
</div>
<hr>
{% endif %}
{% if all_registrations.data or True %}
<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 %}