-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat: api function to delete learner's course grades #34410
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -534,6 +534,27 @@ def _emit_grade_calculated_event(grade): | |
def _cache_key(cls, course_id): | ||
return f"subsection_grades_cache.{course_id}" | ||
|
||
@classmethod | ||
def delete_subsection_grades_for_learner(cls, user_id, course_key): | ||
""" | ||
Clears Subsection grade override for a learner in a course | ||
Arguments: | ||
user_id: The user associated with the desired grade | ||
course_id: The id of the course associated with the desired grade | ||
""" | ||
try: | ||
deleted_count, deleted_obj = cls.objects.filter( | ||
user_id=user_id, | ||
course_id=course_key, | ||
).delete() | ||
get_cache(cls._CACHE_NAMESPACE)[cls._cache_key(course_key)].pop(user_id) | ||
if deleted_obj['grades.PersistentSubsectionGradeOverride'] is not None: | ||
PersistentSubsectionGradeOverride.clear_prefetched_overrides_for_learner(user_id, course_key) | ||
except KeyError: | ||
pass | ||
|
||
return deleted_count | ||
|
||
|
||
class PersistentCourseGrade(TimeStampedModel): | ||
""" | ||
|
@@ -681,6 +702,20 @@ def _cache_key(cls, course_id): | |
def _emit_grade_calculated_event(grade): | ||
events.course_grade_calculated(grade) | ||
|
||
@classmethod | ||
def delete_course_grade_for_learner(cls, course_id, user_id): | ||
""" | ||
Clears course grade for a learner in a course | ||
Arguments: | ||
course_id: The id of the course associated with the desired grade | ||
user_id: The user associated with the desired grade | ||
""" | ||
try: | ||
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. nice |
||
cls.objects.get(user_id=user_id, course_id=course_id).delete() | ||
get_cache(cls._CACHE_NAMESPACE)[cls._cache_key(course_id)].pop(user_id) | ||
except (PersistentCourseGrade.DoesNotExist, KeyError): | ||
pass | ||
|
||
@staticmethod | ||
def _emit_openedx_persistent_grade_summary_changed_event(course_id, user_id, grade): | ||
""" | ||
|
@@ -828,3 +863,7 @@ def _prepare_override_params(subsection_grade_model, override_data): | |
getattr(subsection_grade_model, field_name) | ||
) | ||
return cleaned_data | ||
|
||
@classmethod | ||
def clear_prefetched_overrides_for_learner(cls, user_id, course_key): | ||
get_cache(cls._CACHE_NAMESPACE).pop((user_id, str(course_key)), None) |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.