From 61411127ba4c2bf76dccf825f7ed468260cd5fc4 Mon Sep 17 00:00:00 2001 From: Vincent Porte Date: Wed, 7 Aug 2024 10:10:35 +0200 Subject: [PATCH] feat(documentation): rendre la certification optionnelle (#741) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description 🎸 Rendre optionnelle la mention `certifiée par la communauté de l'inclusion le 17/05/2024` dans les fiches pratiques de la documentation 🎸 Si non, `Fiche mise à jour le 17/05/2024` ## Type de changement 🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une fonctionnalité). 🎨 changement d'UI ### Points d'attention 🦺 None par défaut ### Captures d'écran (optionnel) Non certifiée ![image](https://github.com/user-attachments/assets/974d189d-7b3c-4920-b789-199463df1ed4) Certifiée ![image](https://github.com/user-attachments/assets/1e926410-9297-46cc-b4bb-94d072bfc194) --- lacommunaute/forum/admin.py | 2 +- lacommunaute/forum/forms.py | 3 +- .../forum/migrations/0016_forum_certified.py | 17 ++++++++ lacommunaute/forum/models.py | 1 + .../forum/tests/test_forum_updateview.py | 20 ++++++++++ lacommunaute/forum/tests/tests_forms.py | 3 +- lacommunaute/forum/tests/tests_views.py | 23 +++++++++-- .../tests/__snapshots__/tests_views.ambr | 32 ++++++++------- lacommunaute/search/__snapshots__/tests.ambr | 40 ++++++++++--------- .../templates/forum/forum_documentation.html | 14 ++++--- .../templates/forum/partials/forum_form.html | 1 + .../templates/partials/form_field.html | 40 ++++++++++--------- 12 files changed, 135 insertions(+), 61 deletions(-) create mode 100644 lacommunaute/forum/migrations/0016_forum_certified.py diff --git a/lacommunaute/forum/admin.py b/lacommunaute/forum/admin.py index af4c8b10e..43b934f33 100644 --- a/lacommunaute/forum/admin.py +++ b/lacommunaute/forum/admin.py @@ -6,7 +6,7 @@ class ForumAdmin(BaseForumAdmin): fieldsets = BaseForumAdmin.fieldsets - fieldsets[0][1]["fields"] += ("short_description",) + fieldsets[0][1]["fields"] += ("short_description", "certified") fieldsets[1][1]["fields"] += ( "members_group", "invitation_token", diff --git a/lacommunaute/forum/forms.py b/lacommunaute/forum/forms.py index 9288370e5..9edf7ac6c 100644 --- a/lacommunaute/forum/forms.py +++ b/lacommunaute/forum/forms.py @@ -35,6 +35,7 @@ class ForumForm(forms.ModelForm): label="Banniere de couverture, format 1200 x 630 pixels recommandé", widget=forms.FileInput(attrs={"accept": settings.SUPPORTED_IMAGE_FILE_TYPES.keys()}), ) + certified = forms.BooleanField(required=False, label="Certifiée par la communauté de l'inclusion") def save(self, commit=True): forum = super().save(commit=False) @@ -45,4 +46,4 @@ def save(self, commit=True): class Meta: model = Forum - fields = ["name", "short_description", "description", "image"] + fields = ["name", "short_description", "description", "image", "certified"] diff --git a/lacommunaute/forum/migrations/0016_forum_certified.py b/lacommunaute/forum/migrations/0016_forum_certified.py new file mode 100644 index 000000000..1aa9e84d8 --- /dev/null +++ b/lacommunaute/forum/migrations/0016_forum_certified.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.7 on 2024-08-06 09:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("forum", "0015_alter_forumrating_options"), + ] + + operations = [ + migrations.AddField( + model_name="forum", + name="certified", + field=models.BooleanField(default=False, verbose_name="Certifié par la communauté de l'inclusion"), + ), + ] diff --git a/lacommunaute/forum/models.py b/lacommunaute/forum/models.py index d13c21f5c..bd07c99f1 100644 --- a/lacommunaute/forum/models.py +++ b/lacommunaute/forum/models.py @@ -36,6 +36,7 @@ class Forum(AbstractForum): storage=S3Boto3Storage(bucket_name=settings.AWS_STORAGE_BUCKET_NAME, file_overwrite=False), validators=[validate_image_size], ) + certified = models.BooleanField(default=False, verbose_name="Certifié par la communauté de l'inclusion") upvotes = GenericRelation(UpVote, related_query_name="forum") diff --git a/lacommunaute/forum/tests/test_forum_updateview.py b/lacommunaute/forum/tests/test_forum_updateview.py index 465acad9d..de8edd4c0 100644 --- a/lacommunaute/forum/tests/test_forum_updateview.py +++ b/lacommunaute/forum/tests/test_forum_updateview.py @@ -77,3 +77,23 @@ def test_update_forum_image(client, db, fake_image): assert forum.short_description == "new short description" assert forum.description.raw == "new description" assert forum.image.name == fake_image.name + + +def test_certified_forum(client, db): + client.force_login(UserFactory(is_superuser=True)) + forum = CategoryForumFactory(with_child=True).get_children().first() + url = reverse("forum_extension:edit_forum", kwargs={"pk": forum.pk, "slug": forum.slug}) + + response = client.post( + url, + data={ + "name": "new name", + "short_description": "new short description", + "description": "new description", + "certified": True, + }, + ) + assert response.status_code == 302 + + forum.refresh_from_db() + assert forum.certified is True diff --git a/lacommunaute/forum/tests/tests_forms.py b/lacommunaute/forum/tests/tests_forms.py index 1b3818b05..6f0897e3c 100644 --- a/lacommunaute/forum/tests/tests_forms.py +++ b/lacommunaute/forum/tests/tests_forms.py @@ -42,8 +42,9 @@ def test_saved_forum_description(db): def test_form_field(): form = ForumForm() assert form.Meta.model == Forum - assert form.Meta.fields == ["name", "short_description", "description", "image"] + assert form.Meta.fields == ["name", "short_description", "description", "image", "certified"] assert form.fields["name"].required assert form.fields["short_description"].required assert not form.fields["description"].required assert not form.fields["image"].required + assert not form.fields["certified"].required diff --git a/lacommunaute/forum/tests/tests_views.py b/lacommunaute/forum/tests/tests_views.py index 5eb4a6aaf..8305f798d 100644 --- a/lacommunaute/forum/tests/tests_views.py +++ b/lacommunaute/forum/tests/tests_views.py @@ -1,13 +1,16 @@ -import pytest # noqa import re + +import pytest # noqa +from django.conf import settings from django.contrib.contenttypes.models import ContentType from django.template.defaultfilters import truncatechars_html from django.test import RequestFactory, TestCase from django.urls import reverse from faker import Faker from machina.core.loading import get_class +from pytest_django.asserts import assertContains from taggit.models import Tag -from django.conf import settings + from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory, ForumRatingFactory from lacommunaute.forum.models import Forum @@ -18,7 +21,7 @@ from lacommunaute.forum_conversation.models import Topic from lacommunaute.users.factories import UserFactory from lacommunaute.utils.testing import parse_response_to_soup, reset_model_sequence_fixture -from pytest_django.asserts import assertContains + faker = Faker() @@ -593,6 +596,20 @@ def test_documentation_forum_share_actions(self, client, db, snapshot, reset_for social_share_area = content.select(f"#dropdownMenuSocialShare{str(documentation_forum.pk)}")[0] assert str(social_share_area) == snapshot(name="template_documentation_social_share") + def test_documentation_certified(self, client, db, documentation_forum): + response = client.get(documentation_forum.get_absolute_url()) + content = re.findall(r"Fiche mise à jour le (\d{2}/\d{2}/\d{4})", response.content.decode()) + assert len(content) == 1 + + documentation_forum.certified = True + documentation_forum.save() + + response = client.get(documentation_forum.get_absolute_url()) + content = re.findall( + r"Certifiée par la communauté de l'inclusion le (\d{2}/\d{2}/\d{4})", response.content.decode() + ) + assert len(content) == 1 + def test_documentation_forum_header_content(self, client, db, snapshot, reset_forum_sequence, documentation_forum): sibling_forum = ForumFactory(parent=documentation_forum.parent, with_public_perms=True, name="Test-2") diff --git a/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr index 181509347..58c9da3cf 100644 --- a/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr +++ b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr @@ -184,13 +184,15 @@ '''
- - - - + + + + + + @@ -217,13 +219,15 @@ '''
- - - - + + + + + + diff --git a/lacommunaute/search/__snapshots__/tests.ambr b/lacommunaute/search/__snapshots__/tests.ambr index 0d46b8e9f..58eba0005 100644 --- a/lacommunaute/search/__snapshots__/tests.ambr +++ b/lacommunaute/search/__snapshots__/tests.ambr @@ -28,15 +28,17 @@
- - - - + + + + + + @@ -102,15 +104,17 @@
- - - - + + + + + + diff --git a/lacommunaute/templates/forum/forum_documentation.html b/lacommunaute/templates/forum/forum_documentation.html index 713165d22..da13b896b 100644 --- a/lacommunaute/templates/forum/forum_documentation.html +++ b/lacommunaute/templates/forum/forum_documentation.html @@ -5,11 +5,15 @@
-
- - - Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }} - +
+ {% if forum.certified %} + + + Certifiée par la communauté de l'inclusion le {{ forum.updated|date:"d/m/Y" }} + + {% else %} + Fiche mise à jour le {{ forum.updated|date:"d/m/Y" }} + {% endif %}
{% include "partials/upvotes.html" with obj=forum kind="forum" %} diff --git a/lacommunaute/templates/forum/partials/forum_form.html b/lacommunaute/templates/forum/partials/forum_form.html index 6ed13ac7c..572b0bb33 100644 --- a/lacommunaute/templates/forum/partials/forum_form.html +++ b/lacommunaute/templates/forum/partials/forum_form.html @@ -10,6 +10,7 @@ {% include "partials/form_field.html" with field=form.short_description %} {% include "partials/form_field.html" with field=form.description %} {% include "partials/form_field.html" with field=form.image %} + {% include "partials/form_field.html" with field=form.certified %}
diff --git a/lacommunaute/templates/partials/form_field.html b/lacommunaute/templates/partials/form_field.html index 8c0cdd8c8..81120da5c 100644 --- a/lacommunaute/templates/partials/form_field.html +++ b/lacommunaute/templates/partials/form_field.html @@ -1,25 +1,29 @@ {% load i18n %} {% load widget_tweaks %}
- {% if field.label %} - - {% endif %} - {% if field|widget_type == "checkboxselectmultiple" %} - {% for checkbox in field %} -
- - -
- {% endfor %} + {% if field|widget_type == "checkboxinput" %} +
{{ field }} {{ field.label }}
{% else %} - {{ field | add_class:'form-control' }} + {% if field.label %} + + {% endif %} + {% if field|widget_type == "checkboxselectmultiple" %} + {% for checkbox in field %} +
+ + +
+ {% endfor %} + {% else %} + {{ field|add_class:'form-control' }} + {% endif %} {% endif %} {% if field.help_text %}{{ field.help_text }}{% endif %} {% for error in field.errors %}{{ error }}{% endfor %}