Commit be9a8444 by Awais Committed by Awais Qureshi

Update script to import the short-desc-override.

Add property to show the override value.

EDUCATOR-704
parent 9bd338d0
...@@ -98,7 +98,8 @@ def create_course_runs(meta_data_course, publisher_course): ...@@ -98,7 +98,8 @@ def create_course_runs(meta_data_course, publisher_course):
'language': canonical_course_run.language, 'pacing_type': canonical_course_run.pacing_type, 'language': canonical_course_run.language, 'pacing_type': canonical_course_run.pacing_type,
'length': canonical_course_run.weeks_to_complete, 'length': canonical_course_run.weeks_to_complete,
'card_image_url': canonical_course_run.card_image_url, 'card_image_url': canonical_course_run.card_image_url,
'lms_course_id': canonical_course_run.key 'lms_course_id': canonical_course_run.key,
'short_description_override': canonical_course_run.short_description_override
} }
publisher_course_run, created = CourseRun.objects.update_or_create( publisher_course_run, created = CourseRun.objects.update_or_create(
......
...@@ -106,7 +106,8 @@ class CreateCoursesTests(TestCase): ...@@ -106,7 +106,8 @@ class CreateCoursesTests(TestCase):
# create multiple course-runs against course. # create multiple course-runs against course.
course_runs = CourseRunFactory.create_batch( course_runs = CourseRunFactory.create_batch(
3, course=self.course, transcript_languages=transcript_languages, 3, course=self.course, transcript_languages=transcript_languages,
language=transcript_languages[0] language=transcript_languages[0],
short_description_override='Testing description'
) )
canonical_course_run = course_runs[0] canonical_course_run = course_runs[0]
...@@ -274,6 +275,9 @@ class CreateCoursesTests(TestCase): ...@@ -274,6 +275,9 @@ class CreateCoursesTests(TestCase):
self.assertEqual(publisher_course_run.card_image_url, metadata_course_run.card_image_url) self.assertEqual(publisher_course_run.card_image_url, metadata_course_run.card_image_url)
self.assertEqual(publisher_course_run.language, metadata_course_run.language) self.assertEqual(publisher_course_run.language, metadata_course_run.language)
self.assertEqual(publisher_course_run.lms_course_id, metadata_course_run.key) self.assertEqual(publisher_course_run.lms_course_id, metadata_course_run.key)
self.assertEqual(
publisher_course_run.short_description_override, metadata_course_run.short_description_override
)
# assert ManytoMany fields. # assert ManytoMany fields.
self.assertEqual( self.assertEqual(
......
...@@ -204,6 +204,15 @@ class Course(TimeStampedModel, ChangedByMixin): ...@@ -204,6 +204,15 @@ class Course(TimeStampedModel, ChangedByMixin):
return None return None
@property
def course_short_description(self):
course_run = self.course_runs.filter(course_run_state__name=CourseRunStateChoices.Published).first()
if course_run and course_run.short_description_override:
return course_run.short_description_override
return self.short_description
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."""
......
...@@ -55,6 +55,7 @@ class CourseRunFactory(factory.DjangoModelFactory): ...@@ -55,6 +55,7 @@ class CourseRunFactory(factory.DjangoModelFactory):
preview_url = FuzzyText(prefix='https://example.com/') preview_url = FuzzyText(prefix='https://example.com/')
contacted_partner_manager = FuzzyChoice((True, False)) contacted_partner_manager = FuzzyChoice((True, False))
video_language = factory.Iterator(LanguageTag.objects.all()) video_language = factory.Iterator(LanguageTag.objects.all())
short_description_override = FuzzyText()
class Meta: class Meta:
model = CourseRun model = CourseRun
......
...@@ -345,6 +345,15 @@ class CourseTests(TestCase): ...@@ -345,6 +345,15 @@ class CourseTests(TestCase):
# Verify that property returns course image field url. # Verify that property returns course image field url.
self.assertEqual(self.course.course_image_url, self.course.image.url) self.assertEqual(self.course.course_image_url, self.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)
# Create a published course-run with card_image_url.
course_run = factories.CourseRunFactory(course=self.course)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
self.assertEqual(self.course.course_short_description, course_run.short_description_override)
class SeatTests(TestCase): class SeatTests(TestCase):
""" Tests for the publisher `Seat` model. """ """ Tests for the publisher `Seat` model. """
......
...@@ -2011,6 +2011,19 @@ class CourseDetailViewTests(TestCase): ...@@ -2011,6 +2011,19 @@ 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):
"""
Test that pages shows the override short description.
"""
description = 'Testing short description'
self._assign_user_permission()
course_run = factories.CourseRunFactory(
course=self.course, short_description_override=description
)
factories.CourseRunStateFactory(course_run=course_run, name=CourseRunStateChoices.Published)
response = self.client.get(self.detail_page_url)
self.assertContains(response, description)
def _assign_user_permission(self): def _assign_user_permission(self):
""" Assign permissions.""" """ Assign permissions."""
self.user.groups.add(self.organization_extension.group) self.user.groups.add(self.organization_extension.group)
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
{% trans "Short Description" %} {% trans "Short Description" %}
</div> </div>
<div class="current short_description"> <div class="current short_description">
{% with object.short_description as field %} {% with object.course_short_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