Skip to content

Commit

Permalink
ENT-1321 Add course dates and pacing (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
crice100 authored Aug 20, 2019
1 parent 53a6767 commit 58a0540
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
----------

[1.9.2] - 2019-08-20
--------------------

* Include course run dates and pacing type in the course description sent to SAP.

[1.9.1] - 2019-08-19
--------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from django.utils.translation import ugettext_lazy as _

from enterprise.api_client.lms import parse_lms_api_datetime
from enterprise.utils import get_closest_course_run
from enterprise.views import CourseEnrollmentView
from integrated_channels.integrated_channel.exporters.content_metadata import ContentMetadataExporter
from integrated_channels.sap_success_factors.exporters.utils import (
course_available_for_enrollment,
Expand Down Expand Up @@ -71,18 +73,37 @@ def transform_title(self, content_metadata_item):

def transform_description(self, content_metadata_item):
"""
Return the description of the content item.
Return the description of the content item. Also include the course pacing, and start and end dates.
"""
description_with_locales = []

description = (
content_metadata_item.get('full_description') or
content_metadata_item.get('short_description') or
content_metadata_item.get('title', '')
)

course_runs = content_metadata_item.get('course_runs')
if course_runs:
closest_course_run = get_closest_course_run(course_runs)

# Include the course run start and end dates
date_str = self._get_course_run_start_end_str(closest_course_run)
if date_str:
description = date_str + description

# Include the course pacing
course_pacing = CourseEnrollmentView.PACING_FORMAT.get(closest_course_run['pacing_type'], '')
if course_pacing:
pacing_desc = 'Pacing: {pacing_type}. '.format(
pacing_type=course_pacing
)
description = pacing_desc + description

for locale in self.enterprise_configuration.get_locales():
description_with_locales.append({
'locale': locale,
'value': (
content_metadata_item.get('full_description') or
content_metadata_item.get('short_description') or
content_metadata_item.get('title', '')
)
'value': description
})

return description_with_locales
Expand Down Expand Up @@ -175,6 +196,37 @@ def transform_courserun_title(self, content_metadata_item):

return title_with_locales

def _get_course_run_start_end_str(self, course_run):
"""
Get the course run start and end as a descriptive string. Also include a note if enrollment is closed.
"""
course_run_start = course_run.get('start')
course_run_end = course_run.get('end')
date_str = ''

if course_run_start:
date_str += '{starts}: {:%B %Y}'.format(
parse_lms_api_datetime(course_run_start),
starts=_('Starts')
)

if course_run_end:
if date_str:
date_str += ', '

date_str += '{ends}: {:%B %Y}. '.format(
parse_lms_api_datetime(course_run_end),
ends=_('Ends')
)
else:
if date_str:
date_str += '. '

if not course_available_for_enrollment(course_run):
date_str += 'Enrollment is closed. '

return date_str

def transform_courserun_description(self, content_metadata_item):
"""
Return the description of the courserun content item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,100 @@ def test_transform_launch_points(self):
assert launch_points[0]['launchType'] == 3
assert launch_points[0]['mobileEnabled'] is True
assert launch_points[0]['mobileLaunchURL'] == content_metadata_item['enrollment_url']

@ddt.data(
(
{
'title': 'Hippity Hop',
'course_runs': [
{
'start': '2014-02-05T05:00:00Z',
'end': '2050-12-31T18:00:00Z',
'pacing_type': 'instructor_paced',
'availability': 'Current',
}
],
'short_description': 'Watch the rabbits roam.',
'full_description': 'Rabbits explore their new garden home.',
},
'Pacing: Instructor-Paced. Starts: February 2014, Ends: December 2050. Rabbits explore their new '
'garden home.',
),
(
{
'title': 'Happy Bunny Course',
'course_runs': [
{
'start': '2115-02-05T05:00:00Z',
'end': '2151-12-31T18:00:00Z',
'pacing_type': 'self_paced',
'availability': 'Archived',
}
],
'short_description': 'The bunnies are delighted.',
},
'Pacing: Self-Paced. Starts: February 2115, Ends: December 2151. Enrollment is closed. The bunnies are '
'delighted.',
),
(
{
'title': 'Rabbit Care',
'course_runs': [
{
'pacing_type': 'instructor_paced',
'availability': 'Archived',
}
],
'full_description': 'In depth discussion of rabbit care and feeding.',
},
'Pacing: Instructor-Paced. Enrollment is closed. In depth discussion of rabbit care and feeding.',
),
(
{
'title': 'Acres of Carrots',
'course_runs': [
{
'start': '2216-02-05T05:00:00Z',
'pacing_type': 'instructor_paced',
'availability': 'Current',
}
],
'short_description': 'Learn to grow this colorful veggie.',
'full_description': 'Carrots are great. Rabbits love them. Come learn about growing carrots.',
},
'Pacing: Instructor-Paced. Starts: February 2216. Carrots are great. Rabbits love them. Come learn about '
'growing carrots.',
),
(
{
'title': 'Bunnies are cute',
'course_runs': [
{
'end': '2317-02-05T05:00:00Z',
'pacing_type': 'instructor_paced',
'availability': 'Current',
}
],
'short_description': 'Yep.',
},
'Pacing: Instructor-Paced. Ends: February 2317. Yep.',
),
(
{
},
'',
),
)
@responses.activate
@ddt.unpack
def test_transform_course_description(self, course, expected_description):
"""
Transforming a course description includes the pacing and start date.
"""
exporter = SapSuccessFactorsContentMetadataExporter('fake-user', self.config)
assert exporter.transform_description(course) == [
{
'locale': 'English',
'value': expected_description
}
]

0 comments on commit 58a0540

Please sign in to comment.