feat: upload file in contact form

This commit is contained in:
mohamad
2026-06-07 17:09:04 +03:30
parent 76185c7434
commit cbc49cd8ae
11 changed files with 536 additions and 6 deletions
+17
View File
@@ -1,9 +1,13 @@
from django import forms
from django.core.exceptions import ValidationError
from .contact_uploads import validate_contact_attachments
from .models import ContactSubmission
class ContactForm(forms.ModelForm):
attachments = forms.Field(required=False)
class Meta:
model = ContactSubmission
fields = ["name", "title", "description", "email"]
@@ -22,3 +26,16 @@ class ContactForm(forms.ModelForm):
}
),
}
def __init__(self, *args, file_list=None, **kwargs):
self.file_list = file_list
super().__init__(*args, **kwargs)
def clean(self):
cleaned_data = super().clean()
try:
cleaned_data["attachments"] = validate_contact_attachments(self.file_list)
except ValidationError as exc:
self.add_error("attachments", exc)
cleaned_data["attachments"] = []
return cleaned_data