diff --git a/apps/registration/forms.py b/apps/registration/forms.py index ad28483..ac4650b 100644 --- a/apps/registration/forms.py +++ b/apps/registration/forms.py @@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError from django.forms import FileInput from django.utils.translation import gettext_lazy as _ -from .models import AdminRegistration, CoachRegistration, StudentRegistration, VolunteerRegistration +from .models import AdminRegistration, CoachRegistration, Payment, StudentRegistration, VolunteerRegistration class SignupForm(UserCreationForm): @@ -197,3 +197,34 @@ class AdminRegistrationForm(forms.ModelForm): class Meta: model = AdminRegistration fields = ('role', 'give_contact_to_animath', 'email_confirmed',) + + +class PaymentForm(forms.ModelForm): + """ + Indicate payment information + """ + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["valid"].widget.choices[0] = ('unknown', _("Pending")) + + def clean_scholarship_file(self): + if "scholarship_file" in self.files: + file = self.files["scholarship_file"] + if file.size > 2e6: + raise ValidationError(_("The uploaded file size must be under 2 Mo.")) + if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]: + raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file.")) + return self.cleaned_data["scholarship_file"] + + def clean(self): + cleaned_data = super().clean() + + if "type" in cleaned_data and cleaned_data["type"] == "scholarship" \ + and "scholarship" not in cleaned_data and not self.instance.scholarship_file: + self.add_error("scholarship_file", _("You must upload your scholarship attestation.")) + + return cleaned_data + + class Meta: + model = Payment + fields = ('type', 'scholarship_file', 'additional_information', 'valid',) diff --git a/apps/registration/models.py b/apps/registration/models.py index 18dc200..e45d61f 100644 --- a/apps/registration/models.py +++ b/apps/registration/models.py @@ -338,6 +338,9 @@ class Payment(models.Model): default=False, ) + def get_absolute_url(self): + return reverse_lazy("registration:user_detail", args=(self.registration.user.id,)) + class Meta: verbose_name = _("payment") verbose_name_plural = _("payments") diff --git a/apps/registration/templates/registration/payment_form.html b/apps/registration/templates/registration/payment_form.html new file mode 100644 index 0000000..bd8db0d --- /dev/null +++ b/apps/registration/templates/registration/payment_form.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% load crispy_forms_filters i18n %} + +{% block content %} +
+{% endblock content %} + diff --git a/apps/registration/templates/registration/user_detail.html b/apps/registration/templates/registration/user_detail.html index 39be1d4..d7310b8 100644 --- a/apps/registration/templates/registration/user_detail.html +++ b/apps/registration/templates/registration/user_detail.html @@ -53,7 +53,7 @@ {% if user_object.registration.photo_authorization %} {% trans "Download" %} {% endif %} - {% if user_object.pk == user.pk %} + {% if user_object.registration.team and not user_object.registration.team.participation.valid %} {% endif %} @@ -63,7 +63,7 @@ {% if user_object.registration.health_sheet %} {% trans "Download" %} {% endif %} - {% if user_object.pk == user.pk %} + {% if user_object.registration.team and not user_object.registration.team.participation.valid %} {% endif %} @@ -76,7 +76,7 @@ {% if user_object.registration.parental_authorization %} {% trans "Download" %} {% endif %} - {% if user_object.pk == user.pk %} + {% if user_object.registration.team and not user_object.registration.team.participation.valid %} {% endif %} @@ -125,6 +125,11 @@ {% else %} {{ user_object.registration.payment.get_type_display }}, {% trans "valid:" %} {{ user_object.registration.payment.valid|yesno:yesnodefault }} {% endif %} + {% if user.registration.is_admin or user_object.registration.payment.valid is False %} + + {% endif %} {% endwith %} @@ -145,20 +150,34 @@ {% url "registration:update_user" pk=user_object.pk as modal_action %} {% include "base_modal.html" with modal_id="updateUser" %} - {% trans "Upload photo authorization" as modal_title %} - {% trans "Upload" as modal_button %} - {% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk as modal_action %} - {% include "base_modal.html" with modal_id="uploadPhotoAuthorization" modal_enctype="multipart/form-data" %} + {% if user_object.registration.team and not user_object.registration.team.participation.valid %} + {% trans "Upload photo authorization" as modal_title %} + {% trans "Upload" as modal_button %} + {% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk as modal_action %} + {% include "base_modal.html" with modal_id="uploadPhotoAuthorization" modal_enctype="multipart/form-data" %} - {% trans "Upload health sheet" as modal_title %} - {% trans "Upload" as modal_button %} - {% url "registration:upload_user_health_sheet" pk=user_object.registration.pk as modal_action %} - {% include "base_modal.html" with modal_id="uploadHealthSheet" modal_enctype="multipart/form-data" %} + {% trans "Upload health sheet" as modal_title %} + {% trans "Upload" as modal_button %} + {% url "registration:upload_user_health_sheet" pk=user_object.registration.pk as modal_action %} + {% include "base_modal.html" with modal_id="uploadHealthSheet" modal_enctype="multipart/form-data" %} - {% trans "Upload parental authorization" as modal_title %} - {% trans "Upload" as modal_button %} - {% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk as modal_action %} - {% include "base_modal.html" with modal_id="uploadParentalAuthorization" modal_enctype="multipart/form-data" %} + {% trans "Upload parental authorization" as modal_title %} + {% trans "Upload" as modal_button %} + {% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk as modal_action %} + {% include "base_modal.html" with modal_id="uploadParentalAuthorization" modal_enctype="multipart/form-data" %} + + {% trans "Upload parental authorization" as modal_title %} + {% trans "Upload" as modal_button %} + {% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk as modal_action %} + {% include "base_modal.html" with modal_id="uploadParentalAuthorization" modal_enctype="multipart/form-data" %} + {% endif %} + + {% if user_object.registration.team.participation.valid %} + {% trans "Update payment" as modal_title %} + {% trans "Update" as modal_button %} + {% url "registration:update_payment" pk=user_object.registration.payment.pk as modal_action %} + {% include "base_modal.html" with modal_id="updatePayment" modal_additional_class="modal-xl" modal_enctype="multipart/form-data" %} + {% endif %} {% endblock %} {% block extrajavascript %} @@ -169,21 +188,30 @@ if (!modalBody.html().trim()) modalBody.load("{% url "registration:update_user" pk=user_object.pk %} #form-content"); }); - $('button[data-target="#uploadPhotoAuthorizationModal"]').click(function() { - let modalBody = $("#uploadPhotoAuthorizationModal div.modal-body"); - if (!modalBody.html().trim()) - modalBody.load("{% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk %} #form-content"); - }); - $('button[data-target="#uploadHealthSheetModal"]').click(function() { - let modalBody = $("#uploadHealthSheetModal div.modal-body"); - if (!modalBody.html().trim()) - modalBody.load("{% url "registration:upload_user_health_sheet" pk=user_object.registration.pk %} #form-content"); - }); - $('button[data-target="#uploadParentalAuthorizationModal"]').click(function() { - let modalBody = $("#uploadParentalAuthorizationModal div.modal-body"); - if (!modalBody.html().trim()) - modalBody.load("{% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk %} #form-content"); - }); + {% if user_object.registration.team and not user_object.registration.team.participation.valid %} + $('button[data-target="#uploadPhotoAuthorizationModal"]').click(function() { + let modalBody = $("#uploadPhotoAuthorizationModal div.modal-body"); + if (!modalBody.html().trim()) + modalBody.load("{% url "registration:upload_user_photo_authorization" pk=user_object.registration.pk %} #form-content"); + }); + $('button[data-target="#uploadHealthSheetModal"]').click(function() { + let modalBody = $("#uploadHealthSheetModal div.modal-body"); + if (!modalBody.html().trim()) + modalBody.load("{% url "registration:upload_user_health_sheet" pk=user_object.registration.pk %} #form-content"); + }); + $('button[data-target="#uploadParentalAuthorizationModal"]').click(function() { + let modalBody = $("#uploadParentalAuthorizationModal div.modal-body"); + if (!modalBody.html().trim()) + modalBody.load("{% url "registration:upload_user_parental_authorization" pk=user_object.registration.pk %} #form-content"); + }); + {% endif %} + {% if user_object.registration.team.participation.valid %} + $('button[data-target="#updatePaymentModal"]').click(function() { + let modalBody = $("#updatePaymentModal div.modal-body"); + if (!modalBody.html().trim()) + modalBody.load("{% url "registration:update_payment" pk=user_object.registration.payment.pk %} #form-content"); + }); + {% endif %} }); {% endblock %} diff --git a/apps/registration/urls.py b/apps/registration/urls.py index 663efa9..e6ec201 100644 --- a/apps/registration/urls.py +++ b/apps/registration/urls.py @@ -3,10 +3,10 @@ from django.urls import path -from .views import AddOrganizerView, MyAccountDetailView, ResetAdminView, SignupView, UserDetailView,\ - UserImpersonateView, UserListView, UserResendValidationEmailView, UserUpdateView, UserUploadHealthSheetView, \ - UserUploadParentalAuthorizationView, UserUploadPhotoAuthorizationView, UserValidateView, \ - UserValidationEmailSentView +from .views import AddOrganizerView, MyAccountDetailView, PaymentUpdateView, ResetAdminView, SignupView, \ + UserDetailView, UserImpersonateView, UserListView, UserResendValidationEmailView, UserUpdateView, \ + UserUploadHealthSheetView, UserUploadParentalAuthorizationView, UserUploadPhotoAuthorizationView, \ + UserValidateView, UserValidationEmailSentView app_name = "registration" @@ -26,6 +26,7 @@ urlpatterns = [ name="upload_user_health_sheet"), path("user/