Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions submissions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,37 @@ def get_latest_score_for_submission(submission_uuid, read_replica=False):
return ScoreSerializer(score).data


def delete_student_item(student_id, course_id, item_id):
"""
EFischer - dev testing this on my devstack, will document more fully after trying proof-of-concept
"""
# Retrieve the student item
try:
student_item = StudentItem.objects.get(
student_id=student_id, course_id=course_id, item_id=item_id
)
student_item.delete()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: the default behavior in django is to cascade on delete (https://docs.djangoproject.com/en/1.8/ref/models/fields/, ctrl-F on_delete). Because of this behavior, this single lookup-then-delete will obliterate any trace of this item/student/user triplet in the submissions database.

One thing to investigate - how will this affect data in the assessment and workflow databases? Those entries are almost always keyed on submission['uuid'], so I'd imagine they'll just be orphaned, and possibly still included in a data dump? I'll keep digging there.

except StudentItem.DoesNotExist:
msg = (
u"No record found when deleting student item {item_id}"
u"in course {course_id} for student {student_id}."
).format(item_id=item_id, course_id=course_id, student_id=student_id)
logger.exception(msg)
raise SubmissionInternalError(msg)
except DatabaseError:
msg = (
u"Error occurred while reseting scores for"
u" item {item_id} in course {course_id} for student {student_id}"
).format(item_id=item_id, course_id=course_id, student_id=student_id)
logger.exception(msg)
raise SubmissionInternalError(msg)
else:
msg = u"Successfully deleted item {item_id} in course {course_id} for student {student_id}".format(
item_id=item_id, course_id=course_id, student_id=student_id
)
logger.info(msg)


def reset_score(student_id, course_id, item_id):
"""
Reset scores for a specific student on a specific problem.
Expand Down