Skip to content

Commit

Permalink
New design: Course page layout changes (#1816)
Browse files Browse the repository at this point in the history
* Adds generalized feature flag stuff
* Updates the course page layout for the new design
  • Loading branch information
jkachel authored Aug 24, 2023
1 parent f1aea16 commit 5d2722a
Show file tree
Hide file tree
Showing 37 changed files with 1,887 additions and 162 deletions.
103 changes: 103 additions & 0 deletions cms/migrations/0031_add_faq_remove_faculty_reorder_things.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Generated by Django 3.2.18 on 2023-07-31 14:40

import wagtail.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cms", "0030_move_instructor_short_bios_to_long"),
]

operations = [
migrations.RemoveField(
model_name="coursepage",
name="faculty_members",
),
migrations.RemoveField(
model_name="programpage",
name="faculty_members",
),
migrations.AddField(
model_name="coursepage",
name="faq_url",
field=models.URLField(
blank=True,
help_text="URL a relevant FAQ page or entry for the course/program.",
null=True,
),
),
migrations.AddField(
model_name="programpage",
name="faq_url",
field=models.URLField(
blank=True,
help_text="URL a relevant FAQ page or entry for the course/program.",
null=True,
),
),
migrations.AlterField(
model_name="coursepage",
name="about",
field=wagtail.fields.RichTextField(
blank=True, help_text="Details about this course/program.", null=True
),
),
migrations.AlterField(
model_name="coursepage",
name="description",
field=wagtail.fields.RichTextField(
help_text="The description shown on the home page and product page."
),
),
migrations.AlterField(
model_name="coursepage",
name="prerequisites",
field=wagtail.fields.RichTextField(
blank=True,
help_text="A short description indicating prerequisites of this course/program.",
null=True,
),
),
migrations.AlterField(
model_name="coursepage",
name="video_url",
field=models.URLField(
blank=True,
help_text="URL to the video to be displayed for this course/program. It can be an HLS or Youtube video URL.",
null=True,
),
),
migrations.AlterField(
model_name="programpage",
name="about",
field=wagtail.fields.RichTextField(
blank=True, help_text="Details about this course/program.", null=True
),
),
migrations.AlterField(
model_name="programpage",
name="description",
field=wagtail.fields.RichTextField(
help_text="The description shown on the home page and product page."
),
),
migrations.AlterField(
model_name="programpage",
name="prerequisites",
field=wagtail.fields.RichTextField(
blank=True,
help_text="A short description indicating prerequisites of this course/program.",
null=True,
),
),
migrations.AlterField(
model_name="programpage",
name="video_url",
field=models.URLField(
blank=True,
help_text="URL to the video to be displayed for this course/program. It can be an HLS or Youtube video URL.",
null=True,
),
),
]
42 changes: 27 additions & 15 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ class Meta:
abstract = True

description = RichTextField(
help_text="The description shown on the home page and product page. The recommended character limit is 1000 characters. Longer entries may not display nicely on the page."
help_text="The description shown on the home page and product page."
)

length = models.CharField(
Expand All @@ -821,15 +821,23 @@ class Meta:
prerequisites = RichTextField(
null=True,
blank=True,
help_text="A short description indicating prerequisites of this course.",
help_text="A short description indicating prerequisites of this course/program.",
)

about = RichTextField(null=True, blank=True, help_text="About this course details.")
about = RichTextField(
null=True, blank=True, help_text="Details about this course/program."
)

faq_url = models.URLField(
null=True,
blank=True,
help_text="URL a relevant FAQ page or entry for the course/program.",
)

video_url = models.URLField(
null=True,
blank=True,
help_text="URL to the video to be displayed for this program/course. It can be an HLS or Youtube video URL.",
help_text="URL to the video to be displayed for this course/program. It can be an HLS or Youtube video URL.",
)

what_you_learn = RichTextField(
Expand All @@ -853,14 +861,6 @@ class Meta:
help_text="The title text to display in the faculty cards section of the product page.",
)

faculty_members = StreamField(
[("faculty_member", FacultyBlock())],
null=True,
blank=True,
help_text="The faculty members to display on this page",
use_json_field=True,
)

def save(self, clean=True, user=None, log_action=False, **kwargs):
"""
Updates related courseware object title.
Expand Down Expand Up @@ -933,13 +933,13 @@ def is_program_page(self):
FieldPanel("effort"),
FieldPanel("price"),
FieldPanel("prerequisites"),
FieldPanel("faq_url"),
FieldPanel("about"),
FieldPanel("what_you_learn"),
FieldPanel("feature_image"),
InlinePanel("linked_instructors", label="Faculty Members"),
FieldPanel("faculty_section_title"),
FieldPanel("faculty_members"),
FieldPanel("video_url"),
FieldPanel("faculty_section_title"),
InlinePanel("linked_instructors", label="Faculty Members"),
]

subpage_types = ["FlexiblePricingRequestForm", "CertificatePage"]
Expand Down Expand Up @@ -998,6 +998,18 @@ def get_context(self, request, *args, **kwargs):
"instructors": instructors,
}

def get_context(self, request, *args, **kwargs):
instructors = [
member.linked_instructor_page
for member in self.linked_instructors.order_by("order").all()
]

return {
**super().get_context(request),
**get_base_context(request),
"instructors": instructors,
}


class CoursePage(ProductPage):
"""
Expand Down
1 change: 1 addition & 0 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def test_course_page_context(
member.linked_instructor_page
for member in course_page.linked_instructors.order_by("order").all()
],
"new_design": features.is_enabled("mitxonline-new-product-page"),
}

context = course_page.get_context(request=request)
Expand Down
60 changes: 57 additions & 3 deletions cms/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class CoursePageSerializer(serializers.ModelSerializer):
current_price = serializers.SerializerMethodField()
instructors = serializers.SerializerMethodField()
live = serializers.SerializerMethodField()
effort = serializers.SerializerMethodField()
length = serializers.SerializerMethodField()

def get_feature_image_src(self, instance):
"""Serializes the source of the feature_image"""
Expand Down Expand Up @@ -100,15 +102,18 @@ def get_current_price(self, instance):
return relevant_product.price if relevant_product else None

def get_instructors(self, instance):
members = [member.value for member in instance.faculty_members]
members = [
member.linked_instructor_page
for member in instance.linked_instructors.all()
]
returnable_members = []

for member in members:
returnable_members.append(
{
"name": member["name"],
"name": member.instructor_name,
"description": bleach.clean(
member["description"].source, tags=[], strip=True
member.instructor_bio_short, tags=[], strip=True
),
}
)
Expand All @@ -118,6 +123,20 @@ def get_instructors(self, instance):
def get_live(self, instance):
return instance.live

def get_effort(self, instance):
return (
bleach.clean(instance.effort, tags=[], strip=True)
if instance.effort
else None
)

def get_length(self, instance):
return (
bleach.clean(instance.length, tags=[], strip=True)
if instance.length
else None
)

class Meta:
model = models.CoursePage
fields = [
Expand All @@ -128,6 +147,8 @@ class Meta:
"current_price",
"instructors",
"live",
"length",
"effort",
]


Expand All @@ -154,3 +175,36 @@ class Meta:
"feature_image_src",
"page_url",
]


class InstructorPageSerializer(serializers.ModelSerializer):
"""Instructor page model serializer"""

feature_image_src = serializers.SerializerMethodField()

def get_feature_image_src(self, instance):
"""Serializes the source of the feature_image"""
feature_img_src = None
if hasattr(instance, "feature_image"):
feature_img_src = get_wagtail_img_src(instance.feature_image)

return feature_img_src or static(DEFAULT_COURSE_IMG_PATH)

class Meta:
model = models.InstructorPage
fields = [
"id",
"instructor_name",
"instructor_title",
"instructor_bio_short",
"instructor_bio_long",
"feature_image_src",
]
read_only_fields = [
"id",
"instructor_name",
"instructor_title",
"instructor_bio_short",
"instructor_bio_long",
"feature_image_src",
]
10 changes: 10 additions & 0 deletions cms/serializers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def test_serialize_course_page(
"current_price": None,
"description": bleach.clean(course_page.description, tags=[], strip=True),
"live": True,
"length": course_page.length,
"effort": course_page.effort,
},
)
patched_get_wagtail_src.assert_called_once_with(course_page.feature_image)
Expand Down Expand Up @@ -96,6 +98,8 @@ def test_serialize_course_page_with_flex_price_with_program_fk_and_parent(
"current_price": None,
"description": bleach.clean(course_page.description, tags=[], strip=True),
"live": True,
"length": course_page.length,
"effort": course_page.effort,
},
)

Expand Down Expand Up @@ -136,6 +140,8 @@ def test_serialize_course_page_with_flex_price_with_program_fk_no_parent(
"current_price": None,
"description": bleach.clean(course_page.description, tags=[], strip=True),
"live": True,
"length": course_page.length,
"effort": course_page.effort,
},
)

Expand Down Expand Up @@ -176,6 +182,8 @@ def test_serialize_course_page_with_flex_price_form_as_program_child(
"current_price": None,
"description": bleach.clean(course_page.description, tags=[], strip=True),
"live": True,
"length": course_page.length,
"effort": course_page.effort,
},
)

Expand Down Expand Up @@ -213,5 +221,7 @@ def test_serialize_course_page_with_flex_price_form_as_child_no_program(
"current_price": None,
"description": bleach.clean(course_page.description, tags=[], strip=True),
"live": True,
"length": course_page.length,
"effort": course_page.effort,
},
)
Loading

0 comments on commit 5d2722a

Please sign in to comment.