|
14 | 14 | ) |
15 | 15 |
|
16 | 16 |
|
| 17 | +def json_ld_from( |
| 18 | + courses: list[PublicCourseSerializer], organization: Organization |
| 19 | +) -> dict: |
| 20 | + course_list = [] |
| 21 | + for course in courses: |
| 22 | + course_data = { |
| 23 | + "@type": "Course", |
| 24 | + "name": course.title, |
| 25 | + "description": course.description, |
| 26 | + "inLanguage": course.language, |
| 27 | + "provider": { |
| 28 | + "@type": "Organization", |
| 29 | + "name": organization.name, |
| 30 | + }, |
| 31 | + } |
| 32 | + if course.image: |
| 33 | + course_data["image"] = course.image |
| 34 | + course_list.append(course_data) |
| 35 | + return { |
| 36 | + "@context": "https://schema.org", |
| 37 | + "@type": "ItemList", |
| 38 | + "itemListElement": course_list, |
| 39 | + } |
| 40 | + |
| 41 | + |
17 | 42 | @method_decorator(ensure_csrf_cookie, name="dispatch") |
18 | 43 | class OrganizationView(TemplateView): |
19 | 44 | template_name = "public/organization.html" |
@@ -82,6 +107,16 @@ def get_context_data(self, **kwargs) -> dict: # type: ignore[no-untyped-def] |
82 | 107 | "course_language": _("Course language"), |
83 | 108 | }, |
84 | 109 | } |
| 110 | + context["organization_name"] = organization.name |
| 111 | + context["organization_description"] = organization.description |
| 112 | + context["organization_logo_url"] = ( |
| 113 | + self.request.build_absolute_uri(organization.logo.url) |
| 114 | + if organization.logo |
| 115 | + else None |
| 116 | + ) |
| 117 | + |
| 118 | + if len(courses) > 0: |
| 119 | + context["json_ld"] = json_ld_from(courses, organization) |
85 | 120 | context["page_title"] = organization.name |
86 | 121 | return context |
87 | 122 |
|
|
0 commit comments