-
Notifications
You must be signed in to change notification settings - Fork 4.3k
(BB-1389) Update enrollment serializer and Add problem submission history endpoint #20948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ba4ae79
3f47481
6139b66
a7dcbcb
5bc4415
cd11d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,13 @@ | |
|
|
||
| import logging | ||
|
|
||
| from django.core.exceptions import PermissionDenied | ||
| from rest_framework import serializers | ||
| from xmodule.modulestore.django import modulestore | ||
|
|
||
| from common.djangoapps.course_modes.models import CourseMode | ||
| from common.djangoapps.student.models import CourseEnrollment | ||
| from lms.djangoapps.grades.course_grade_factory import CourseGradeFactory | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
@@ -83,15 +86,49 @@ class CourseEnrollmentSerializer(serializers.ModelSerializer): | |
|
|
||
| """ | ||
| course_details = CourseSerializer(source="course_overview") | ||
| user = serializers.SerializerMethodField('get_username') | ||
| user = serializers.SerializerMethodField("get_username") | ||
| finished = serializers.SerializerMethodField() | ||
| grading = serializers.SerializerMethodField() | ||
|
|
||
| def get_username(self, model): | ||
| """Retrieves the username from the associated model.""" | ||
| return model.username | ||
|
|
||
| class Meta: | ||
| def get_finished(self, model): | ||
| """Retrieve finished course.""" | ||
| course = modulestore().get_course(model.course_id) | ||
| if course: | ||
| try: | ||
| coursegrade = CourseGradeFactory().read(model.user, course).passed | ||
| except PermissionDenied: | ||
| return False | ||
| return coursegrade | ||
| return False | ||
|
|
||
| def get_grading(self, model): | ||
| """Retrieve course grade.""" | ||
| course = modulestore().get_course(model.course_id) | ||
| course_grade = None | ||
| summary = [] | ||
| current_grade = 0 | ||
| if course: | ||
| try: | ||
| course_grade = CourseGradeFactory().read(model.user, course) | ||
| current_grade = int(course_grade.percent * 100) | ||
| for section in course_grade.summary.get(u'section_breakdown'): | ||
| if section.get(u'prominent'): | ||
| summary.append(section) | ||
| except PermissionDenied: | ||
| pass | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't do anything if it fails permission checks, should we instead return an empty response?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The values are initialized at the beginning of the method. If there's a permission issue the response would be: {
'current_grade': 0,
'certificate_eligible': False,
'summary': [],
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'm wondering if it would be better to imply an empty grade like that, or to return an empty list entirely.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kaizoku I think to avoid issues on the frontend it's better to return an empty grade like this. That way the front-end code doesn't have to change if there's a permission error.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, perhaps the edX reviewer will have some ideas on this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ormsbee Can you comment on this change? Is this approach feasible? |
||
| return [ | ||
| {u'current_grade': current_grade, | ||
| u'certificate_eligible': course_grade.passed if course_grade else False, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not consistent with the certificates API, so it can return different values than generated grade reports.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for catching this @Agrendalath possibly one of the changes that have been impacting this PR since it has been created. I'll schedule some time to look into this, resolve conflicts and fix tests. |
||
| u'summary': summary} | ||
| ] | ||
|
|
||
| class Meta(object): | ||
| model = CourseEnrollment | ||
| fields = ('created', 'mode', 'is_active', 'course_details', 'user') | ||
| fields = ('created', 'mode', 'is_active', 'course_details', 'user', 'finished', 'grading') | ||
| lookup_field = 'username' | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also specify the method name as is done for the user field.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kaizoku we can't do this because there's a quality error raised:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah gotcha, my mistake.