1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-24 17:40:32 +02:00

Setup payment interface

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2024-02-18 22:36:01 +01:00
parent 7c9083a6b8
commit 4d157b2bd7
8 changed files with 366 additions and 131 deletions

View File

@ -219,7 +219,7 @@ class VolunteerRegistrationForm(forms.ModelForm):
fields = ('professional_activity', 'admin', 'give_contact_to_animath', 'email_confirmed',)
class PaymentForm(forms.ModelForm):
class PaymentAdminForm(forms.ModelForm):
"""
Indicate payment information
"""
@ -228,7 +228,6 @@ class PaymentForm(forms.ModelForm):
self.fields["valid"].widget.choices[0] = ('unknown', _("Pending"))
def clean_receipt(self):
print(self.files)
if "receipt" in self.files:
file = self.files["receipt"]
if file.size > 2e6:
@ -241,7 +240,7 @@ class PaymentForm(forms.ModelForm):
cleaned_data = super().clean()
if "type" in cleaned_data and cleaned_data['type'] in ["scholarship", "bank_transfer"] \
and "receipt" not in self.files and not self.instance.scholarship_file:
and "receipt" not in self.files and not self.instance.receipt:
self.add_error("receipt", _("You must upload your receipt."))
return cleaned_data
@ -249,3 +248,37 @@ class PaymentForm(forms.ModelForm):
class Meta:
model = Payment
fields = ('type', 'receipt', 'additional_information', 'valid',)
class PaymentForm(forms.ModelForm):
"""
Indicate payment information
"""
def __init__(self, payment_type, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['type'].widget = forms.HiddenInput(attrs={'value': payment_type})
self.fields['receipt'].required = payment_type in ["scholarship", "bank_transfer"]
self.fields['additional_information'].required = payment_type in ["other"]
def clean_receipt(self):
if "receipt" in self.files:
file = self.files["receipt"]
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["receipt"]
def clean(self):
cleaned_data = super().clean()
if "type" in cleaned_data and cleaned_data['type'] in ["scholarship", "bank_transfer"] \
and "receipt" not in self.files and not self.instance.receipt:
self.add_error("receipt", _("You must upload your receipt."))
return cleaned_data
class Meta:
model = Payment
fields = ('type', 'receipt', 'additional_information',)