Commit 5e3d372a by Clinton Blackburn

Updated course image logic for Publisher

All courses must have their own associated image. Images are no longer pulled from the URL associated with the published course run.

EDUCATOR-1462
parent d771c66f
......@@ -207,21 +207,6 @@ class Course(TimeStampedModel, ChangedByMixin):
return None
@property
def course_image_url(self):
"""
Return course image url.
"""
if self.image:
return self.image.url
course_run = self.course_runs.filter(course_run_state__name=CourseRunStateChoices.Published).first()
if course_run and course_run.card_image_url:
return course_run.card_image_url
return None
@property
def course_short_description(self):
course_run = self.course_runs.filter(course_run_state__name=CourseRunStateChoices.Published).first()
......
......@@ -146,8 +146,8 @@
<div class="heading course-image-heading">
{% trans "Course Image" %}
</div>
{% if object.course_image_url %}
<img class="course-image" src="{{ object.course_image_url }}" alt="{% trans 'Course Image' %}">
{% if object.image %}
<img class="course-image" src="{{ object.image.url }}" alt="{% trans 'Course Image' %}">
{% else %}
{% trans "(Required) Not yet added" %}
{% endif %}
......
......@@ -207,15 +207,15 @@
{% trans "Course Image" %}
</div>
<div>
{% if not object.course_image_url %}
{% trans "(Required) Not yet added" %}
{% else %}
<img class="course-image" src="{{ object.course_image_url }}" alt="{% trans 'Course Image' %}">
{% if object.course.image %}
<img class="course-image" src="{{ object.course.image.url }}" alt="{% trans 'Course Image' %}">
<div class="download-image">
<a download href="{{ object.course_image_url }}">
<a download href="{{ object.course.image.url }}">
{% trans "Download" %}
</a>
</div>
{% else %}
{% trans "(Required) Not yet added" %}
{% endif %}
</div>
</div>
......
......@@ -327,21 +327,6 @@ class CourseTests(TestCase):
self.assertEqual(self.user1, self.course2.publisher)
def test_course_image_url(self):
course = factories.CourseFactory(image=None)
assert course.course_image_url is None
course_run = factories.CourseRunFactory(course=course)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
course_run.card_image_url = 'http://example.com/test.jpg'
course_run.save()
assert course.course_image_url == course_run.card_image_url
# Create a course image.
course.image = make_image_file('test_banner1.jpg')
course.save()
assert course.course_image_url == course.image.url
def test_short_description_override(self):
""" Verify that the property returns the short_description. """
self.assertEqual(self.course.short_description, self.course.course_short_description)
......@@ -355,6 +340,7 @@ class CourseTests(TestCase):
self.assertEqual(self.course.full_description, self.course.course_full_description)
course_run = factories.CourseRunFactory(course=self.course)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
self.assertEqual(self.course.course_full_description, course_run.full_description_override)
......
......@@ -5,7 +5,6 @@ from unittest import mock
import ddt
from django.test import TestCase
from course_discovery.apps.core.tests.helpers import make_image_file
from course_discovery.apps.course_metadata.choices import CourseRunPacing
from course_discovery.apps.course_metadata.tests.factories import (OrganizationFactory, PersonFactory,
PersonSocialNetworkFactory, PositionFactory)
......@@ -161,16 +160,6 @@ class CourseRunWrapperTests(TestCase):
""" Verify that the wrapper return the course team admin. """
self.assertEqual(self.wrapped_course_run.course_team_admin, self.course.course_team_admin)
def test_course_image_url(self):
course_run = factories.CourseRunFactory(course__image=None)
wrapped_course_run = CourseRunWrapper(course_run)
assert wrapped_course_run.course_image_url is None
course = course_run.course
course.image = make_image_file('test_banner1.jpg')
course.save()
assert wrapped_course_run.course_image_url == course.image.url
def test_course_staff(self):
"""Verify that the wrapper return staff list."""
staff = PersonFactory()
......
......@@ -187,10 +187,6 @@ class CourseRunWrapper(BaseWrapper):
return self.wrapped_obj.course.course_team_admin
@property
def course_image_url(self):
return self.wrapped_obj.course.course_image_url
@property
def course_staff(self):
staff_list = []
for staff in self.wrapped_obj.staff.all():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment