diff --git a/fet2020/finance/forms.py b/fet2020/finance/forms.py index 6e7aa35c..30ac2dcf 100644 --- a/fet2020/finance/forms.py +++ b/fet2020/finance/forms.py @@ -103,7 +103,7 @@ class BillCreateForm(forms.ModelForm): "affiliation": "Abrechnungsbudget", "payer": "Ursprüngliche Bezahlmethode", "only_digital": "Ich habe nur eine digitale Rechnung.", - "file_field": "Rechnung hochladen (PDF)", + "file_field": "Rechnung hochladen (PDF- und Bildformate erlaubt)", "comment": "Kommentar", } @@ -194,7 +194,7 @@ class BillUpdateForm(forms.ModelForm): "affiliation": "Abrechnungsbudget", "payer": "Wie wurde die Rechnung bezahlt?", "only_digital": "Ich habe nur eine digitale Rechnung.", - "file_field": "Neue Rechnung hochladen (PDF)", + "file_field": "Neue Rechnung hochladen (PDF- und Bildformate erlaubt)", "comment": "Kommentar", } @@ -556,7 +556,7 @@ class BillAdminForm(forms.ModelForm): "amount": "Betrag (EUR)", "comment": "Kommentar", "date": "Rechnungsdatum", - "file_field": "Rechnung hochladen (PDF)", + "file_field": "Rechnung hochladen (PDF- und Bildformate erlaubt)", "invoice": "Rechnungsaussteller", "only_digital": "Ich habe nur eine digitale Rechnung.", "payer": "Wie wurde die Rechnung bezahlt?", diff --git a/fet2020/finance/models.py b/fet2020/finance/models.py index 3e30bf68..a48b304f 100644 --- a/fet2020/finance/models.py +++ b/fet2020/finance/models.py @@ -6,6 +6,8 @@ from django.urls import reverse from members.models import Member +from .validators import validate_bill_file_extension + class BankData(models.Model): # members can be deleted but never their bank datas @@ -246,7 +248,7 @@ class Bill(models.Model): file_field = models.FileField( upload_to="uploads/finance/bills/", - validators=[FileExtensionValidator(["pdf"])], + validators=[validate_bill_file_extension], blank=True, null=True, ) diff --git a/fet2020/finance/validators.py b/fet2020/finance/validators.py new file mode 100644 index 00000000..4491fe4f --- /dev/null +++ b/fet2020/finance/validators.py @@ -0,0 +1,5 @@ +from django.core.validators import FileExtensionValidator, get_available_image_extensions + + +def validate_bill_file_extension(value): + return FileExtensionValidator([*["pdf"], *get_available_image_extensions()])(value)