Skip to content

Commit

Permalink
feat(forum): attr accept définit sur forms.ImageField (#734)
Browse files Browse the repository at this point in the history
## Description

🎸 Ajouté une définition des formats d'image acceptés (encouragés) sur
les thématiques
🎸 Ajouté un champ dans le settings du projet pour clarifier les formats
d'image soutenu. J'ai choisis les formats d'image qui sont [soutenu par
le plupart des navigateurs
mondiales](https://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support)

## Type de changement

🎨 changement d'UI

### Points d'attention

🦺 J'ai inclus GIF 😁

---------

Co-authored-by: vincent porte <[email protected]>
  • Loading branch information
calummackervoy and vincentporte committed Aug 5, 2024
1 parent 616c0aa commit 0e8b8c9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lacommunaute/forum/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re

from django import forms
from django.conf import settings

from lacommunaute.forum.models import Forum

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/forum/tests/test_forum_updateview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0e8b8c9

Please sign in to comment.