Skip to content

Commit

Permalink
Merge pull request #603 from edx/iahmad/ENT-2428-Thumbnails-not-being…
Browse files Browse the repository at this point in the history
…-displayed-in-Cornerstone

ENT-2428: Updated image url field for cornerstone and degreed
  • Loading branch information
irfanuddinahmad authored Oct 28, 2019
2 parents a1974db + 37dfc14 commit 4aa6362
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Change Log
Unreleased
----------
[2.0.9] - 2019-10-28
---------------------

* Updated image url field in content metadata export for cornerstone and degreed

[2.0.8] - 2019-10-22
---------------------

Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = "2.0.8"
__version__ = "2.0.9"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from enterprise.utils import get_closest_course_run, get_language_code
from integrated_channels.integrated_channel.exporters.content_metadata import ContentMetadataExporter
from integrated_channels.utils import get_image_url

LOGGER = getLogger(__name__)

Expand All @@ -33,7 +34,7 @@ class CornerstoneContentMetadataExporter(ContentMetadataExporter): # pylint: di
'ID': 'key',
'Title': 'title',
'Description': 'description',
'Thumbnail': 'card_image_url',
'Thumbnail': 'image',
'URL': 'enrollment_url',
'IsActive': 'is_active',
'LastModifiedUTC': 'modified',
Expand Down Expand Up @@ -98,6 +99,12 @@ def transform_estimated_hours(self, content_metadata_item):

return duration

def transform_image(self, content_metadata_item):
"""
Return the image URI of the content item.
"""
return get_image_url(content_metadata_item)

def transform_languages(self, content_metadata_item):
"""
Return the languages supported by course or `English` as default if no languages found.
Expand Down
10 changes: 2 additions & 8 deletions integrated_channels/degreed/exporters/content_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from enterprise.utils import get_closest_course_run, get_course_run_duration_info
from integrated_channels.integrated_channel.exporters.content_metadata import ContentMetadataExporter
from integrated_channels.utils import strip_html_tags
from integrated_channels.utils import get_image_url, strip_html_tags

LOGGER = getLogger(__name__)

Expand Down Expand Up @@ -78,13 +78,7 @@ def transform_image(self, content_metadata_item):
"""
Return the image URI of the content item.
"""
image_url = ''
if content_metadata_item['content_type'] in ['course', 'program']:
image_url = content_metadata_item.get('card_image_url')
elif content_metadata_item['content_type'] == 'courserun':
image_url = content_metadata_item.get('image_url')

return image_url
return get_image_url(content_metadata_item)

def transform_program_key(self, content_metadata_item):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
UNIX_MAX_DATE_STRING,
UNIX_MIN_DATE_STRING,
current_time_is_in_interval,
get_image_url,
parse_datetime_to_epoch_millis,
)

Expand Down Expand Up @@ -112,13 +113,7 @@ def transform_image(self, content_metadata_item):
"""
Return the image URI of the content item.
"""
image_url = ''
if content_metadata_item['content_type'] == 'program':
image_url = content_metadata_item.get('card_image_url')
elif content_metadata_item['content_type'] in ['course', 'courserun']:
image_url = content_metadata_item.get('image_url')

return image_url
return get_image_url(content_metadata_item)

def transform_launch_points(self, content_metadata_item):
"""
Expand Down
13 changes: 13 additions & 0 deletions integrated_channels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ def strfdelta(tdelta, fmt='{D:02}d {H:02}h {M:02}m {S:02}s', input_type='timedel
values[field], remainder = divmod(remainder, constants[field])

return f.format(fmt, **values)


def get_image_url(content_metadata_item):
"""
Return the image URI of the content item.
"""
image_url = ''
if content_metadata_item['content_type'] == 'program':
image_url = content_metadata_item.get('card_image_url')
elif content_metadata_item['content_type'] in ['course', 'courserun']:
image_url = content_metadata_item.get('image_url')

return image_url
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,64 @@ def test_transform_subjects(self, item_subjects, expected_subjects):
item_content_metadata = self._merge_dicts(FAKE_SEARCH_ALL_COURSE_RESULT_3, item_subjects)
exporter = CornerstoneContentMetadataExporter('fake-user', self.config)
assert sorted(exporter.transform_subjects(item_content_metadata)) == sorted(expected_subjects)

@ddt.data(
(
{
'aggregation_key': 'course:edX+DemoX',
'title': 'edX Demonstration Course',
'key': 'edX+DemoX',
'content_type': 'course',
'image_url': 'https://edx.devstack.lms:18000/'
'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg',
'short_description': 'Some short description.',
'full_description': 'Detailed description of edx demo course.',
},
'https://edx.devstack.lms:18000/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg'
),
(
{
'number': 'DemoX',
'org': 'edX',
'seat_types': ['verified', 'audit'],
'key': 'course-v1:edX+DemoX+Demo_Course',
'availability': 'Current',
'title': 'edX Demonstration Course',
'content_type': 'courserun',
'image_url': 'https://edx.devstack.lms:18000/'
'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg',
},
'https://edx.devstack.lms:18000/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg'
),
(
{
'uuid': '5742ec8d-25ce-43b7-a158-6dad82034ca2',
'title': 'edX Demonstration program',
'published': True,
'language': [],
'type': 'Verified Certificate',
'status': 'active',
'content_type': 'program',
'card_image_url': 'https://edx.devstack.discovery/'
'media/programs/banner_images/5742ec8d-25ce-43b7-a158-6dad82034ca2.jpg',
},
'https://edx.devstack.discovery/media/programs/banner_images/5742ec8d-25ce-43b7-a158-6dad82034ca2.jpg',
),
(
{
'title': 'INVALID COURSE',
'content_type': 'INVALID-CONTENT_TYPE',
},
'',
),
)
@responses.activate
@ddt.unpack
def test_transform_image(self, content_metadata_item, expected_thumbnail_url):
"""
Transforming a image gives back the thumbnail URI by checking the
content type of the provided `content_metadata_item`.
"""
exporter = CornerstoneContentMetadataExporter('fake-user', self.config)
assert exporter.transform_image(content_metadata_item) == expected_thumbnail_url
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def test_content_exporter_export(self):
'title': 'edX Demonstration Course',
'key': 'edX+DemoX',
'content_type': 'course',
'card_image_url': 'https://edx.devstack.lms:18000/'
'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg',
'image_url': 'https://edx.devstack.lms:18000/'
'asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.jpg',
'short_description': 'Some short description.',
'full_description': 'Detailed description of edx demo course.',
},
Expand Down

0 comments on commit 4aa6362

Please sign in to comment.