Skip to content

Commit

Permalink
🗃️(backend/core) add display_mode field to CourseRun model
Browse files Browse the repository at this point in the history
Editor users wants to be able to customize the look'n feel of Joanie Product
widget. To take this need, we add a `display_mode` choice field to `CourseRun`
model then bind this new field to the React widget props serializer. In this
way, frontend will be aware in which mode joanie product should be displayed.
  • Loading branch information
jbpenrath committed Sep 1, 2023
1 parent 9288b21 commit f47f5b0
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Add `display_mode` choice field to `CourseRun` model
- Add a footer on enrollment's item in the learner dashboard. It give the
possibility to purchase linked product or download linked certificate.

Expand All @@ -19,6 +20,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
the number of seller organization instead of the title of the first one.
- Update `JOANIE_BACKEND` settings, frontend widgets and learner dashboard
to match new API endpoint to retrieve course products
- Use cunningham Button component.

### Fixed

Expand Down Expand Up @@ -64,7 +66,6 @@ through `context_processor`
- Improve the design of the dashboards sidebars.
- Move course's syllabus course runs list to React.
- Migrate wishlist to new API.
- Use cunningham Button component.

### Removed

Expand Down
1 change: 1 addition & 0 deletions src/richie/apps/courses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Meta:
"enrollment_count",
"catalog_visibility",
"sync_mode",
"display_mode",
]

def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions src/richie/apps/courses/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ class Meta:
title = factory.Sequence(_("Run {:d}").format)
resource_link = factory.Faker("uri")
sync_mode = models.CourseRunSyncMode.SYNC_TO_PUBLIC
display_mode = models.CourseRunDisplayMode.DETAILED

# pylint: disable=no-self-use
@factory.lazy_attribute
Expand Down
68 changes: 68 additions & 0 deletions src/richie/apps/courses/migrations/0034_auto_20230817_1736.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Generated by Django 3.2.20 on 2023-08-17 15:36

from django.db import migrations, models

import richie.apps.core.fields.duration


class Migration(migrations.Migration):
dependencies = [
("courses", "0033_auto_20211207_2251"),
]

operations = [
migrations.AddField(
model_name="courserun",
name="display_mode",
field=models.CharField(
choices=[
(
"compact",
"compact - show minimal information about the course run (only for products).",
),
(
"detailed",
"detailed - show all information about the course run (only for products).",
),
],
default="detailed",
max_length=20,
),
),
migrations.AlterField(
model_name="course",
name="effort",
field=richie.apps.core.fields.duration.CompositeDurationField(
blank=True,
default_unit="hour",
help_text="Total amount of time to complete this course.",
max_length=80,
null=True,
time_units={"hour": ("hour", "hours"), "minute": ("minute", "minutes")},
),
),
migrations.AlterField(
model_name="courserun",
name="enrollment_count",
field=models.PositiveIntegerField(
blank=True,
default=0,
help_text="The number of enrolled students",
verbose_name="enrollment count",
),
),
migrations.AlterField(
model_name="courserun",
name="sync_mode",
field=models.CharField(
choices=[
("manual", "Manual"),
("sync_to_draft", "Synchronization to draft page"),
("sync_to_public", "Synchronization to public page"),
],
default="manual",
max_length=20,
verbose_name="Synchronization mode",
),
),
]
17 changes: 17 additions & 0 deletions src/richie/apps/courses/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,17 @@ class CourseRunCatalogVisibility(models.TextChoices):
HIDDEN = "hidden", _("hidden - hide on the course page and from search results")


class CourseRunDisplayMode(models.TextChoices):
"""Course run catalog display modes."""

COMPACT = "compact", _(
"compact - show minimal information about the course run (only for products)."
)
DETAILED = "detailed", _(
"detailed - show all information about the course run (only for products)."
)


class CourseRun(TranslatableModel):
"""
The course run represents and records the occurence of a course between a start
Expand Down Expand Up @@ -761,6 +772,12 @@ class CourseRun(TranslatableModel):
blank=False,
max_length=20,
)
display_mode = models.CharField(
choices=CourseRunDisplayMode.choices,
default=CourseRunDisplayMode.DETAILED,
blank=False,
max_length=20,
)

class Meta:
db_table = "richie_course_run"
Expand Down
1 change: 1 addition & 0 deletions src/richie/apps/courses/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Meta:
"enrollment_end",
"languages",
"catalog_visibility",
"display_mode",
"snapshot",
]

Expand Down
2 changes: 2 additions & 0 deletions tests/apps/courses/test_admin_course_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def _prepare_add_view_post(self, course, status_code):
"enrollment_end_1": "09:07:11",
"catalog_visibility": "course_and_search",
"sync_mode": "manual",
"display_mode": "detailed",
}
with timezone.override(pytz.utc):
response = self.client.post(url, data, follow=True)
Expand Down Expand Up @@ -450,6 +451,7 @@ def _prepare_change_view_post(self, course_run, course, status_code, check_metho
"enrollment_count": "5",
"catalog_visibility": "course_and_search",
"sync_mode": "manual",
"display_mode": "detailed",
}
with timezone.override(pytz.utc):
response = self.client.post(url, data, follow=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/apps/courses/test_admin_form_course_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _get_admin_form(course, user):
"enrollment_end_1": "09:07:11",
"catalog_visibility": "course_and_search",
"sync_mode": "manual",
"display_mode": "detailed",
}
request = RequestFactory().get("/")
request.user = user
Expand Down Expand Up @@ -112,6 +113,7 @@ def test_admin_form_course_run_superuser_empty_form(self):
form.errors,
{
"direct_course": ["This field is required."],
"display_mode": ["This field is required."],
"languages": ["This field is required."],
"catalog_visibility": ["This field is required."],
"sync_mode": ["This field is required."],
Expand Down
1 change: 1 addition & 0 deletions tests/apps/courses/test_models_course_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ def test_models_course_run_mark_dirty_any_field(self):
stub = CourseRunFactory(
sync_mode="manual",
catalog_visibility=CourseRunCatalogVisibility.COURSE_ONLY,
display_mode="compact",
) # New random values to update our course run

for field in fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_templatetags_course_runs_list_widget_props_tag(self):
else None,
"languages": sorted(course_run.languages),
"catalog_visibility": course_run.catalog_visibility,
"display_mode": "detailed",
"snapshot": None,
}
],
Expand Down Expand Up @@ -129,6 +130,7 @@ def test_templatetags_course_runs_list_widget_props_tag_with_snapshot(self):
else None,
"languages": sorted(course_run.languages),
"catalog_visibility": course_run.catalog_visibility,
"display_mode": "detailed",
"snapshot": snapshot.extended_object.get_absolute_url(),
}
],
Expand Down Expand Up @@ -200,6 +202,7 @@ def test_templatetags_course_runs_list_widget_props_tag_edit_mode(self):
else None,
"languages": sorted(course_run.languages),
"catalog_visibility": course_run.catalog_visibility,
"display_mode": "detailed",
"snapshot": None,
}
for course_run in course.course_runs.all()
Expand Down

0 comments on commit f47f5b0

Please sign in to comment.