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

refactor(documentation): partie 1, désactivation des routes et scripts necessaires #783

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion clevercloud/collect_weekly_matomo_forum_stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ fi
# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

python manage.py collect_matomo_forum_stats
# reactivate after documentation migration
# python manage.py collect_matomo_forum_stats
echo "Collecting weekly matomo stats for the forum is disabled for now."
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,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
Loading
Loading