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

✨(search) allows different search and courses page #1811

Closed
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Add `RICHIE_SEARCH_REVERSE_ID` setting that allows to have different search
page and courses parent page.
- Add Dashboard router
- Add generic dashboard component
- Add dashboard components for Order, Enrollment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura
environ_prefix=None,
)

# Configure course search page reverse id
RICHIE_SEARCH_REVERSE_ID = values.Value(
"courses",
environ_name="RICHIE_SEARCH_REVERSE_ID",
environ_prefix=None,
)

# Internationalization
TIME_ZONE = "Europe/Paris"
USE_I18N = True
Expand Down
7 changes: 7 additions & 0 deletions sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura
environ_prefix=None,
)

# Configure course search page reverse id
RICHIE_SEARCH_REVERSE_ID = values.Value(
"courses",
environ_name="RICHIE_SEARCH_REVERSE_ID",
environ_prefix=None,
)

@classmethod
def _get_environment(cls):
"""Environment in which the application is launched."""
Expand Down
5 changes: 5 additions & 0 deletions src/richie/apps/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def site_metas(request: HttpRequest):
**WebAnalyticsContextProcessor().context_processor(request),
}

# Add a context variable with the reverse id of the search course page.
context["RICHIE_SEARCH_REVERSE_ID"] = getattr(
settings, "RICHIE_SEARCH_REVERSE_ID", "courses"
)

if getattr(settings, "CDN_DOMAIN", None):
context["CDN_DOMAIN"] = settings.CDN_DOMAIN

Expand Down
2 changes: 1 addition & 1 deletion src/richie/apps/core/templates/richie/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<div class="topbar__menu topbar__menu--aside">
{% block topbar_searchbar %}
<div class="topbar__search richie-react richie-react--root-search-suggest-field"
data-props='{"courseSearchPageUrl": "{% page_url 'courses' %}"}'></div>
data-props='{"courseSearchPageUrl": "{% page_url RICHIE_SEARCH_REVERSE_ID %}"}'></div>
{% endblock topbar_searchbar %}
<ul class="topbar__list topbar__list--controls">
{% block userlogin %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ <h2 class="category-detail__title">{% trans "Related courses" %}</h2>
{% include "richie/pagination.html" with label=_("Courses pagination") %}
<div class="button-caesura">
{% if category.get_meta_category %}
<a href="{% page_url 'courses' %}?{{ category.get_meta_category.extended_object.reverse_id }}={{ category.get_es_id }}" class="category-detail__see-more">
<a href="{% page_url RICHIE_SEARCH_REVERSE_ID %}?{{ category.get_meta_category.extended_object.reverse_id }}={{ category.get_es_id }}" class="category-detail__see-more">
{% blocktrans with category_title=category.extended_object.get_title %}
See all courses related to {{ category_title }}
{% endblocktrans %}
</a>
{% else %}
<a href="{% page_url 'courses' %}" class="category-detail__see-more">
<a href="{% page_url RICHIE_SEARCH_REVERSE_ID %}" class="category-detail__see-more">
{% trans "See all courses" %}
</a>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h2 class="organization-detail__title">{% trans "Related courses" %}</h2>
{% if paginator.num_pages > 1 %}
{% include "richie/pagination.html" with label=_("Related courses pagination") %}
<div class="button-caesura">
<a href="{% page_url 'courses' %}?organizations={{ organization.get_es_id }}" class="organization-detail__see-more">
<a href="{% page_url RICHIE_SEARCH_REVERSE_ID %}?organizations={{ organization.get_es_id }}" class="organization-detail__see-more">
{% blocktrans with organization_title=organization.extended_object.get_title %}
See all courses related to {{ organization_title }}
{% endblocktrans %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ <h2 class="person-detail__title">{% trans "Courses" %}</h2>
{% if paginator.num_pages > 1 %}
{% include "richie/pagination.html" with label=_("Courses pagination") %}
<div class="button-caesura">
<a href="{% page_url 'courses' %}?persons={{ person.extended_object_id }}" class="person-detail__see-more">
<a href="{% page_url RICHIE_SEARCH_REVERSE_ID %}?persons={{ person.extended_object_id }}" class="person-detail__see-more">
{% blocktrans with person_title=person.extended_object.get_title %}
See all courses related to {{ person_title }}
{% endblocktrans %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</p>

<div class="richie-react richie-react--root-search-suggest-field"
data-props='{"courseSearchPageUrl": "{% page_url 'courses' %}"}'></div>
data-props='{"courseSearchPageUrl": "{% page_url RICHIE_SEARCH_REVERSE_ID %}"}'></div>

<a class="hero-intro__cta" href="{% page_url 'courses' %}">
<a class="hero-intro__cta" href="{% page_url RICHIE_SEARCH_REVERSE_ID %}">
{% trans "Explore our catalog" %}
</a>
</div>
Expand Down
11 changes: 9 additions & 2 deletions tests/apps/courses/test_templates_organization_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,12 @@ def test_templates_organization_detail_cms_published_content(self):
@mock.patch(
"cms.templatetags.cms_tags.PageUrl.get_value", return_value="/the/courses/"
)
@override_settings(RICHIE_GLIMPSE_PAGINATION={"courses": 2})
@override_settings(
RICHIE_GLIMPSE_PAGINATION={"courses": 2},
RICHIE_SEARCH_REVERSE_ID="overall-search",
)
def test_templates_organization_detail_cms_published_content_max_courses(
self, _mock_page_url
self, mock_page_url
):
"""
Make sure the organization detail page does not display too many courses, even when a large
Expand Down Expand Up @@ -314,6 +317,10 @@ def test_templates_organization_detail_cms_published_content_max_courses(
self.assertContains(response, courses[1].extended_object.get_title())
self.assertNotContains(response, courses[2].extended_object.get_title())

# Check if `RICHIE_SEARCH_REVERSE_ID` setting value is used has reverse id
# to find course page search
self.assertEqual("overall-search", mock_page_url.call_args[1]["page_lookup"])

# There is a link to view more related courses directly in the Search view
self.assertContains(
response, f'href="/the/courses/?organizations={organization.get_es_id():s}"'
Expand Down