Commit 1156bd67 by Awais Committed by Awais Qureshi

Adding properties to show override fields on course detail pages.

EDUCATOR-818
parent 988b3a58
...@@ -213,6 +213,24 @@ class Course(TimeStampedModel, ChangedByMixin): ...@@ -213,6 +213,24 @@ class Course(TimeStampedModel, ChangedByMixin):
return self.short_description return self.short_description
@property
def course_full_description(self):
course_run = self.course_runs.filter(course_run_state__name=CourseRunStateChoices.Published).first()
if course_run and course_run.full_description_override:
return course_run.full_description_override
return self.full_description
@property
def course_title(self):
course_run = self.course_runs.filter(course_run_state__name=CourseRunStateChoices.Published).first()
if course_run and course_run.title_override:
return course_run.title_override
return self.title
class CourseRun(TimeStampedModel, ChangedByMixin): class CourseRun(TimeStampedModel, ChangedByMixin):
""" Publisher CourseRun model. It contains fields related to the course run intake form.""" """ Publisher CourseRun model. It contains fields related to the course run intake form."""
......
...@@ -349,11 +349,26 @@ class CourseTests(TestCase): ...@@ -349,11 +349,26 @@ class CourseTests(TestCase):
""" Verify that the property returns the short_description. """ """ Verify that the property returns the short_description. """
self.assertEqual(self.course.short_description, self.course.course_short_description) self.assertEqual(self.course.short_description, self.course.course_short_description)
# Create a published course-run with card_image_url.
course_run = factories.CourseRunFactory(course=self.course) course_run = factories.CourseRunFactory(course=self.course)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published) factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
self.assertEqual(self.course.course_short_description, course_run.short_description_override) self.assertEqual(self.course.course_short_description, course_run.short_description_override)
def test_full_description_override(self):
""" Verify that the property returns the full_description. """
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)
def test_title_override(self):
""" Verify that the property returns the title. """
self.assertEqual(self.course.title, self.course.course_title)
course_run = factories.CourseRunFactory(course=self.course)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
self.assertEqual(self.course.course_title, course_run.title_override)
class SeatTests(TestCase): class SeatTests(TestCase):
""" Tests for the publisher `Seat` model. """ """ Tests for the publisher `Seat` model. """
......
...@@ -1728,6 +1728,7 @@ class CourseDetailViewTests(TestCase): ...@@ -1728,6 +1728,7 @@ class CourseDetailViewTests(TestCase):
self.assertContains(response, self.course.faq) self.assertContains(response, self.course.faq)
self.assertContains(response, self.course.video_link) self.assertContains(response, self.course.video_link)
self.assertContains(response, self.course.syllabus) self.assertContains(response, self.course.syllabus)
self.assertEqual(response.context['breadcrumbs'][1]['slug'], self.course.title)
def test_details_page_with_course_runs_lms_id(self): def test_details_page_with_course_runs_lms_id(self):
""" Test that user can see course runs with lms-id on course detail page. """ """ Test that user can see course runs with lms-id on course detail page. """
...@@ -2013,18 +2014,25 @@ class CourseDetailViewTests(TestCase): ...@@ -2013,18 +2014,25 @@ class CourseDetailViewTests(TestCase):
self.assertEqual(response.context['most_recent_revision_id'], current_user_revision) self.assertEqual(response.context['most_recent_revision_id'], current_user_revision)
self.assertTrue(response.context['accept_all_button']) self.assertTrue(response.context['accept_all_button'])
def test_detail_page_with_override_short_description(self): def test_detail_page_with_override_values(self):
""" """
Test that pages shows the override short description. Test that pages shows the override short description, full description and title.
""" """
description = 'Testing short description' short_description = 'Testing short description'
full_description = 'Testing full description'
title = 'Testing title'
self._assign_user_permission() self._assign_user_permission()
course_run = factories.CourseRunFactory( course_run = factories.CourseRunFactory(
course=self.course, short_description_override=description course=self.course, short_description_override=short_description,
full_description_override=full_description, title_override=title
) )
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published) factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
response = self.client.get(self.detail_page_url) response = self.client.get(self.detail_page_url)
self.assertContains(response, description) self.assertContains(response, short_description)
self.assertContains(response, full_description)
self.assertContains(response, title)
self.assertEqual(response.context['breadcrumbs'][1]['slug'], title)
def _assign_user_permission(self): def _assign_user_permission(self):
""" Assign permissions.""" """ Assign permissions."""
......
...@@ -446,7 +446,7 @@ class CourseDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMixi ...@@ -446,7 +446,7 @@ class CourseDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMixi
context['breadcrumbs'] = make_bread_crumbs( context['breadcrumbs'] = make_bread_crumbs(
[ [
(reverse('publisher:publisher_courses'), 'Courses'), (reverse('publisher:publisher_courses'), 'Courses'),
(None, course.title), (None, course.course_title),
] ]
) )
context['comment_object'] = course context['comment_object'] = course
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
<div class="heading"> <div class="heading">
{% trans "Course Title" %} {% trans "Course Title" %}
</div> </div>
<div class="current title">{{ object.title }}</div> <div class="current title">{{ object.course_title }}</div>
<div class="show-diff"></div> <div class="show-diff"></div>
</div> </div>
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
{% trans "Long Description" %} {% trans "Long Description" %}
</div> </div>
<div class="current full_description"> <div class="current full_description">
{% with object.full_description as field %} {% with object.course_full_description as field %}
{% include "publisher/_render_required_field.html" %} {% include "publisher/_render_required_field.html" %}
{% endwith %} {% endwith %}
</div> </div>
......
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