diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index c1a51ede32..43e9b9b791 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -126,10 +126,9 @@ def course_image_url(course): url += '/' + course.course_image else: url += '/images/course_image.jpg' - elif course.course_image == '': - # if course_image is empty the url will be blank as location - # of the course_image does not exist - url = '' + elif not course.course_image: + # if course_image is empty, use the default image url from settings + url = settings.STATIC_URL + settings.DEFAULT_COURSE_ABOUT_IMAGE_URL else: loc = StaticContent.compute_location(course.id, course.course_image) url = StaticContent.serialize_asset_key_with_slash(loc) diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index ba9331fa6b..1f22edee36 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -794,16 +794,19 @@ class TestHtmlModifiers(ModuleStoreTestCase): self.assertTrue(url.startswith('/static/toy_course_dir/')) self.course.static_asset_path = "" + @override_settings(DEFAULT_COURSE_ABOUT_IMAGE_URL='test.png') + @override_settings(STATIC_URL='static/') @ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split) def test_course_image_for_split_course(self, store): """ - for split courses if course_image is empty then course_image_url will be blank + for split courses if course_image is empty then course_image_url will be + the default image url defined in settings """ self.course = CourseFactory.create(default_store=store) self.course.course_image = '' url = course_image_url(self.course) - self.assertEqual('', url) + self.assertEqual('static/test.png', url) def test_get_course_info_section(self): self.course.static_asset_path = "toy_course_dir" diff --git a/lms/envs/aws.py b/lms/envs/aws.py index ff2676cca3..221b785966 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -131,6 +131,9 @@ if STATIC_URL_BASE: if not STATIC_URL.endswith("/"): STATIC_URL += "/" +# DEFAULT_COURSE_ABOUT_IMAGE_URL specifies the default image to show for courses that don't provide one +DEFAULT_COURSE_ABOUT_IMAGE_URL = ENV_TOKENS.get('DEFAULT_COURSE_ABOUT_IMAGE_URL', DEFAULT_COURSE_ABOUT_IMAGE_URL) + # MEDIA_ROOT specifies the directory where user-uploaded files are stored. MEDIA_ROOT = ENV_TOKENS.get('MEDIA_ROOT', MEDIA_ROOT) MEDIA_URL = ENV_TOKENS.get('MEDIA_URL', MEDIA_URL) diff --git a/lms/envs/common.py b/lms/envs/common.py index a030bf9e51..80f42ff210 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -843,6 +843,7 @@ STATICFILES_DIRS = [ ] FAVICON_PATH = 'images/favicon.ico' +DEFAULT_COURSE_ABOUT_IMAGE_URL = 'images/pencils.jpg' # User-uploaded content MEDIA_ROOT = '/edx/var/edxapp/media/' diff --git a/lms/static/images/pencils.jpg b/lms/static/images/pencils.jpg new file mode 100644 index 0000000000..ae18b86276 Binary files /dev/null and b/lms/static/images/pencils.jpg differ