-
Notifications
You must be signed in to change notification settings - Fork 4.3k
convert user objects to unicode, improve error logging #424
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
|
|
@@ -310,7 +310,9 @@ def get_student_from_identifier(unique_student_identifier): | |
| "Delete student state for module" in action or | ||
| "Rescore student's problem submission" in action): | ||
| # get the form data | ||
| unique_student_identifier = request.POST.get('unique_student_identifier', '') | ||
| unique_student_identifier = request.POST.get( | ||
| 'unique_student_identifier', '' | ||
| ) | ||
| problem_urlname = request.POST.get('problem_for_student', '') | ||
| module_state_key = get_module_url(problem_urlname) | ||
| # try to uniquely id student by email address or username | ||
|
|
@@ -320,43 +322,67 @@ def get_student_from_identifier(unique_student_identifier): | |
| if student is not None: | ||
| # find the module in question | ||
| try: | ||
| student_module = StudentModule.objects.get(student_id=student.id, | ||
| course_id=course_id, | ||
| module_state_key=module_state_key) | ||
| student_module = StudentModule.objects.get( | ||
| student_id=student.id, | ||
| course_id=course_id, | ||
| module_state_key=module_state_key | ||
| ) | ||
| msg += "Found module. " | ||
| except StudentModule.DoesNotExist: | ||
| msg += "<font color='red'>Couldn't find module with that urlname. </font>" | ||
| except StudentModule.DoesNotExist as err: | ||
| error_msg = "Couldn't find module with that urlname: {0}. ".format( | ||
| problem_urlname | ||
| ) | ||
| msg += "<font color='red'>" + error_msg + "({0}) ".format(err) + "</font>" | ||
| log.debug(error_msg) | ||
|
|
||
| if student_module is not None: | ||
| if "Delete student state for module" in action: | ||
| # delete the state | ||
| try: | ||
| student_module.delete() | ||
| msg += "<font color='red'>Deleted student module state for %s!</font>" % module_state_key | ||
| event = {"problem": problem_url, "student": unique_student_identifier, "course": course_id} | ||
| track.views.server_track(request, "delete-student-module-state", event, page="idashboard") | ||
| except: | ||
| msg += "Failed to delete module state for %s/%s" % (unique_student_identifier, problem_urlname) | ||
| msg += "<font color='red'>Deleted student module state for {0}!</font>".format(module_state_key) | ||
| event = { | ||
| "problem": problem_url, | ||
| "student": unique_student_identifier, | ||
| "course": course_id | ||
| } | ||
| track.views.server_track( | ||
| request, | ||
| "delete-student-module-state", | ||
| event, | ||
| page="idashboard" | ||
| ) | ||
| except Exception as err: | ||
| error_msg = "Failed to delete module state for {0}/{1}. ".format( | ||
| unique_student_identifier, problem_urlname | ||
| ) | ||
| msg += "<font color='red'>" + error_msg + "({0}) ".format(err) + "</font>" | ||
| log.exception(error_msg) | ||
| elif "Reset student's attempts" in action: | ||
| # modify the problem's state | ||
| try: | ||
| # load the state json | ||
| problem_state = json.loads(student_module.state) | ||
| old_number_of_attempts = problem_state["attempts"] | ||
| problem_state["attempts"] = 0 | ||
|
|
||
| # save | ||
| student_module.state = json.dumps(problem_state) | ||
| student_module.save() | ||
| event = {"old_attempts": old_number_of_attempts, | ||
| "student": student, | ||
| "problem": student_module.module_state_key, | ||
| "instructor": request.user, | ||
| "course": course_id} | ||
| event = { | ||
| "old_attempts": old_number_of_attempts, | ||
| "student": unicode(student), | ||
| "problem": student_module.module_state_key, | ||
| "instructor": unicode(request.user), | ||
| "course": course_id | ||
| } | ||
| track.views.server_track(request, "reset-student-attempts", event, page="idashboard") | ||
| msg += "<font color='green'>Module state successfully reset!</font>" | ||
| except: | ||
| msg += "<font color='red'>Couldn't reset module state. </font>" | ||
| except Exception as err: | ||
| error_msg = "Couldn't reset module state for {0}/{1}. ".format( | ||
| unique_student_identifier, problem_urlname | ||
| ) | ||
| msg += "<font color='red'>" + error_msg + "({0}) ".format(err) + "</font>" | ||
| log.exception(error_msg) | ||
| else: | ||
| # "Rescore student's problem submission" case | ||
| try: | ||
|
|
@@ -365,9 +391,14 @@ def get_student_from_identifier(unique_student_identifier): | |
| msg += '<font color="red">Failed to create a background task for rescoring "{0}" for student {1}.</font>'.format(module_state_key, unique_student_identifier) | ||
| else: | ||
| track.views.server_track(request, "rescore-student-submission", {"problem": module_state_key, "student": unique_student_identifier, "course": course_id}, page="idashboard") | ||
| except Exception as e: | ||
| log.exception("Encountered exception from rescore: {0}") | ||
| msg += '<font color="red">Failed to create a background task for rescoring "{0}": {1}.</font>'.format(module_state_key, e.message) | ||
| except Exception as err: | ||
| msg += '<font color="red">Failed to create a background task for rescoring "{0}": {1}.</font>'.format( | ||
| module_state_key, err.message | ||
| ) | ||
|
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. looks good... |
||
| log.exception("Encountered exception from rescore: student '{0}' problem '{1}'".format( | ||
| unique_student_identifier, module_state_key | ||
| ) | ||
| ) | ||
|
|
||
| elif "Get link to student's progress page" in action: | ||
| unique_student_identifier = request.POST.get('unique_student_identifier', '') | ||
|
|
||
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.
I would now just make this more like the rescore.
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.
Meaning different error messages for the logs and for the user?
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.
Yup. Just like you wrote above. Exactly like...
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.
I'm sorry, I'm still confused what you mean by this being more like the rescore. The rescore is the only exception for which the user-facing and log-facing error messages significantly differ. In other places, they are the same, except we explicitly show the exception to the user.