Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forum): attr accept définit sur forms.ImageField #734

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
image = forms.ImageField(
required=False,
label="Banniere de couverture",
widget=forms.FileInput(attrs={"accept": settings.SUPPORTED_IMAGE_FILE_TYPES.keys()}),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention qu'on accepte toujours les autres fichiers acceptés par ImageField (TIFF, WEBP), je n'ai pas ajouté une contrainte sur la base de données. Si on décide que c'est une contrainte forte, on pourrait en ajouter

Je n'ai pas enquêter s'il y a des images obscures sur prod qui on aurait besoin de transformer


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
Loading