Files
edx-platform/common/djangoapps/course_about/views.py
stephensanchez 1e7d567b58 Initial framework for the Course About API.
ECOM-248 Course Info API. Basic functionality implemented.

ECOM-248 adding factory for about descriptor and test cases for course info api

ECOM-248 adding test cases for couse info api.

ECOM-248 re-factoring code. updating test cases.

Tests for course_about data module

ECOM-248 Adding test cases for the exceptions.

ECOM-248 re-factoring code. fixing quality issues.

ECOM-248 fixing test cases and moved parse video method into utils.

added github username in authors

ECOM-248 removed merging issue of test_data

ECOM-248 removed unused files
2015-01-07 20:03:54 +05:00

64 lines
2.1 KiB
Python

"""
Implementation of the RESTful endpoints for the Course About API.
"""
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView
from course_about import api
from rest_framework import status
from rest_framework.response import Response
from course_about.errors import CourseNotFoundError, CourseAboutError
class CourseAboutThrottle(UserRateThrottle):
"""Limit the number of requests users can make to the Course About API."""
# TODO Limit based on expected throughput # pylint: disable=fixme
rate = '50/second'
class CourseAboutView(APIView):
""" RESTful Course About API view.
Used to retrieve JSON serialized Course About information.
"""
authentication_classes = []
permission_classes = []
throttle_classes = CourseAboutThrottle,
def get(self, request, course_id=None): # pylint: disable=unused-argument
"""Read course information.
HTTP Endpoint for course info api.
Args:
Course Id = URI element specifying the course location. Course information will be
returned for this particular course.
Return:
A JSON serialized representation of the course information
"""
try:
return Response(api.get_course_about_details(course_id))
except CourseNotFoundError:
return Response(
status=status.HTTP_404_NOT_FOUND,
data={
"message": (
u"An error occurred while retrieving course information"
u" for course '{course_id}' no course found"
).format(course_id=course_id)
}
)
except CourseAboutError:
return Response(
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
data={
"message": (
u"An error occurred while retrieving course information"
u" for course '{course_id}'"
).format(course_id=course_id)
}
)