Skip to content

Commit

Permalink
feat(documentation): rendre la certification optionnelle (#741)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
vincentporte authored Aug 7, 2024
1 parent 32cb339 commit 6141112
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lacommunaute/forum/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion lacommunaute/forum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"]
17 changes: 17 additions & 0 deletions lacommunaute/forum/migrations/0016_forum_certified.py
Original file line number Diff line number Diff line change
@@ -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"),
),
]
1 change: 1 addition & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
20 changes: 20 additions & 0 deletions lacommunaute/forum/tests/test_forum_updateview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion lacommunaute/forum/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 20 additions & 3 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,15 @@
'''
<div class="form-group" id="div_id_content">

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>




Expand All @@ -217,13 +219,15 @@
'''
<div class="form-group" id="div_id_content">

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>

<label class="control-label" for="id_content">
Message

</label>


<textarea class="form-control" cols="40" id="id_content" name="content" placeholder="Entrez votre message" required="" rows="10"></textarea>




Expand Down
40 changes: 22 additions & 18 deletions lacommunaute/search/__snapshots__/tests.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@

<div class="form-group" id="div_id_q">

<label class="control-label" for="id_q">
Rechercher par mots clés

<span class="text-muted">(optional)</span>

</label>


<input class="form-control" id="id_q" maxlength="255" name="q" placeholder="Mots clés ou phrase" type="search"/>

<label class="control-label" for="id_q">
Rechercher par mots clés

<span class="text-muted">(optional)</span>

</label>


<input class="form-control" id="id_q" maxlength="255" name="q" placeholder="Mots clés ou phrase" type="search"/>




Expand Down Expand Up @@ -102,15 +104,17 @@

<div class="form-group" id="div_id_q">

<label class="control-label" for="id_q">
Rechercher par mots clés

<span class="text-muted">(optional)</span>

</label>


<input class="form-control" id="id_q" maxlength="255" name="q" placeholder="Mots clés ou phrase" type="search" value="Bubba Gump Shrimp Co."/>

<label class="control-label" for="id_q">
Rechercher par mots clés

<span class="text-muted">(optional)</span>

</label>


<input class="form-control" id="id_q" maxlength="255" name="q" placeholder="Mots clés ou phrase" type="search" value="Bubba Gump Shrimp Co."/>




Expand Down
14 changes: 9 additions & 5 deletions lacommunaute/templates/forum/forum_documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
<div class="s-section__row row">
<div class="col-12 col-lg-9">
<div class="row align-items-sm-center mb-3">
<div class="col-12 col-sm">
<span class="badge badge-xs rounded-pill bg-communaute text-white text-decoration-none">
<i class="ri-checkbox-circle-fill"></i>
Certifié par la Plateforme de l'Inclusion le {{ forum.updated|date:"d/m/Y" }}
</span>
<div class="col-12 col-sm" id="updated_area">
{% if forum.certified %}
<span class="badge badge-xs rounded-pill bg-communaute text-white text-decoration-none">
<i class="ri-checkbox-circle-fill"></i>
Certifiée par la communauté de l'inclusion le {{ forum.updated|date:"d/m/Y" }}
</span>
{% else %}
<span class="fs-sm">Fiche mise à jour le {{ forum.updated|date:"d/m/Y" }}</span>
{% endif %}
</div>
<div class="col-12 col-sm-auto">
{% include "partials/upvotes.html" with obj=forum kind="forum" %}
Expand Down
1 change: 1 addition & 0 deletions lacommunaute/templates/forum/partials/forum_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<hr class="mb-5">
<div class="form-actions form-row">
<div class="form-group col-auto">
Expand Down
40 changes: 22 additions & 18 deletions lacommunaute/templates/partials/form_field.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{% load i18n %}
{% load widget_tweaks %}
<div id="div_id_{{ field.html_name }}" class="form-group{% if field.errors %} has-error{% endif %}">
{% if field.label %}
<label class="control-label" for="{{ field.auto_id }}">
{{ field.label }}
{% if not field.field.required %}
<span class="text-muted">{% trans "(optional)" %}</span>
{% endif %}
</label>
{% endif %}
{% if field|widget_type == "checkboxselectmultiple" %}
{% for checkbox in field %}
<div class="form-check form-check-inline">
<input id="{{ checkbox.id_for_label }}" class="form-check-input" type="checkbox" name="{{ checkbox.data.name }}" value="{{ checkbox.data.value }}" {% if checkbox.data.selected %}checked=""{% endif %}>
<label class="form-check-label badge badge-sm rounded-pill bg-info-lighter text-info" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
{% if field|widget_type == "checkboxinput" %}
<div class="checkbox">{{ field }} {{ field.label }}</div>
{% else %}
{{ field | add_class:'form-control' }}
{% if field.label %}
<label class="control-label" for="{{ field.auto_id }}">
{{ field.label }}
{% if not field.field.required %}
<span class="text-muted">{% trans "(optional)" %}</span>
{% endif %}
</label>
{% endif %}
{% if field|widget_type == "checkboxselectmultiple" %}
{% for checkbox in field %}
<div class="form-check form-check-inline">
<input id="{{ checkbox.id_for_label }}" class="form-check-input" type="checkbox" name="{{ checkbox.data.name }}" value="{{ checkbox.data.value }}" {% if checkbox.data.selected %}checked=""{% endif %}>
<label class="form-check-label badge badge-sm rounded-pill bg-info-lighter text-info" for="{{ checkbox.id_for_label }}">
{{ checkbox.choice_label }}
</label>
</div>
{% endfor %}
{% else %}
{{ field|add_class:'form-control' }}
{% endif %}
{% endif %}
{% if field.help_text %}<small class="form-text text-muted">{{ field.help_text }}</small>{% endif %}
{% for error in field.errors %}<span class="text-danger error">{{ error }}</span>{% endfor %}
Expand Down

0 comments on commit 6141112

Please sign in to comment.