1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-07-05 04:24:04 +02:00

It is possible to validate payment status

This commit is contained in:
Yohann D'ANELLO
2021-01-18 20:02:49 +01:00
parent 53a55ee898
commit 4cd1e43564
6 changed files with 140 additions and 39 deletions

View File

@ -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',)