Skip to content

Commit

Permalink
remove /documentation/ routes to reused it with documentation app
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 23, 2024
1 parent 171bdde commit f776aeb
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 270 deletions.
10 changes: 5 additions & 5 deletions lacommunaute/forum/tests/__snapshots__/tests_views.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="#">Documentation</a>

</li>

Expand All @@ -22,7 +22,7 @@
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="#">Documentation</a>

</li>

Expand Down Expand Up @@ -60,7 +60,7 @@
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="#">Documentation</a>

</li>

Expand Down Expand Up @@ -127,7 +127,7 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="s-section__col col-12">
<a aria-label="Ajouter une fiche pratique" class="btn btn-outline-primary" href="/documentation/category/9999/create/" role="button">Ajouter une fiche pratique</a>
<a aria-label="Ajouter une fiche pratique" class="btn btn-outline-primary" href="#" role="button">Ajouter une fiche pratique</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -176,7 +176,7 @@
<li class="breadcrumb-item">Retourner vers</li>
<li class="breadcrumb-item">

<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="/documentation/">Documentation</a>
<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="documentation_breadcrumb" href="#">Documentation</a>

</li>

Expand Down
60 changes: 0 additions & 60 deletions lacommunaute/forum/tests/test_categoryforum_createview.py

This file was deleted.

42 changes: 1 addition & 41 deletions lacommunaute/forum/tests/test_categoryforum_listview.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
import pytest # noqa
from django.urls import reverse
from pytest_django.asserts import assertContains, assertNotContains
from pytest_django.asserts import assertContains

from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.users.factories import UserFactory


def test_context(client, db):
url = reverse("forum_extension:documentation")
response = client.get(url)
assert "forum/category_forum_list.html" == response.templates[0].name
assertContains(response, reverse("stats:statistiques"), status_code=200)


def test_queryset(client, db):
forum = ForumFactory(type=Forum.FORUM_CAT)
unvisible_forums = (
ForumFactory(type=Forum.FORUM_CAT, parent=forum),
ForumFactory(),
ForumFactory(type=Forum.FORUM_LINK),
)
url = reverse("forum_extension:documentation")
response = client.get(url)
assert response.status_code == 200
assert forum in response.context_data["forums"]
for unvisible_forum in unvisible_forums:
assert unvisible_forum not in response.context_data["forums"]


def test_display_create_category_button(client, db):
url = reverse("forum_extension:documentation")
response = client.get(url)
assertNotContains(response, reverse("forum_extension:create_category"), status_code=200)

user = UserFactory()
client.force_login(user)
response = client.get(url)
assertNotContains(response, reverse("forum_extension:create_category"), status_code=200)

user.is_superuser = True
user.save()
response = client.get(url)
assertContains(response, reverse("forum_extension:create_category"), status_code=200)


def test_display_banners(client, db):
Expand Down
69 changes: 0 additions & 69 deletions lacommunaute/forum/tests/test_subcategoryforum_createview.py

This file was deleted.

18 changes: 0 additions & 18 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,6 @@ def test_descendants_are_in_cards_if_forum_is_category_type(self):
response, reverse("forum_extension:forum", kwargs={"pk": child_forum.pk, "slug": child_forum.slug})
)

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

user = UserFactory()
self.client.force_login(user)
response = self.client.get(url)
self.assertNotContains(
response, reverse("forum_extension:create_subcategory", kwargs={"pk": forum.pk}), status_code=200
)

user.is_superuser = True
user.save()
response = self.client.get(url)
self.assertContains(
response, reverse("forum_extension:create_subcategory", kwargs={"pk": forum.pk}), status_code=200
)

def test_siblings_in_context(self):
forum = CategoryForumFactory(with_public_perms=True)
ForumFactory.create_batch(3, parent=forum, with_public_perms=True)
Expand Down
6 changes: 0 additions & 6 deletions lacommunaute/forum/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
from machina.apps.forum.views import IndexView

from lacommunaute.forum.views import (
CategoryForumCreateView,
CategoryForumListView,
ForumRatingView,
ForumUpdateView,
ForumView,
SubCategoryForumCreateView,
SubCategoryForumListView,
)

Expand All @@ -21,7 +18,4 @@
path("forum/<str:slug>-<int:pk>/rate/", ForumRatingView.as_view(), name="rate"),
path("forum/<str:slug>-<int:pk>/subs/", SubCategoryForumListView.as_view(), name="subcategory_forums"),
path("forums/", IndexView.as_view(), name="index"),
path("documentation/", CategoryForumListView.as_view(), name="documentation"),
path("documentation/category/create/", CategoryForumCreateView.as_view(), name="create_category"),
path("documentation/category/<int:pk>/create/", SubCategoryForumCreateView.as_view(), name="create_subcategory"),
]
64 changes: 3 additions & 61 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from django.conf import settings
from django.contrib.auth.mixins import UserPassesTestMixin
from django.contrib.contenttypes.models import ContentType
from django.db.models.query import QuerySet
from django.shortcuts import get_object_or_404, render
from django.urls import reverse, reverse_lazy
from django.urls import reverse
from django.views import View
from django.views.generic import CreateView, ListView, UpdateView
from django.views.generic import UpdateView
from machina.apps.forum.views import ForumView as BaseForumView
from machina.core.loading import get_class
from taggit.models import Tag
Expand All @@ -17,7 +16,7 @@
from lacommunaute.forum_conversation.forms import PostForm
from lacommunaute.forum_conversation.view_mixins import FilteredTopicsListViewMixin
from lacommunaute.forum_upvote.models import UpVote
from lacommunaute.utils.perms import add_public_perms_on_forum, forum_visibility_content_tree_from_forums
from lacommunaute.utils.perms import forum_visibility_content_tree_from_forums


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -134,63 +133,6 @@ def get_context_data(self, **kwargs):
return context


class CategoryForumListView(ListView):
template_name = "forum/category_forum_list.html"
context_object_name = "forums"

def get_queryset(self) -> QuerySet[Forum]:
return Forum.objects.filter(type=Forum.FORUM_CAT, level=0)


class BaseCategoryForumCreateView(UserPassesTestMixin, CreateView):
template_name = "forum/forum_create_or_update.html"
form_class = ForumForm

def test_func(self):
return self.request.user.is_superuser

def form_valid(self, form):
response = super().form_valid(form)
add_public_perms_on_forum(form.instance)
return response


class CategoryForumCreateView(BaseCategoryForumCreateView):
success_url = reverse_lazy("forum_extension:documentation")

def form_valid(self, form):
form.instance.parent = None
form.instance.type = Forum.FORUM_CAT
return super().form_valid(form)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Créer une nouvelle catégorie documentaire"
context["back_url"] = reverse("forum_extension:documentation")
return context


class SubCategoryForumCreateView(BaseCategoryForumCreateView):
def get_success_url(self):
return reverse("forum_extension:forum", kwargs={"pk": self.object.pk, "slug": self.object.slug})

def get_parent_forum(self):
return Forum.objects.get(pk=self.kwargs["pk"])

def form_valid(self, form):
form.instance.type = Forum.FORUM_POST
form.instance.parent = self.get_parent_forum()
return super().form_valid(form)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = f"Créer une fiche pratique dans la catégorie {self.get_parent_forum().name}"
context["back_url"] = reverse(
"forum_extension:forum", kwargs={"pk": self.get_parent_forum().pk, "slug": self.get_parent_forum().slug}
)
return context


class ForumRatingView(View):
def post(self, request, *args, **kwargs):
forum_rating = ForumRating.objects.create(
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1 class="h1">Bienvenue sur le site de la Communauté de l'Inclusion.</h1>
<a href="{% url 'forum_conversation_extension:topics' %}">Espace d'échanges</a>
</li>
<li>
<a href="{% url 'forum_extension:documentation' %}">Documentation</a>
<a href="#">Documentation</a>
</li>
<li>
<a href="{% url 'search:index' %}">Recherche</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="s-section__container container">
<div class="s-section__row row">
<div class="s-section__col col-12">
<a href="{% url 'forum_extension:create_subcategory' forum.pk %}" aria-label="Ajouter une fiche pratique" role="button" class="btn btn-outline-primary">Ajouter une fiche pratique</a>
<a href="#" aria-label="Ajouter une fiche pratique" role="button" class="btn btn-outline-primary">Ajouter une fiche pratique</a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% block body_class %}p-home{{ block.super }}{% endblock %}
{% block content %}
{% url 'forum_conversation_extension:topics' as publicforum_url %}
{% url 'forum_extension:documentation' as documentation_url %}
{% url None as documentation_url %}
{% url 'event:current' as event_url %}
{% url 'surveys:dsp_create' as dsp_url %}
<section class="s-home-title-01 s-home-title-01--communaute mb-md-6 mb-lg-10" style="--home-title-bg: url({% static 'images/commu-home-illu-02b-light.png' %})">
Expand Down
6 changes: 1 addition & 5 deletions lacommunaute/templates/partials/ask_a_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
</div>
<div class="col-12 col-lg-auto py-1 py-lg-0 px-lg-0 text-center">ou</div>
<div class="col-12 col-lg-auto">
<a href="{% url 'forum_extension:documentation' %}"
class="btn btn-outline-primary btn-ico btn-block matomo-event"
data-matomo-category="engagement"
data-matomo-action="view"
data-matomo-option="documentation">
<a href="#" class="btn btn-outline-primary btn-ico btn-block matomo-event" data-matomo-category="engagement" data-matomo-action="view" data-matomo-option="documentation">
<span>Consulter la documentation</span>
</a>
</div>
Expand Down
Loading

0 comments on commit f776aeb

Please sign in to comment.