1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-21 01:48:21 +02:00

[WEI] Change color of validation button of WEI registrations

Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
2021-08-29 14:10:52 +02:00
parent 0887e4bbde
commit a7bdffd71a
6 changed files with 646 additions and 566 deletions

View File

@ -262,6 +262,33 @@ class WEIRegistration(models.Model):
"""
self.information_json = json.dumps(information, indent=2)
@property
def fee(self):
bde = Club.objects.get(pk=1)
kfet = Club.objects.get(pk=2)
kfet_member = Membership.objects.filter(
club_id=kfet.id,
user=self.user,
date_start__gte=kfet.membership_start,
).exists()
bde_member = Membership.objects.filter(
club_id=bde.id,
user=self.user,
date_start__gte=bde.membership_start,
).exists()
fee = self.wei.membership_fee_paid if self.user.profile.paid \
else self.wei.membership_fee_unpaid
if not kfet_member:
fee += kfet.membership_fee_paid if self.user.profile.paid \
else kfet.membership_fee_unpaid
if not bde_member:
fee += bde.membership_fee_paid if self.user.profile.paid \
else bde.membership_fee_unpaid
return fee
@property
def is_validated(self):
try:

View File

@ -43,6 +43,7 @@ class WEIRegistrationTable(tables.Table):
edit = tables.LinkColumn(
'wei:wei_update_registration',
orderable=False,
args=[A('pk')],
verbose_name=_("Edit"),
text=_("Edit"),
@ -53,18 +54,14 @@ class WEIRegistrationTable(tables.Table):
}
}
)
validate = tables.LinkColumn(
'wei:validate_registration',
args=[A('pk')],
validate = tables.Column(
verbose_name=_("Validate"),
text=_("Validate"),
orderable=False,
accessor=A('pk'),
attrs={
'th': {
'id': 'validate-membership-header'
},
'a': {
'class': 'btn btn-success',
'data-type': 'validate-membership'
}
}
)
@ -72,6 +69,7 @@ class WEIRegistrationTable(tables.Table):
delete = tables.LinkColumn(
'wei:wei_delete_registration',
args=[A('pk')],
orderable=False,
verbose_name=_("delete"),
text=_("Delete"),
attrs={
@ -96,7 +94,20 @@ class WEIRegistrationTable(tables.Table):
registration=record,
)
)
return _("Validate") if hasperm else format_html("<span class='no-perm'></span>")
if not hasperm:
return format_html("<span class='no-perm'></span>")
url = reverse_lazy('wei:validate_registration', args=(record.pk,))
text = _('Validate')
if record.fee > record.user.note.balance:
btn_class = 'btn-secondary'
tooltip = _("The user does not have enough money.")
else:
btn_class = 'btn-success'
tooltip = _("The user has enough money, you can validate the registration.")
return format_html(f"<a class=\"btn {btn_class}\" data-type='validate-membership' data-toggle=\"tooltip\" "
f"title=\"{tooltip}\" href=\"{url}\">{text}</a>")
def render_delete(self, record):
hasperm = PermissionBackend.check_perm(get_current_authenticated_user(), "wei.delete_weimembership", record)
@ -108,7 +119,8 @@ class WEIRegistrationTable(tables.Table):
}
model = WEIRegistration
template_name = 'django_tables2/bootstrap4.html'
fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'caution_check',)
fields = ('user', 'user__first_name', 'user__last_name', 'first_year', 'caution_check',
'edit', 'validate', 'delete',)
row_attrs = {
'class': 'table-row',
'id': lambda record: "row-" + str(record.pk),

View File

@ -818,22 +818,13 @@ class WEIValidateRegistrationView(ProtectQuerysetMixin, ProtectedCreateView):
date_start__gte=bde.membership_start,
).exists()
fee = registration.wei.membership_fee_paid if registration.user.profile.paid \
else registration.wei.membership_fee_unpaid
if not context["kfet_member"]:
fee += kfet.membership_fee_paid if registration.user.profile.paid \
else kfet.membership_fee_unpaid
if not context["bde_member"]:
fee += bde.membership_fee_paid if registration.user.profile.paid \
else bde.membership_fee_unpaid
context["fee"] = fee
context["fee"] = registration.fee
form = context["form"]
if registration.soge_credit:
form.fields["credit_amount"].initial = fee
form.fields["credit_amount"].initial = registration.fee
else:
form.fields["credit_amount"].initial = max(0, fee - registration.user.note.balance)
form.fields["credit_amount"].initial = max(0, registration.fee - registration.user.note.balance)
return context