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

🐛(rdfa) fix errors on Google Search Console #2445

Merged
merged 2 commits into from
Jul 3, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unrealeased]

### Fixed

- Fix course enrollment count shouldn't include the hidden runs.
- Fix RDFa errors on Google Search Console

## [2.28.1]

### Fixed
Expand Down
12 changes: 8 additions & 4 deletions src/richie/apps/courses/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,14 @@ def course_runs_enrollment_count(self):
node = self.extended_object.node
current_and_descendant_nodes = node.__class__.get_tree(parent=node)

return CourseRun.objects.filter(
direct_course__extended_object__node__in=current_and_descendant_nodes,
direct_course__extended_object__publisher_is_draft=is_draft,
).aggregate(sum=Sum("enrollment_count"))["sum"]
return (
CourseRun.objects.filter(
direct_course__extended_object__node__in=current_and_descendant_nodes,
direct_course__extended_object__publisher_is_draft=is_draft,
)
.exclude(catalog_visibility=CourseRunCatalogVisibility.HIDDEN)
.aggregate(sum=Sum("enrollment_count"))["sum"]
)

@cached_property
def languages_display(self):
Expand Down
13 changes: 7 additions & 6 deletions src/richie/apps/courses/templates/courses/cms/course_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,19 @@ <h2 class="course-detail__title">{% blocktrans context "course_detail__title" %}
<div class="course-detail__aside">
{% render_model_add course "" "" "get_admin_url_to_add_run" %}
{% with runs_dict=current_page.course.course_runs_dict %}
{% with open_visible_runs=runs_dict.0|add:runs_dict.1|add:runs_dict.2|visible_on_course_page:request.toolbar.edit_mode_active %}
{% with runs_without_to_be_scheduled=runs_dict.0|add:runs_dict.1|add:runs_dict.2|add:runs_dict.3|add:runs_dict.4|add:runs_dict.5|add:runs_dict.6|visible_on_course_page:request.toolbar.edit_mode_active %}
<!--
As course runs are rendered through React, we use meta tags to
setup course runs RFDa properties.
-->
{% for run in open_visible_runs %}
-->
{% for run in runs_without_to_be_scheduled %}
<span rel="hasCourseInstance" typeof="CourseInstance">
<meta property="name" content="{{ run.title }}" />
<meta property="inLanguage" content="{{ run.get_languages_display }}" />
<meta property="courseMode" content="online" />
<meta property="name" content='{{ run.title|default:current_page.get_title }}' />
<meta property="inLanguage" content="{{ run.get_languages_display }}" />
<meta property="courseMode" content="online" />
<meta property="startDate" content="{{ run.start|date:'Y-m-d' }}" />
<meta property="endDate" content="{{ run.end|date:'Y-m-d' }}" />
<meta property="courseWorkload" content="{{ current_page.course.pt_effort }}" />
</span>
{% endfor %}
{% endwith %}
Expand Down
21 changes: 21 additions & 0 deletions tests/apps/courses/test_models_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from richie.apps.courses import defaults, factories
from richie.apps.courses.cms_plugins import CoursePlugin
from richie.apps.courses.models import Course, CourseRun, CourseRunTranslation, Program
from richie.apps.courses.models.course import CourseRunCatalogVisibility

# pylint: disable=too-many-public-methods

Expand Down Expand Up @@ -941,6 +942,26 @@ def test_models_course_course_runs_enrollment_count(self):
enrollment_count_sum = course.public_extension.course_runs_enrollment_count
self.assertEqual(enrollment_count_sum, 5)

def test_models_course_course_runs_enrollment_count_hidden_run(self):
"""
The `course_runs_enrollment_count` property should not include the hidden course runs.
"""
course = factories.CourseFactory()

# Create random course runs for this course
factories.CourseRunFactory(enrollment_count=30, direct_course=course)
factories.CourseRunFactory(enrollment_count=20, direct_course=course)
factories.CourseRunFactory(
enrollment_count=10,
direct_course=course,
catalog_visibility=CourseRunCatalogVisibility.HIDDEN,
)
course.extended_object.publish("en")
course.refresh_from_db()

enrollment_count_sum = course.public_extension.course_runs_enrollment_count
self.assertEqual(enrollment_count_sum, 50)

def test_models_course_course_runs_dict(self):
"""The `course_runs_dict` property should be computed on once per request."""
course = factories.CourseFactory()
Expand Down
25 changes: 25 additions & 0 deletions tests/apps/courses/test_templates_course_detail_rdfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
OrganizationFactory,
PersonFactory,
)
from richie.apps.courses.models import CourseRunCatalogVisibility
from richie.plugins.nesteditem.defaults import ACCORDION

# pylint: disable=too-many-lines,too-many-locals,too-many-statements
Expand Down Expand Up @@ -213,6 +214,27 @@ def test_templates_course_detail_rdfa(self):
languages=["de"],
enrollment_count=3000,
)
CourseRunFactory(
title="A hidden course run",
direct_course=course,
start=datetime(2010, 6, 1, tzinfo=timezone.utc),
end=datetime(2050, 7, 10, tzinfo=timezone.utc),
enrollment_start=datetime(2010, 6, 13, tzinfo=timezone.utc),
enrollment_end=datetime(2050, 6, 20, tzinfo=timezone.utc),
languages=["pt"],
enrollment_count=100,
catalog_visibility=CourseRunCatalogVisibility.HIDDEN,
)
CourseRunFactory(
title="A to be scheduled run",
direct_course=course,
start=None,
end=None,
enrollment_start=None,
enrollment_end=None,
languages=["en"],
enrollment_count=0,
)

contributor1.extended_object.publish("en")
course.extended_object.publish("en")
Expand Down Expand Up @@ -552,6 +574,9 @@ def test_templates_course_detail_rdfa(self):
self.assertTrue(
(course_run_subject, SDO.courseMode, Literal("online")) in graph
)
self.assertTrue(
(course_run_subject, SDO.courseWorkload, Literal("PT3H")) in graph
)

for title in ["Run 0", "Run 1"]:
(course_run_subject,) = graph.subjects(SDO.name, Literal(title))
Expand Down