mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 07:02:10 +01:00 
			
		
		
		
	Restructure payment model
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
		@@ -227,25 +227,25 @@ class PaymentForm(forms.ModelForm):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
        self.fields["valid"].widget.choices[0] = ('unknown', _("Pending"))
 | 
			
		||||
 | 
			
		||||
    def clean_scholarship_file(self):
 | 
			
		||||
    def clean_receipt(self):
 | 
			
		||||
        print(self.files)
 | 
			
		||||
        if "scholarship_file" in self.files:
 | 
			
		||||
            file = self.files["scholarship_file"]
 | 
			
		||||
        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["scholarship_file"]
 | 
			
		||||
            return self.cleaned_data["receipt"]
 | 
			
		||||
 | 
			
		||||
    def clean(self):
 | 
			
		||||
        cleaned_data = super().clean()
 | 
			
		||||
 | 
			
		||||
        if "type" in cleaned_data and cleaned_data["type"] == "scholarship" \
 | 
			
		||||
                and "scholarship_file" not in self.files and not self.instance.scholarship_file:
 | 
			
		||||
            self.add_error("scholarship_file", _("You must upload your scholarship attestation."))
 | 
			
		||||
        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:
 | 
			
		||||
            self.add_error("receipt", _("You must upload your receipt."))
 | 
			
		||||
 | 
			
		||||
        return cleaned_data
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Payment
 | 
			
		||||
        fields = ('type', 'scholarship_file', 'additional_information', 'valid',)
 | 
			
		||||
        fields = ('type', 'receipt', 'additional_information', 'valid',)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user