Skip to content

Commit

Permalink
feat: ajout d'une balise youtube dans le markdown (#810)
Browse files Browse the repository at this point in the history
## Description

🎸 Permettre l'ajout d'une video Youtube en iframe, en utilisant une
balise de style markdown `[youtube:12345abc]`

## Type de changement

🎢 Nouvelle fonctionnalité (changement non cassant qui ajoute une
fonctionnalité).
🚧 technique

### Points d'attention

🦺 rationalisation des rendus de champs markdown via le gabarit
`partials/rendered_md.html`
🦺 rationalisation des vues `TopicContentView` et
`TopicCertifiedPostView` en utilisant directement le nouveau gabarit
🦺 suppression du gabarit `post_preview.html` (code mort)
  • Loading branch information
vincentporte authored Nov 14, 2024
1 parent 64e04a3 commit adbff17
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 148 deletions.
2 changes: 0 additions & 2 deletions lacommunaute/forum/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from lacommunaute.forum.models import Forum
from lacommunaute.partner.models import Partner
from lacommunaute.utils.html import wrap_iframe_in_div_tag


class ForumForm(forms.ModelForm):
Expand Down Expand Up @@ -45,7 +44,6 @@ def __init__(self, *args, **kwargs):

def save(self, commit=True):
forum = super().save(commit=False)
forum.description = wrap_iframe_in_div_tag(self.cleaned_data.get("description"))

if commit:
forum.save()
Expand Down
8 changes: 7 additions & 1 deletion lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@

<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><p>Test description</p></article>
<article class="textarea_cms_md">


<p>Test description</p>


</article>
</div>
</div>

Expand Down
17 changes: 0 additions & 17 deletions lacommunaute/forum/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
from lacommunaute.forum.models import Forum


def test_saved_forum_description(db):
form = ForumForm(
data={
"name": "test",
"short_description": "test",
"description": "Text\n<iframe src='xxx'></iframe>\ntext\n<div><iframe src='yyy'></iframe></div>\nbye",
}
)
assert form.is_valid()
form.instance.type = Forum.FORUM_POST
forum = form.save()
assert forum.description.rendered == (
"<p>Text</p>\n\n<div><iframe src='xxx'></iframe></div>\n\n"
"<p>text</p>\n\n<div><iframe src='yyy'></iframe></div>\n\n<p>bye</p>"
)


def test_form_field():
form = ForumForm()
assert form.Meta.model == Forum
Expand Down
10 changes: 7 additions & 3 deletions lacommunaute/forum_conversation/views_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class TopicContentView(PermissionRequiredMixin, View):
template = "forum_conversation/partials/topic_content.html"
template = "partials/rendered_md.html"
permission_required = [
"can_read_forum",
]
Expand All @@ -32,6 +32,9 @@ def get_topic(self):
)
return self.topic

def get_content(self):
return self.get_topic().first_post.content

def get(self, request, **kwargs):
topic = self.get_topic()

Expand All @@ -40,15 +43,16 @@ def get(self, request, **kwargs):
return render(
request,
self.template,
context={"topic": topic},
context={"content": self.get_content()},
)

def get_controlled_object(self):
return self.get_topic().forum


class TopicCertifiedPostView(TopicContentView):
template = "forum_conversation/partials/topic_certified_post.html"
def get_content(self):
return self.get_topic().certified_post.post.content


class PostListView(PermissionRequiredMixin, View):
Expand Down
10 changes: 0 additions & 10 deletions lacommunaute/partner/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.conf import settings

from lacommunaute.partner.models import Partner
from lacommunaute.utils.html import wrap_iframe_in_div_tag


class PartnerForm(forms.ModelForm):
Expand All @@ -12,15 +11,6 @@ class PartnerForm(forms.ModelForm):
widget=forms.FileInput(attrs={"accept": settings.SUPPORTED_IMAGE_FILE_TYPES.keys()}),
)

def save(self, commit=True):
partner = super().save(commit=False)
partner.description = wrap_iframe_in_div_tag(self.cleaned_data.get("description"))

if commit:
partner.save()

return partner

class Meta:
model = Partner
fields = ("name", "short_description", "description", "logo", "url")
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><h3>h3 long MD description</h3>
<article class="textarea_cms_md">


<h3>h3 long MD description</h3>

<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>


<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>
</article>

<div class="mt-3">
<a class="has-external-link" href="https://www.best-partner-ever.com" rel="noopener noreferrer" target="_blank">https://www.best-partner-ever.com</a>
Expand Down Expand Up @@ -103,9 +109,15 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><h3>h3 long MD description</h3>
<article class="textarea_cms_md">


<h3>h3 long MD description</h3>

<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>


<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>
</article>

<div class="mt-3">
<a class="has-external-link" href="https://www.best-partner-ever.com" rel="noopener noreferrer" target="_blank">https://www.best-partner-ever.com</a>
Expand Down Expand Up @@ -163,9 +175,15 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><h3>h3 long MD description</h3>
<article class="textarea_cms_md">


<h3>h3 long MD description</h3>

<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>


<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>
</article>

<div class="mt-3">
<a class="has-external-link" href="https://www.best-partner-ever.com" rel="noopener noreferrer" target="_blank">https://www.best-partner-ever.com</a>
Expand Down Expand Up @@ -223,9 +241,15 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md"><h3>h3 long MD description</h3>
<article class="textarea_cms_md">


<h3>h3 long MD description</h3>

<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>


<p>lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>
</article>

<div class="mt-3">
<a class="has-external-link" href="https://www.best-partner-ever.com" rel="noopener noreferrer" target="_blank">https://www.best-partner-ever.com</a>
Expand Down
16 changes: 0 additions & 16 deletions lacommunaute/partner/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
from lacommunaute.partner.models import Partner


def test_saved_partner_description(db):
form = PartnerForm(
data={
"name": "test",
"short_description": "test",
"description": "Text\n<iframe src='xxx'></iframe>\ntext\n<div><iframe src='yyy'></iframe></div>\nbye",
}
)
assert form.is_valid()
partner = form.save()
assert partner.description.rendered == (
"<p>Text</p>\n\n<div><iframe src='xxx'></iframe></div>\n\n"
"<p>text</p>\n\n<div><iframe src='yyy'></iframe></div>\n\n<p>bye</p>"
)


def test_form_field():
form = PartnerForm()
assert form.Meta.model == Partner
Expand Down
4 changes: 2 additions & 2 deletions lacommunaute/partner/tests/tests_partner_createview.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def test_post_partner(client, db, url, superuser):
data = {
"name": "Test",
"short_description": "Short description",
"description": "# Titre\n<iframe src='https://www.example.com'></iframe>",
"description": "# Titre\ntext",
"url": "https://www.example.com",
}
response = client.post(url, data)
assert response.status_code == 302

partner = Partner.objects.get()
assert response.url == reverse("partner:detail", kwargs={"pk": partner.pk, "slug": partner.slug})
assert partner.description.raw == "# Titre\n<div><iframe src='https://www.example.com'></iframe></div>"
assert partner.description.raw == "# Titre\ntext"
5 changes: 3 additions & 2 deletions lacommunaute/templates/forum/forum_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{% load forum_conversation_tags %}
{% load forum_permission_tags %}
{% load forum_tracking_tags %}
{% load str_filters %}
{% block title %}{{ forum.name }}{{ block.super }}{% endblock %}
{% block meta_description %}
{{ forum.short_description }}
Expand Down Expand Up @@ -34,7 +33,9 @@ <h1>{{ forum.name }}</h1>
{% if forum.description %}
<div class="s-section__row row">
<div class="col-12">
<article class="textarea_cms_md">{{ forum.description.rendered|urlizetrunc_target_blank:30|img_fluid }}</article>
<article class="textarea_cms_md">
{% include 'partials/rendered_md.html' with content=forum.description only %}
</article>
</div>
</div>
{% endif %}
Expand Down
5 changes: 3 additions & 2 deletions lacommunaute/templates/forum/forum_documentation.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends "forum/forum_detail.html" %}
{% load i18n %}
{% load str_filters %}
{% block forum_head_content %}
<div class="s-section__row row">
<div class="col-12 col-lg-9">
Expand All @@ -27,7 +26,9 @@
</div>
{% endif %}
<div class="col-12 col-sm-auto mt-3">
<article class="textarea_cms_md">{{ forum.description.rendered|urlizetrunc_target_blank:30|img_fluid }}</article>
<article class="textarea_cms_md">
{% include 'partials/rendered_md.html' with content=forum.description only %}
</article>
</div>
{% if forum.partner %}
<div class="col-12 col-sm-auto mt-3" id="partner_area">
Expand Down
5 changes: 3 additions & 2 deletions lacommunaute/templates/forum/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% load i18n %}
{% load mptt_tags %}
{% load forum_tags %}
{% load str_filters %}
{% block title %}
{% trans "Index" %}{{ block.super }}
{% endblock %}
Expand All @@ -27,7 +26,9 @@ <h3 class="h3 mb-0">
</div>
</div>
<div class="card-body pt-0">
{% if node.obj.description.rendered %}{{ node.obj.description.rendered|urlizetrunc_target_blank:30 }}{% endif %}
{% if node.obj.description.rendered %}
{% include 'partials/rendered_md.html' with content=node.obj.description only %}
{% endif %}
{% if node.children %}
<a data-bs-toggle="collapse" href="#collapse{{ node.obj.id }}" role="button" aria-expanded="false" aria-controls="collapse{{ node.obj.id }}" class="btn btn-link pt-0 ps-0">
{% if node.obj.is_forum %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load i18n %}
{% load forum_member_tags %}
{% load forum_permission_tags %}
{% load str_filters %}
{% if post %}
<div class="card post my-3 bg-communaute-lighter border-communaute has-links-inside ms-3">
<div class="card-body">
Expand All @@ -12,7 +11,7 @@
<div>{% include "forum_conversation/partials/post_certified_badge.html" %}</div>
</div>
<div class="post-content" id="showmorecertifiedpostsarea{{ topic.pk }}">
{{ post.content.rendered|urlizetrunc_target_blank:30|img_fluid|truncatechars_html:200 }}
{% include 'partials/rendered_md.html' with content=post.content truncatechars=1 only %}
{% if post.content.rendered|length > 200 %}
<a hx-get="{% url 'forum_conversation_extension:showmore_certified' topic.forum.slug topic.forum.pk topic.slug topic.pk %}"
id="showmorecertified-button{{ topic.pk }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load i18n %}
{% load forum_member_tags %}
{% load forum_permission_tags %}
{% load str_filters %}
{% get_permission 'can_download_files' topic.forum request.user as user_can_download_files %}
<div class="card post my-3 bg-light has-links-inside ms-3">
<div class="card-body">
Expand All @@ -14,7 +13,7 @@
{% include "partials/upvotes.html" with obj=post kind="post" %}
</div>
<div class="post-content">
{{ post.content.rendered|urlizetrunc_target_blank:30|img_fluid }}
{% include 'partials/rendered_md.html' with content=post.content only %}
{% include "forum_conversation/forum_attachments/attachments_images.html" %}
</div>
{% include "forum_conversation/forum_attachments/attachments_detail.html" with post=post user_can_download_files=user_can_download_files %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load i18n %}
{% load forum_member_tags %}
{% load forum_permission_tags %}
{% load str_filters %}
{% get_permission 'can_download_files' topic.forum request.user as user_can_download_files %}
<div id="showmorepostsarea{{ topic.pk }}">
{% for post in posts %}
Expand All @@ -20,7 +19,7 @@
</div>
</div>
<div class="post-content">
{{ post.content.rendered|urlizetrunc_target_blank:30|img_fluid }}
{% include 'partials/rendered_md.html' with content=post.content only %}
{% include "forum_conversation/forum_attachments/attachments_images.html" %}
</div>
{% include "forum_conversation/forum_attachments/attachments_detail.html" with post=post user_can_download_files=user_can_download_files %}
Expand Down

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions lacommunaute/templates/forum_conversation/post_preview.html

This file was deleted.

3 changes: 1 addition & 2 deletions lacommunaute/templates/forum_conversation/topic_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% load i18n %}
{% load forum_conversation_tags %}
{% load forum_permission_tags %}
{% load str_filters %}
{% block title %}{{ topic.subject }} ({{ topic.forum.name }}){% endblock %}
{% block meta_description %}
{{ topic.first_post.content.raw }}
Expand Down Expand Up @@ -36,7 +35,7 @@ <h1>{{ topic.subject }}</h1>
<div class="card-body pt-0">
<div class="row">
<div class="col-12 post-content mb-3">
{{ post.content.rendered|urlizetrunc_target_blank:30|img_fluid }}
{% include 'partials/rendered_md.html' with content=post.content only %}
{% include "forum_conversation/forum_attachments/attachments_images.html" %}
</div>
<div class="col-12 post-content-wrapper">
Expand Down
3 changes: 1 addition & 2 deletions lacommunaute/templates/forum_conversation/topic_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
{% load forum_member_tags %}
{% load forum_tracking_tags %}
{% load forum_permission_tags %}
{% load str_filters %}
{% load url_add_query %}
{% if forum %}
{% get_permission 'can_download_files' forum request.user as user_can_download_files %}
Expand Down Expand Up @@ -49,7 +48,7 @@
</div>
<div class="col-12 post-content">
<div id="showmoretopicsarea{{ topic.pk }}">
{{ topic.first_post.content.rendered|urlizetrunc_target_blank:30|img_fluid|truncatechars_html:200 }}
{% include 'partials/rendered_md.html' with content=topic.first_post.content truncatechars=1 only %}
{% if topic.first_post.content.rendered|length > 200 %}
<a hx-get="{% url 'forum_conversation_extension:showmore_topic' topic.forum.slug topic.forum.pk topic.slug topic.pk %}"
id="showmoretopic-button{{ topic.pk }}"
Expand Down
Loading

0 comments on commit adbff17

Please sign in to comment.