mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-07-23 01:06:47 +02:00
Better Membership update
This commit is contained in:
@ -136,8 +136,8 @@ class WEIRegistrationTable(tables.Table):
|
||||
|
||||
class WEIMembershipTable(tables.Table):
|
||||
user = tables.LinkColumn(
|
||||
'wei:wei_update_registration',
|
||||
args=[A('registration__pk')],
|
||||
'wei:wei_update_membership',
|
||||
args=[A('pk')],
|
||||
)
|
||||
|
||||
year = tables.Column(
|
||||
|
@ -213,7 +213,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||
$("input[name='bus']:checked").each(function (ignored) {
|
||||
buses.push($(this).parent().text().trim());
|
||||
});
|
||||
console.log(buses);
|
||||
$("input[name='team']").each(function () {
|
||||
let label = $(this).parent();
|
||||
$(this).parent().addClass('d-none');
|
||||
|
46
apps/wei/templates/wei/weimembership_update.html
Normal file
46
apps/wei/templates/wei/weimembership_update.html
Normal file
@ -0,0 +1,46 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
Copyright (C) 2018-2025 by BDE ENS Paris-Saclay
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
{% endcomment %}
|
||||
{% load i18n crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
<div class="card bg-white mb-3">
|
||||
<h3 class="card-header text-center">
|
||||
{{ title }}
|
||||
</h3>
|
||||
<div class="card-body" id="form">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form | crispy }}
|
||||
<button class="btn btn-primary" type="submit">{% trans "Submit"%}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
function refreshTeams() {
|
||||
let buses = [];
|
||||
$("input[name='bus']:checked").each(function (ignored) {
|
||||
buses.push($(this).parent().text().trim());
|
||||
});
|
||||
$("input[name='team']").each(function () {
|
||||
let label = $(this).parent();
|
||||
$(this).parent().addClass('d-none');
|
||||
buses.forEach(function (bus) {
|
||||
if (label.text().includes(bus))
|
||||
label.removeClass('d-none');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$("input[name='bus']").change(refreshTeams);
|
||||
|
||||
refreshTeams();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@ -7,7 +7,7 @@ from .views import CurrentWEIDetailView, WEI1AListView, WEIListView, WEICreateVi
|
||||
WEIRegistrationsView, WEIMembershipsView, MemberListRenderView, BusInformationUpdateView, \
|
||||
BusCreateView, BusManageView, BusUpdateView, BusTeamCreateView, BusTeamManageView, BusTeamUpdateView, \
|
||||
WEIAttributeBus1AView, WEIAttributeBus1ANextView, WEIRegister1AView, WEIRegister2AView, WEIUpdateRegistrationView, \
|
||||
WEIDeleteRegistrationView, WEIValidateRegistrationView, WEISurveyView, WEISurveyEndView, WEIClosedView
|
||||
WEIDeleteRegistrationView, WEIValidateRegistrationView, WEISurveyView, WEISurveyEndView, WEIClosedView, WEIUpdateMembershipView
|
||||
|
||||
app_name = 'wei'
|
||||
urlpatterns = [
|
||||
@ -43,4 +43,6 @@ urlpatterns = [
|
||||
path('bus-1A/<int:pk>/', WEIAttributeBus1AView.as_view(), name="wei_bus_1A"),
|
||||
path('bus-1A/next/<int:pk>/', WEIAttributeBus1ANextView.as_view(), name="wei_bus_1A_next"),
|
||||
path('update-bus-info/<int:pk>/', BusInformationUpdateView.as_view(), name="update_bus_info"),
|
||||
|
||||
path('edit_membership/<int:pk>/', WEIUpdateMembershipView.as_view(), name="wei_update_membership"),
|
||||
]
|
||||
|
@ -1181,6 +1181,49 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
|
||||
return reverse_lazy("wei:wei_registrations", kwargs={"pk": self.object.club.pk})
|
||||
|
||||
|
||||
class WEIUpdateMembershipView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||
"""
|
||||
Update a membership for the WEI
|
||||
"""
|
||||
model = WEIMembership
|
||||
context_object_name = "membership"
|
||||
template_name = "wei/weimembership_update.html"
|
||||
extra_context = {"title": _("Update WEI Membership")}
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
wei = self.get_object().registration.wei
|
||||
today = date.today()
|
||||
# We can't update a registration once the WEI is started and before the membership start date
|
||||
if today >= wei.date_start or today < wei.membership_start:
|
||||
return redirect(reverse_lazy('wei:wei_closed', args=(wei.pk,)))
|
||||
# Store the validate parameter in the view's state
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get_form(self):
|
||||
form = WEIMembershipForm(
|
||||
self.request.POST or None,
|
||||
self.request.FILES or None,
|
||||
instance=self.object,
|
||||
wei=self.object.registration.wei,
|
||||
)
|
||||
|
||||
form.fields["roles"].initial = self.object.roles.all()
|
||||
form.fields["bus"].initial = self.object.bus
|
||||
form.fields["team"].initial = self.object.team
|
||||
|
||||
del form.fields["credit_type"]
|
||||
del form.fields["credit_amount"]
|
||||
del form.fields["first_name"]
|
||||
del form.fields["last_name"]
|
||||
del form.fields["bank"]
|
||||
|
||||
return form
|
||||
|
||||
def get_success_url(self):
|
||||
print("get_success_url")
|
||||
return reverse_lazy("wei:wei_detail", kwargs={"pk": self.object.registration.wei.pk})
|
||||
|
||||
|
||||
class WEISurveyView(LoginRequiredMixin, BaseFormView, DetailView):
|
||||
"""
|
||||
Display the survey for the WEI for first year members.
|
||||
|
Reference in New Issue
Block a user