forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: grading rest api for authoring api (openedx#34854)
* feat: grading rest api for authoring api * fix: doc string api path
- Loading branch information
1 parent
b264988
commit 38320f8
Showing
5 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
cms/djangoapps/contentstore/rest_api/v0/serializers/authoring_grading.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
API Serializers for course grading | ||
""" | ||
|
||
from rest_framework import serializers | ||
|
||
|
||
class GradersSerializer(serializers.Serializer): | ||
""" Serializer for graders """ | ||
type = serializers.CharField() | ||
min_count = serializers.IntegerField() | ||
drop_count = serializers.IntegerField() | ||
short_label = serializers.CharField(required=False, allow_null=True, allow_blank=True) | ||
weight = serializers.IntegerField() | ||
id = serializers.IntegerField() | ||
|
||
|
||
class CourseGradingModelSerializer(serializers.Serializer): | ||
""" Serializer for course grading model data """ | ||
graders = GradersSerializer(many=True, allow_null=True, allow_empty=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
cms/djangoapps/contentstore/rest_api/v0/views/authoring_grading.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" API Views for course advanced settings """ | ||
|
||
import edx_api_doc_tools as apidocs | ||
from opaque_keys.edx.keys import CourseKey | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from cms.djangoapps.models.settings.course_grading import CourseGradingModel | ||
from common.djangoapps.student.auth import has_studio_read_access | ||
from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements | ||
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, verify_course_exists, view_auth_classes | ||
from ..serializers import CourseGradingModelSerializer | ||
|
||
|
||
@view_auth_classes(is_authenticated=True) | ||
class AuthoringGradingView(DeveloperErrorViewMixin, APIView): | ||
""" | ||
View for getting and setting the advanced settings for a course. | ||
""" | ||
@apidocs.schema( | ||
body=CourseGradingModelSerializer, | ||
parameters=[ | ||
apidocs.string_parameter("course_id", apidocs.ParameterLocation.PATH, description="Course ID"), | ||
], | ||
responses={ | ||
200: CourseGradingModelSerializer, | ||
401: "The requester is not authenticated.", | ||
403: "The requester cannot access the specified course.", | ||
404: "The requested course does not exist.", | ||
}, | ||
) | ||
@verify_course_exists() | ||
def post(self, request: Request, course_id: str): | ||
""" | ||
Update a course's grading. | ||
**Example Request** | ||
POST /api/contentstore/v0/course_grading/{course_id} | ||
**POST Parameters** | ||
The data sent for a post request should follow next object. | ||
Here is an example request data that updates the ``course_grading`` | ||
```json | ||
{ | ||
"graders": [ | ||
{ | ||
"type": "Homework", | ||
"min_count": 1, | ||
"drop_count": 0, | ||
"short_label": "", | ||
"weight": 100, | ||
"id": 0 | ||
} | ||
], | ||
"grade_cutoffs": { | ||
"A": 0.75, | ||
"B": 0.63, | ||
"C": 0.57, | ||
"D": 0.5 | ||
}, | ||
"grace_period": { | ||
"hours": 12, | ||
"minutes": 0 | ||
}, | ||
"minimum_grade_credit": 0.7, | ||
"is_credit_course": true | ||
} | ||
``` | ||
**Response Values** | ||
If the request is successful, an HTTP 200 "OK" response is returned, | ||
""" | ||
course_key = CourseKey.from_string(course_id) | ||
|
||
if not has_studio_read_access(request.user, course_key): | ||
self.permission_denied(request) | ||
|
||
if 'minimum_grade_credit' in request.data: | ||
update_credit_course_requirements.delay(str(course_key)) | ||
|
||
updated_data = CourseGradingModel.update_from_json(course_key, request.data, request.user) | ||
serializer = CourseGradingModelSerializer(updated_data) | ||
return Response(serializer.data) |