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

[FORUM] partager la documentation sur les réseaux sociaux #350

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions lacommunaute/forum/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ def with_public_perms(self, create, extracted, **kwargs):
for permission in ForumPermission.objects.filter(codename__in=perms)
]
UserForumPermission.objects.bulk_create(anonymous_authorized_perms + authentified_authorized_perms)


class CategoryForumFactory(ForumFactory):
type = Forum.FORUM_CAT

@factory.post_generation
def with_child(self, create, extracted, **kwargs):
if not create or not extracted:
return

ForumFactory(parent=self, with_public_perms=True)
10 changes: 10 additions & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib.auth.models import Group
from django.db import models
from django.urls import reverse
from django.utils.functional import cached_property
from machina.apps.forum.abstract_models import AbstractForum

Expand All @@ -28,6 +29,15 @@ class Forum(AbstractForum):

objects = ForumQuerySet().as_manager()

def get_absolute_url(self):
return reverse(
"forum_extension:forum",
kwargs={
"pk": self.pk,
"slug": self.slug,
},
)

def get_unanswered_topics(self):
return Topic.objects.unanswered().filter(forum__in=self.get_descendants(include_self=True))

Expand Down
19 changes: 7 additions & 12 deletions lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
from django.db import IntegrityError
from django.test import TestCase
from faker import Faker
from machina.core.db.models import get_model
from machina.core.loading import get_class

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.forum_conversation.factories import TopicFactory


faker = Faker()

ForumPermission = get_model("forum_permission", "ForumPermission")
UserForumPermission = get_model("forum_permission", "UserForumPermission")
PermissionHandler = get_class("forum_permission.handler", "PermissionHandler")
assign_perm = get_class("forum_permission.shortcuts", "assign_perm")
remove_perm = get_class("forum_permission.shortcuts", "remove_perm")


class ForumManagerTest(TestCase):
def test_public_method(self):
forum = ForumFactory(kind=ForumKind.PUBLIC_FORUM)
Expand Down Expand Up @@ -55,3 +43,10 @@ def test_kind(self):
Forum.kind.field.flatchoices,
[("PUBLIC_FORUM", "Espace public"), ("PRIVATE_FORUM", "Espace privé"), ("NEWS", "Actualités")],
)

def test_get_absolute_url(self):
forum = ForumFactory()
self.assertEqual(
forum.get_absolute_url(),
f"/forum/{forum.slug}-{forum.pk}/",
)
29 changes: 19 additions & 10 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from faker import Faker
from machina.core.loading import get_class

from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory
from lacommunaute.forum.views import ForumView
from lacommunaute.forum_conversation.factories import PostFactory, TopicFactory
from lacommunaute.forum_conversation.forms import PostForm
Expand Down Expand Up @@ -319,11 +318,11 @@ def test_description_is_markdown_rendered(self):
self.assertContains(response, "<h1>title</h1>")

def test_descendants_are_in_cards_if_forum_is_category_type(self):
self.forum.type = Forum.FORUM_CAT
self.forum.save()
child_forum = ForumFactory(parent=self.forum, with_public_perms=True)
forum = CategoryForumFactory(with_public_perms=True, with_child=True)
child_forum = forum.get_children().first()
url = reverse("forum_extension:forum", kwargs={"pk": forum.pk, "slug": forum.slug})

response = self.client.get(self.url)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertContains(response, '<div class="card-body')
Expand All @@ -333,18 +332,28 @@ def test_descendants_are_in_cards_if_forum_is_category_type(self):
)

def test_siblings_in_context(self):
self.forum.type = Forum.FORUM_CAT
self.forum.save()
child_forum = ForumFactory(parent=self.forum, with_public_perms=True)
forum = CategoryForumFactory(with_public_perms=True, with_child=True)
child_forum = forum.get_children().first()
url = reverse("forum_extension:forum", kwargs={"pk": child_forum.pk, "slug": child_forum.slug})

response = self.client.get(url)
self.assertEqual(response.status_code, 200)

self.assertEqual(response.context_data["forums"].get(), child_forum)
self.assertEqual(response.context_data["parent_forum"], self.forum)
self.assertEqual(response.context_data["parent_forum"], forum)

def test_next_url_in_context(self):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context_data["next_url"], self.url)

def test_share_buttons(self):
forum = CategoryForumFactory(with_public_perms=True, with_child=True)
child_forum = forum.get_children().first()
url = reverse("forum_extension:forum", kwargs={"pk": child_forum.pk, "slug": child_forum.slug})

response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(
response, 'div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuSocialShare">'
)
16 changes: 15 additions & 1 deletion lacommunaute/templates/forum/forum_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,22 @@ <h2 class="mt-3">
{% if forums %}
<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 badge-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>
</div>
{{forum.description.rendered|urlizetrunc_target_blank:30}}
<small>dernière mise à jour le : {{ forum.updated|date:"d/m/Y" }}</small>
<div class="row align-items-sm-center mb-3">
<div class="col-12 col-sm">
</div>
<div class="col-12 col-sm-auto">
{% include "partials/social_share_buttons.html" with text=forum.name instance=forum %}
</div>
</div>
</div>
<div class="col-12 col-lg-3">
<a href="{% url 'forum_extension:forum' parent_forum.slug parent_forum.id %}"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ <h1>{{ topic.subject }}</h1>
{% include "forum_conversation/partials/topic_detail_actions.html" %}
</div>
<div class="col-12 col-sm-auto">
{% include "forum_conversation/partials/social_share_buttons.html" with topic=topic %}
{% include "partials/social_share_buttons.html" with text=topic.subject instance=topic %}
</div>
</div>
<div class="row mt-5 mb-5">
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/templates/forum_conversation/topic_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{% include "forum_conversation/partials/topic_detail_actions.html" with posts_count=topic.posts_count %}
</div>
<div class="col-12 col-sm-auto">
{% include "forum_conversation/partials/social_share_buttons.html" with topic=topic %}
{% include "partials/social_share_buttons.html" with text=topic.subject instance=topic %}
</div>
</div>
{% empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</a>
</p>
<div>
{% include "forum_conversation/partials/social_share_buttons.html" with topic=topic %}
{% include "partials/social_share_buttons.html" with text=topic.subject instance=topic %}
</div>
</div>
<div class="card-body pt-0">
Expand Down
13 changes: 13 additions & 0 deletions lacommunaute/templates/partials/social_share_buttons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% load i18n %}
{% load social_share %}

<button class="btn btn-sm btn-ico-only btn-secondary" type="button" id="dropdownMenuSocialShare" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="ri-share-fill ri-lg" aria-label="{% trans "Share this topics on " %}"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuSocialShare">
{% post_to_facebook instance '<i class="ri-facebook-fill ri-lg"></i> Partager sur Facebook' %}
{% post_to_whatsapp instance '<i class="ri-whatsapp-line ri-lg"></i> Partager sur Whatsapp' %}
{% post_to_twitter text instance '<i class="ri-twitter-line ri-lg"></i> Partager sur Twitter' %}
{% send_email text "Ce lien peut t'intéresser :" instance '<i class="ri-mail-line ri-lg"></i> Partager par email' %}
{% post_to_linkedin instance %}
</div>