From 5728b99e1bbfab9cdd3d3c95e7ae12698cd72c6d Mon Sep 17 00:00:00 2001 From: Tiago-Salles Date: Wed, 16 Oct 2024 14:39:06 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20add=20faqs=20to=20a=20cat?= =?UTF-8?q?egory=20and=20get=20from=20a=20course?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add course_faq placeholder to category detail page - get the course_faq placeholder from the course detail page using the category reverse_id page --- src/richie/apps/courses/settings/__init__.py | 5 ++ .../courses/cms/category_detail.html | 9 +++ .../templates/courses/cms/course_detail.html | 18 +++++ .../apps/courses/templatetags/extra_tags.py | 13 ++++ .../courses/test_templates_category_detail.py | 38 +++++++++++ ...tra_tags_get_categories_pages_have_faqs.py | 66 +++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 tests/apps/courses/test_templatetags_extra_tags_get_categories_pages_have_faqs.py diff --git a/src/richie/apps/courses/settings/__init__.py b/src/richie/apps/courses/settings/__init__.py index 3e54800989..b11c12648e 100644 --- a/src/richie/apps/courses/settings/__init__.py +++ b/src/richie/apps/courses/settings/__init__.py @@ -304,6 +304,11 @@ def richie_placeholder_conf(name): "plugins": ["CKEditorPlugin"], "limits": {"CKEditorPlugin": 1}, }, + "courses/cms/category_detail.html course_faq": { + "name": _("Faq"), + "plugins": ["NestedItemPlugin"], + "child_classes": {"NestedItemPlugin": ["NestedItemPlugin"]}, + }, # Person detail "courses/cms/person_detail.html categories": { "name": _("Categories"), diff --git a/src/richie/apps/courses/templates/courses/cms/category_detail.html b/src/richie/apps/courses/templates/courses/cms/category_detail.html index 2746f8a67a..08c00282db 100644 --- a/src/richie/apps/courses/templates/courses/cms/category_detail.html +++ b/src/richie/apps/courses/templates/courses/cms/category_detail.html @@ -190,6 +190,15 @@

{% trans "Related blogposts" %}

{% endif %} {% endwith %} +
+
+

{% trans "Category FAQ's" %}

+ {% placeholder "course_faq" or %} +

{% trans 'Enter a FAQ for this category' %}

+ {% endplaceholder %} +
+
+ {% with persons=category.get_persons %} {% if persons %} {% autopaginate persons GLIMPSE_PAGINATION_PERSONS %} diff --git a/src/richie/apps/courses/templates/courses/cms/course_detail.html b/src/richie/apps/courses/templates/courses/cms/course_detail.html index 9077a76bfd..a904ffe6c1 100644 --- a/src/richie/apps/courses/templates/courses/cms/course_detail.html +++ b/src/richie/apps/courses/templates/courses/cms/course_detail.html @@ -445,6 +445,24 @@

{% endif %} {% endblock team %} + {% block course_faq %} +
+ {% with is_syllabus_property=True %} + {% get_categories_pages_have_faqs current_page.course as pages_have_faqs %} + {% if pages_have_faqs %} +

{% blocktrans context "course_detail__title" %}Crucial information{% endblocktrans %}

+ + {% for page in pages_have_faqs %} + {% with reverse_id=page.reverse_id %} +

{{ page.get_title }}

+ {% show_placeholder "course_faq" reverse_id %} + {% endwith %} + {% endfor %} + {% endif %} + {% endwith %} +
+ {% endblock course_faq %} + {% block organizations %} {% if current_page.publisher_is_draft or not current_page|is_empty_placeholder:"course_organizations" %}
diff --git a/src/richie/apps/courses/templatetags/extra_tags.py b/src/richie/apps/courses/templatetags/extra_tags.py index 550952729c..b9c45193a3 100644 --- a/src/richie/apps/courses/templatetags/extra_tags.py +++ b/src/richie/apps/courses/templatetags/extra_tags.py @@ -1,6 +1,7 @@ """Custom template tags for the courses application of Richie.""" import json +from typing import List from django import template from django.conf import settings @@ -21,8 +22,10 @@ from cms.toolbar.utils import get_toolbar_from_request from cms.utils import get_site_id from cms.utils.plugins import get_plugins +from cms.api import Page from richie.apps.courses.defaults import RICHIE_MAX_ARCHIVED_COURSE_RUNS +from richie.apps.courses.models.course import Course from ..lms import LMSHandler from ..models import CourseRunCatalogVisibility @@ -270,6 +273,16 @@ def joanie_product_widget_props(context): return json.dumps({"productId": product_id, "courseCode": course_code}) +@register.simple_tag() +def get_categories_pages_have_faqs(course: Course) -> list[Page]: + """ + Return a list with all pages have faq + """ + + categories_pages: list[Page] = course.get_root_to_leaf_public_category_pages().filter(reverse_id__isnull=False) + pages_have_faq: list[Page] = [page for page in categories_pages if not page.get_placeholders().get(slot="course_faq") is None] + + return pages_have_faq @register.simple_tag(takes_context=True) def course_runs_list_widget_props(context): diff --git a/tests/apps/courses/test_templates_category_detail.py b/tests/apps/courses/test_templates_category_detail.py index e67b927194..1aebd05382 100644 --- a/tests/apps/courses/test_templates_category_detail.py +++ b/tests/apps/courses/test_templates_category_detail.py @@ -21,6 +21,7 @@ OrganizationFactory, PersonFactory, ) +from richie.plugins.nesteditem.defaults import ACCORDION class CategoryCMSTestCase(CMSTestCase): @@ -553,3 +554,40 @@ def test_template_category_detail_meta_description_empty(self): response, ' 0) + \ No newline at end of file