From 3c59256d59466aef1a5c07161d040232a80dd51e Mon Sep 17 00:00:00 2001 From: jessiebelle Date: Sun, 24 Dec 2023 20:31:24 +0200 Subject: [PATCH] changing imagefield to file field on sponsorupdateform and sponsorshipapplicationform. adding django file validator to these two and the sponsor model --- sponsors/forms.py | 7 +++++-- .../migrations/0099_auto_20231224_1829.py | 19 +++++++++++++++++++ sponsors/models/sponsors.py | 2 ++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 sponsors/migrations/0099_auto_20231224_1829.py diff --git a/sponsors/forms.py b/sponsors/forms.py index 8d262b337..ed59a6fbf 100644 --- a/sponsors/forms.py +++ b/sponsors/forms.py @@ -3,6 +3,7 @@ from django import forms from django.conf import settings from django.contrib.admin.widgets import AdminDateWidget +from django.core.validators import FileExtensionValidator from django.db.models import Q from django.utils import timezone from django.utils.functional import cached_property @@ -225,10 +226,11 @@ class SponsorshipApplicationForm(forms.Form): help_text="For display on our sponsor webpage. High resolution PNG or JPG, smallest dimension no less than 256px", required=False, ) - print_logo = forms.ImageField( + print_logo = forms.FileField( label="Sponsor print logo", help_text="For printed materials, signage, and projection. SVG or EPS", required=False, + validators=[FileExtensionValidator(['eps', 'epsf' 'epsi', 'svg'])], ) primary_phone = forms.CharField( @@ -557,10 +559,11 @@ class SponsorUpdateForm(forms.ModelForm): help_text="For display on our sponsor webpage. High resolution PNG or JPG, smallest dimension no less than 256px", required=False, ) - print_logo = forms.ImageField( + print_logo = forms.FileField( widget=forms.widgets.FileInput, help_text="For printed materials, signage, and projection. SVG or EPS", required=False, + validators=[FileExtensionValidator(['eps', 'epsf' 'epsi', 'svg'])], ) def __init__(self, *args, **kwargs): diff --git a/sponsors/migrations/0099_auto_20231224_1829.py b/sponsors/migrations/0099_auto_20231224_1829.py new file mode 100644 index 000000000..f3bb0c0db --- /dev/null +++ b/sponsors/migrations/0099_auto_20231224_1829.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.24 on 2023-12-24 18:29 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sponsors', '0098_auto_20231219_1910'), + ] + + operations = [ + migrations.AlterField( + model_name='sponsor', + name='print_logo', + field=models.FileField(blank=True, help_text='For printed materials, signage, and projection. SVG or EPS', null=True, upload_to='sponsor_print_logos', validators=[django.core.validators.FileExtensionValidator(['eps', 'epsfepsi', 'svg'])], verbose_name='Print logo'), + ), + ] diff --git a/sponsors/models/sponsors.py b/sponsors/models/sponsors.py index 9b4d8fe86..8332934c3 100644 --- a/sponsors/models/sponsors.py +++ b/sponsors/models/sponsors.py @@ -3,6 +3,7 @@ """ from allauth.account.models import EmailAddress from django.conf import settings +from django.core.validators import FileExtensionValidator from django.db import models from django.core.exceptions import ObjectDoesNotExist from django.template.defaultfilters import slugify @@ -51,6 +52,7 @@ class Sponsor(ContentManageable): ) print_logo = models.FileField( upload_to="sponsor_print_logos", + validators=[FileExtensionValidator(['eps', 'epsf' 'epsi', 'svg'])], blank=True, null=True, verbose_name="Print logo",