Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #564 from torchbox/related-courses
Browse files Browse the repository at this point in the history
Adds related course pages
  • Loading branch information
kevinhowbrook authored Jan 4, 2024
2 parents 7311346 + 484638f commit 70aa231
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tbx/courses/migrations/0003_adds_related_course_pages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Generated by Django 4.2.8 on 2024-01-03 10:18

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):

dependencies = [
("wagtailcore", "0089_log_entry_data_json_null_to_object"),
("courses", "0002_adds_course_landing_page_fields"),
]

operations = [
migrations.CreateModel(
name="RelatedCoursePage",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"sort_order",
models.IntegerField(blank=True, editable=False, null=True),
),
(
"page",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="courses.coursedetailpage",
),
),
(
"source_page",
modelcluster.fields.ParentalKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="related_course_pages",
to="wagtailcore.page",
),
),
],
options={
"ordering": ["sort_order"],
"abstract": False,
},
),
]
17 changes: 17 additions & 0 deletions tbx/courses/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.core import exceptions as django_exceptions
from django.db import models

from modelcluster import fields as modelcluster_fields
from tbx.core.utils import models as utils_models
from tbx.courses import blocks as tbx_course_blocks
from wagtail import fields as wagtail_fields
Expand Down Expand Up @@ -73,6 +74,15 @@ def get_context(self, request, *args, **kwargs):
return context


class RelatedCoursePage(wagtail_models.Orderable):
source_page = modelcluster_fields.ParentalKey(
wagtail_models.Page, related_name="related_course_pages"
)
page = models.ForeignKey("courses.CourseDetailPage", on_delete=models.CASCADE)

panels = [panels.FieldPanel("page")]


class CourseDetailPage(utils_models.SocialFields, wagtail_models.Page):
parent_page_types = ["courses.CourseLandingPage"]

Expand Down Expand Up @@ -115,6 +125,7 @@ class CourseDetailPage(utils_models.SocialFields, wagtail_models.Page):
classname="collapsible",
),
panels.FieldPanel("body"),
panels.InlinePanel("related_course_pages", label="Related courses"),
]

promote_panels = [
Expand All @@ -137,3 +148,9 @@ def clean(self):

if errors:
raise django_exceptions.ValidationError(errors)

@property
def related_courses(self):
return [
page.page for page in self.related_course_pages.all().select_related("page")
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ <h1 class="title-block__heading title-block__heading--course">
</div>

{% include_block page.body %}

{% if page.related_courses %}
<div class="streamfield">
<div class="related-courses">
<h2 class="course-grid-title">Related courses:</h2>
{% include "patterns/molecules/course-grid/course-grid.html" with cards=page.related_courses %}
</div>
</div>
{% endif %}

{% endblock %}
5 changes: 5 additions & 0 deletions tbx/static_src/sass/components/_related-courses.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.related-courses {
@include media-query(x-large) {
margin-left: $variable-gutter--medium;
}
}
1 change: 1 addition & 0 deletions tbx/static_src/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
@import 'components/raw-html-block';
@import 'components/reason';
@import 'components/related-content';
@import 'components/related-courses';
@import 'components/related-item';
@import 'components/report-hero';
@import 'components/report-in-page-nav';
Expand Down

0 comments on commit 70aa231

Please sign in to comment.