From 1185fff1ec4e8bbff3747581265a7996b20aba64 Mon Sep 17 00:00:00 2001 From: Clinton Blackburn Date: Tue, 29 Mar 2016 23:18:23 -0400 Subject: [PATCH] Added pacing field Course API ECOM-3994 --- lms/djangoapps/course_api/serializers.py | 1 + .../course_api/tests/test_serializers.py | 14 +++++++++++ lms/djangoapps/course_api/views.py | 4 +++- .../migrations/0010_auto_20160329_2317.py | 23 +++++++++++++++++++ .../content/course_overviews/models.py | 14 ++++++++++- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 openedx/core/djangoapps/content/course_overviews/migrations/0010_auto_20160329_2317.py diff --git a/lms/djangoapps/course_api/serializers.py b/lms/djangoapps/course_api/serializers.py index a744658f8f..ec5fee7396 100644 --- a/lms/djangoapps/course_api/serializers.py +++ b/lms/djangoapps/course_api/serializers.py @@ -55,6 +55,7 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth start = serializers.DateTimeField() start_display = serializers.CharField() start_type = serializers.CharField() + pacing = serializers.CharField() # 'course_id' is a deprecated field, please use 'id' instead. course_id = serializers.CharField(source='id', read_only=True) diff --git a/lms/djangoapps/course_api/tests/test_serializers.py b/lms/djangoapps/course_api/tests/test_serializers.py index 795c1f4208..244826cf6f 100644 --- a/lms/djangoapps/course_api/tests/test_serializers.py +++ b/lms/djangoapps/course_api/tests/test_serializers.py @@ -2,8 +2,10 @@ Test data created by CourseSerializer and CourseDetailSerializer """ +from __future__ import unicode_literals from datetime import datetime +import ddt from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from rest_framework.test import APIRequestFactory @@ -18,6 +20,7 @@ from ..serializers import CourseSerializer, CourseDetailSerializer from .mixins import CourseApiFactoryMixin +@ddt.ddt class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): """ Test CourseSerializer @@ -54,6 +57,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): 'enrollment_end': u'2015-07-15T00:00:00Z', 'blocks_url': u'http://testserver/api/courses/v1/blocks/?course_id=edX%2Ftoy%2F2012_Fall', 'effort': u'6 hours', + 'pacing': 'instructor', # 'course_id' is a deprecated field, please use 'id' instead. 'course_id': u'edX/toy/2012_Fall', @@ -101,6 +105,16 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase): self.assertEqual(result['start_type'], u'empty') self.assertIsNone(result['start_display']) + @ddt.unpack + @ddt.data( + (True, 'self'), + (False, 'instructor'), + ) + def test_pacing(self, self_paced, expected_pacing): + course = self.create_course(self_paced=self_paced) + result = self._get_result(course) + self.assertEqual(result['pacing'], expected_pacing) + class TestCourseDetailSerializer(TestCourseSerializer): # pylint: disable=test-inherits-tests """ diff --git a/lms/djangoapps/course_api/views.py b/lms/djangoapps/course_api/views.py index c30d76c6a4..f2c09d1874 100644 --- a/lms/djangoapps/course_api/views.py +++ b/lms/djangoapps/course_api/views.py @@ -52,6 +52,7 @@ class CourseDetailView(DeveloperErrorViewMixin, RetrieveAPIView): * `"string"`: manually set * `"timestamp"`: generated form `start` timestamp * `"empty"`: the start date should not be shown + * pacing: Course pacing. Possible values: instructor, self Deprecated fields: @@ -94,7 +95,8 @@ class CourseDetailView(DeveloperErrorViewMixin, RetrieveAPIView): "overview: "

A verbose description of the course.

" "start": "2015-07-17T12:00:00Z", "start_display": "July 17, 2015", - "start_type": "timestamp" + "start_type": "timestamp", + "pacing": "instructor" } """ diff --git a/openedx/core/djangoapps/content/course_overviews/migrations/0010_auto_20160329_2317.py b/openedx/core/djangoapps/content/course_overviews/migrations/0010_auto_20160329_2317.py new file mode 100644 index 0000000000..c699d9096e --- /dev/null +++ b/openedx/core/djangoapps/content/course_overviews/migrations/0010_auto_20160329_2317.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course_overviews', '0009_readd_facebook_url'), + ] + + operations = [ + migrations.RemoveField( + model_name='courseoverview', + name='facebook_url', + ), + migrations.AddField( + model_name='courseoverview', + name='self_paced', + field=models.BooleanField(default=False), + ), + ] diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index 3e1edf2080..ce8ccf53cc 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -45,7 +45,7 @@ class CourseOverview(TimeStampedModel): app_label = 'course_overviews' # IMPORTANT: Bump this whenever you modify this model and/or add a migration. - VERSION = 3 + VERSION = 4 # Cache entry versioning. version = IntegerField() @@ -98,6 +98,7 @@ class CourseOverview(TimeStampedModel): short_description = TextField(null=True) course_video_url = TextField(null=True) effort = TextField(null=True) + self_paced = BooleanField(default=False) @classmethod def _create_from_course(cls, course): @@ -181,6 +182,7 @@ class CourseOverview(TimeStampedModel): short_description=CourseDetails.fetch_about_attribute(course.id, 'short_description'), effort=CourseDetails.fetch_about_attribute(course.id, 'effort'), course_video_url=CourseDetails.fetch_video_url(course.id), + self_paced=course.self_paced, ) @classmethod @@ -551,6 +553,16 @@ class CourseOverview(TimeStampedModel): return self.apply_cdn_to_urls(urls) + @property + def pacing(self): + """ Returns the pacing for the course. + + Potential values: + self: Self-paced courses + instructor: Instructor-led courses + """ + return 'self' if self.self_paced else 'instructor' + def apply_cdn_to_urls(self, image_urls): """ Given a dict of resolutions -> urls, return a copy with CDN applied.