Skip to content

Commit

Permalink
allow identify without grading
Browse files Browse the repository at this point in the history
  • Loading branch information
IonMich committed Oct 1, 2023
1 parent 92596af commit d1fea47
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 2 deletions.
101 changes: 101 additions & 0 deletions submissions/static/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -1667,3 +1667,104 @@ savedCommentsSelect.addEventListener("change", (event) => {
}
);

// listen for the dropdown to be closed in the student name selectpicker
// when the dropdown is closed, console.log the selected student
const studentNameSelect = document.querySelector("#id_student");
studentNameSelect.addEventListener("change", (event) => {
console.log(event.target.value);

// get the student pk from the selectpicker
const studentPk = event.target.value;
// get the student name from the selectpicker
const studentName = event.target.selectedOptions[0].text;
console.log(studentName);
// send the student name change to the server
handleNameChange(event);
});

// send the name change to the server
async function handleNameChange (event) {
// get the student pk from the selectpicker
const assignmentPk = JSON.parse(
document.querySelector("#assignment_id").textContent
);
const studentPk = event.target.value;
const csrfToken = document.querySelector("[name=csrfmiddlewaretoken]").value;
// get the student name from the selectpicker
const studentName = event.target.selectedOptions[0].text;
console.log(studentName);
// send the student name change to the server
const url = `/assignments/${assignmentPk}/submissions/${pk}/`;
const data = {
"student": studentPk,
"classification_type": "M",
"csrfmiddlewaretoken": csrfToken,
};
const options = {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": csrfToken,
},
body: JSON.stringify(data),
};
try {
const response = await fetch(url, options);
const json = await response.json();
console.log(json.student);
console.log(studentPk);
if (json.student.toString() !== studentPk) {
throw new Error("Student name change failed");
}
const toastDiv = document.createElement("div");
toastDiv.classList.add("toast", "align-items-center", "text-white", "bg-success", "border-0");
toastDiv.setAttribute("role", "alert");
toastDiv.setAttribute("aria-live", "assertive");
toastDiv.setAttribute("aria-atomic", "true");
toastDiv.innerHTML = `<div class="d-flex">
<div class="toast-body">
Student name changed to ${studentName}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>`;
document.querySelector(".toast-container").appendChild(toastDiv);
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastDiv);
toastBootstrap.show();
} catch (error) {
console.log(error);
const toastDiv = document.createElement("div");
toastDiv.classList.add("toast", "align-items-center", "text-white", "bg-danger", "border-0");
toastDiv.setAttribute("role", "alert");
toastDiv.setAttribute("aria-live", "assertive");
toastDiv.setAttribute("aria-atomic", "true");
toastDiv.innerHTML = `<div class="d-flex">
<div class="toast-body">
Error changing student name
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>`;
document.querySelector(".toast-container").appendChild(toastDiv);
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastDiv);
toastBootstrap.show();
}
}

// get the grading-progress-bar and set the color to primary if data-bs-theme is light
// get the grading-progress-bar and set the color to orange if
// - data-bs-theme is dark
// - data-bs-theme is auto and prefers-color-scheme is dark

const gradingProgressBar = document.querySelector("#grading-progress-bar");

if (gradingProgressBar) {
console.log("gradingProgressBar exists");
const getStoredTheme = () => localStorage.getItem('theme')
const storedTheme = getStoredTheme()
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");

if (storedTheme === "light") {
gradingProgressBar.classList.add("bg-primary");
} else if (storedTheme === "dark" || (storedTheme === "auto" && prefersDarkScheme.matches)) {
gradingProgressBar.classList.add("bg-warning");
}
}
13 changes: 11 additions & 2 deletions submissions/templates/submissions/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@

{% block navbar %}

<div class="progress" style="height: 2px; width:100%">
<div class="progress-bar" role="progressbar" style=" width: {{submission.assignment.get_grading_progress}}%" aria-valuenow="{{submission.assignment.get_grading_progress}}" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress" style="height: 3px; width:100%">
<div
class="progress-bar"
role="progressbar"
style=" width: {{submission.assignment.get_grading_progress}}%"
aria-valuenow="{{submission.assignment.get_grading_progress}}"
aria-valuemin="0"
aria-valuemax="100"
id="grading-progress-bar"
>
</div>
</div>
{% endblock navbar %}

Expand Down
2 changes: 2 additions & 0 deletions submissions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
submission_classify_view, submission_comment_delete_view,
submission_comment_modify_view, submission_delete_all_view,
submission_delete_view, submission_detail_view,
api_submission_patch_view,
submission_list_view)

app_name = 'submissions'
Expand All @@ -17,6 +18,7 @@
path('courses/<course_pk>/assignments/<assignment_pk>/submissions/<uuid:submission_pk>/previous/', redirect_to_previous, name='detail_previous'),
path('courses/<course_pk>/assignments/<assignment_pk>/submissions/<uuid:submission_pk>/next/', redirect_to_next, name='detail_next'),
path('courses/<course_pk>/assignments/<assignment_pk>/submissions/<submission_pk>/delete/', submission_delete_view, name='delete-submission'),
path('assignments/<assignment_pk>/submissions/<submission_pk>/', api_submission_patch_view, name='api-submission-patch'),
path('courses/<course_pk>/assignments/<assignment_pk>/submissions/<submission_pk>/comments/<comment_pk>/delete/', submission_comment_delete_view, name='delete-comment'),
path('courses/<course_pk>/assignments/<assignment_pk>/submissions/<submission_pk>/comments/<comment_pk>/modify/', submission_comment_modify_view, name='modify-comment'),
]
38 changes: 38 additions & 0 deletions submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,44 @@ def submission_detail_view(request, course_pk, assignment_pk, submission_pk):
'grading_form': grading_form,
'grades_zipped': grades_zipped})

@login_required
def api_submission_patch_view(request, assignment_pk, submission_pk):
import json
submission = get_object_or_404(PaperSubmission, pk=submission_pk)
if request.method == 'PATCH':
print("request was PATCH")
print(request.body)
data = json.loads(request.body)
print(data)
# get the student model from the database
from django.apps import apps
Student = apps.get_model('students', 'Student')
if data.get('student'):
try:
student_pk = data.get('student')
# check if the student belongs to the course
student = get_object_or_404(Student, pk=student_pk)
assignment = get_object_or_404(Assignment, pk=assignment_pk)
if student not in assignment.course.get_students():
return JsonResponse({"message": "error"})
else:
submission.student = student
except Exception as e:
print(e)
return JsonResponse({"message": "error"})
if data.get('classification_type'):
submission.classification_type = data.get('classification_type')
else:
submission.classification_type = 'M'
if data.get('canvas_id'):
submission.canvas_id = data.get('canvas_id')
if data.get('canvas_url'):
submission.canvas_url = data.get('canvas_url')
submission.save()
return JsonResponse({"message": "success", "student": submission.student.id})
else:
return JsonResponse({"message": "error"})

@login_required
def redirect_to_previous(request, course_pk, assignment_pk, submission_pk):

Expand Down

0 comments on commit d1fea47

Please sign in to comment.