Skip to content

Commit

Permalink
🐛(rdfa) fix errors on Google Search Console
Browse files Browse the repository at this point in the history
Google Search Console requires more information for the RDFa information.
Fixed errors:
- Missing field 'hasCourseInstance'
- Either 'courseWorkload' or 'courseSchedule' should be specified
  (in 'hasCourseInstance')

related to #2444
  • Loading branch information
igobranco committed Jul 3, 2024
1 parent 0866db8 commit bb7babc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
### Fixed

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

## [2.28.1]

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
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

0 comments on commit bb7babc

Please sign in to comment.