diff --git a/config/settings/base.py b/config/settings/base.py index 9b151e0b0..adba814a7 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -333,6 +333,7 @@ "machina.core.markdown.markdown", {"safe_mode": False, "extras": {"break-on-newline": True, "code-friendly": True, "nofollow": True}}, ) +SUPPORTED_IMAGE_FILE_TYPES = {"image/png": "png", "image/jpeg": "jpeg", "image/jpg": "jpg", "image/gif": "gif"} # Django sites framework SITE_ID = 1 diff --git a/lacommunaute/forum/forms.py b/lacommunaute/forum/forms.py index d02288980..9288370e5 100644 --- a/lacommunaute/forum/forms.py +++ b/lacommunaute/forum/forms.py @@ -1,6 +1,7 @@ import re from django import forms +from django.conf import settings from lacommunaute.forum.models import Forum @@ -29,7 +30,11 @@ class ForumForm(forms.ModelForm): description = forms.CharField( widget=forms.Textarea(attrs={"rows": 20}), required=False, label="Contenu (markdown autorisé)" ) - image = forms.ImageField(required=False, label="Banniere de couverture, format 1200 x 630 pixels recommandé") + image = forms.ImageField( + required=False, + label="Banniere de couverture, format 1200 x 630 pixels recommandé", + widget=forms.FileInput(attrs={"accept": settings.SUPPORTED_IMAGE_FILE_TYPES.keys()}), + ) def save(self, commit=True): forum = super().save(commit=False) diff --git a/lacommunaute/forum/tests/test_forum_updateview.py b/lacommunaute/forum/tests/test_forum_updateview.py index aeb757e97..465acad9d 100644 --- a/lacommunaute/forum/tests/test_forum_updateview.py +++ b/lacommunaute/forum/tests/test_forum_updateview.py @@ -14,7 +14,7 @@ @pytest.fixture def fake_image(): fake = Faker() - image_name = fake.pystr(min_chars=30, max_chars=40, prefix="pytest_", suffix=".png") + image_name = fake.pystr(min_chars=30, max_chars=40, prefix="pytest_", suffix=".jpg") image = Image.new("RGB", (100, 100)) image_file = BytesIO()