Skip to content

Commit

Permalink
Added pacing field Course API
Browse files Browse the repository at this point in the history
ECOM-3994
  • Loading branch information
clintonb committed Mar 30, 2016
1 parent 84e88eb commit 3e5f143
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions lms/djangoapps/course_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
start = serializers.DateTimeField()
start_display = serializers.CharField()
start_type = serializers.CharField()
pacing = serializers.SerializerMethodField()

# 'course_id' is a deprecated field, please use 'id' instead.
course_id = serializers.CharField(source='id', read_only=True)

def get_pacing(self, course_overview):
return 'self' if course_overview.self_paced else 'instructor'

def get_blocks_url(self, course_overview):
"""
Get the representation for SerializerMethodField `blocks_url`
Expand Down
18 changes: 15 additions & 3 deletions lms/djangoapps/course_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Test data created by CourseSerializer and CourseDetailSerializer
"""
""" 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
Expand All @@ -18,6 +18,7 @@
from .mixins import CourseApiFactoryMixin


@ddt.ddt
class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase):
"""
Test CourseSerializer
Expand Down Expand Up @@ -54,6 +55,7 @@ def setUp(self):
'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',
Expand Down Expand Up @@ -101,6 +103,16 @@ def test_empty_start(self):
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
"""
Expand Down
4 changes: 3 additions & 1 deletion lms/djangoapps/course_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -94,7 +95,8 @@ class CourseDetailView(DeveloperErrorViewMixin, RetrieveAPIView):
"overview: "<p>A verbose description of the course.</p>"
"start": "2015-07-17T12:00:00Z",
"start_display": "July 17, 2015",
"start_type": "timestamp"
"start_type": "timestamp",
"pacing": "instructor"
}
"""

Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
4 changes: 3 additions & 1 deletion openedx/core/djangoapps/content/course_overviews/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Meta(object):
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()
Expand Down Expand Up @@ -98,6 +98,7 @@ class Meta(object):
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):
Expand Down Expand Up @@ -181,6 +182,7 @@ def _create_from_course(cls, course):
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
Expand Down

0 comments on commit 3e5f143

Please sign in to comment.