Skip to content

Commit

Permalink
fix #75
Browse files Browse the repository at this point in the history
  • Loading branch information
IonMich committed Feb 25, 2024
1 parent ab017c0 commit 8c2dc3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 90 deletions.
21 changes: 13 additions & 8 deletions submissions/static/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function navigatorHandler (event) {
}
switch(event.key) {
case "ArrowLeft":
if (pk === firstPk) {
if (!hasPrevious) {
return
}
handleChangesAndNavigate(prev_url);
break;
case "ArrowRight":
if (pk === lastPk) {
if (!hasNext) {
return
}
handleChangesAndNavigate(next_url);
Expand Down Expand Up @@ -457,6 +457,13 @@ const collectionPks = JSON.parse(
const filterPks = JSON.parse(
document.getElementById("filter-pks").textContent
);

const hasPrevious = JSON.parse(
document.getElementById("has-previous").textContent
);
const hasNext = JSON.parse(
document.getElementById("has-next").textContent
);
const currentSub = collectionPks.indexOf(pk);
const currentSubInFilter = filterPks.indexOf(pk);
console.log("currentSub", currentSub);
Expand All @@ -466,18 +473,16 @@ subPaginationCurrent.textContent = currentSub + 1;
if (filterPks.length === 0) {
// if there are no filtered submissions, hide the filter pagination
document.querySelector("#sub-pagination-filter-position").classList.add("d-none");
firstPk = collectionPks[0];
lastPk = collectionPks[collectionPks.length - 1];
} else {
const subPaginationFilterCurrent = document.querySelector("#sub-pagination-filter-current");
subPaginationFilterCurrent.textContent = currentSubInFilter >= 0 ? currentSubInFilter + 1 : "-";
}
console.log(scroll_height_factors, course_id, assignment_id);
console.log(pk, firstPk, lastPk);
if (pk === lastPk) {
console.log(course_id, assignment_id);
console.log(pk, hasPrevious, hasNext);
if (!hasNext) {
nextBtn.disabled = true;
}
if (pk === firstPk) {
if (!hasPrevious) {
prevBtn.disabled = true;
}

Expand Down
4 changes: 2 additions & 2 deletions submissions/templates/submissions/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
{{ submission.pk|json_script:"sub-pk" }}
{{ filter_pks|json_script:"filter-pks" }}
{{ collection_pks|json_script:"collection-pks" }}
{{ filter_pks|first|json_script:"first-sub-pk" }}
{{ filter_pks|last|json_script:"last-sub-pk" }}
{{ has_previous|json_script:"has-previous" }}
{{ has_next|json_script:"has-next" }}
<script src="{% static 'submissions/detail.js' %}" defer></script>
{% endblock scripts %}

Expand Down
89 changes: 9 additions & 80 deletions submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def submission_list_view(request):
@login_required
def submission_detail_view(request, course_pk, assignment_pk, submission_pk):
submission = get_object_or_404(PaperSubmission, pk=submission_pk)
n_q = submission.assignment.number_of_questions
grades_zipped = list(zip_longest(
submission.get_question_grades(),
submission.assignment.get_max_question_scores())
Expand Down Expand Up @@ -156,92 +155,20 @@ def submission_detail_view(request, course_pk, assignment_pk, submission_pk):
filter_pks = filtered_collection.values_list('pk', flat=True)
filter_pks = list(filter_pks)
query_params_dict['version_filter'] = version_filter
has_previous = filtered_collection.filter(
created__lt=submission.created).exists()
has_next = filtered_collection.filter(
created__gt=submission.created).exists()
print(has_previous, has_next)
if question_focus:
query_params_dict['question_focus'] = question_focus
print(query_params_dict)
collection_pks = collection.values_list('pk', flat=True)
collection_pks = list(collection_pks)
print(submission.assignment)
print("request.user: ", request.user)
if request.method == 'POST':
submission.graded_at = timezone.now()
submission.graded_by = request.user
# if the submission student is not the same as the request.POST['student'],
# then the student was changed manually at this stage,
# so we need to update the classification type to 'M' for manual
# and remove the canvas_id from the submission
if (not submission.student) or str(submission.student.id) != request.POST['student']:
submission.classification_type = 'M'
submission.canvas_id = ''
submission.canvas_url = ''

q_grades = [ str(request.POST.get(f"grade_{i+1}"))
for i in range(n_q)]
print(q_grades)
if q_grades:
_mutable = request.POST._mutable
# set to mutable
request.POST._mutable = True
# сhange the values you want
request.POST['question_grades'] = ",".join(q_grades)
# set mutable flag back
request.POST._mutable = _mutable

print(f"text: {request.POST.get('new_comment')}")
print(f"file: {request.FILES.get('comment_files')}")

grading_form = GradingForm(
request.POST,
request.FILES,
instance=submission)


if grading_form.is_valid():
print("form is valid")
print(grading_form.cleaned_data)

# add new comment from request.POST to a new SubmissionComment instance
# assigned to the submission and authored by the request.user

submission.save()

if request.POST.get('new_comment').strip():
comment = SubmissionComment(
paper_submission=submission,
author=request.user,
text=request.POST.get('new_comment'))
comment.save()
print("comment saved")
# add new file from request.FILES to a new SubmissionFile instance
# assigned to the submission and authored by the request.user
if request.FILES.get('comment_files'):
# use the class method add_commentfile_to_db of SubmissionComment
# to add the file to the database
print("adding file(s)")
SubmissionComment.add_commentfiles_to_db(
submission_target=submission,
uploaded_files=request.FILES.getlist('comment_files'),
author=request.user)

print("question grades", submission.question_grades)
grades_zipped = list(zip_longest(
submission.get_question_grades(),
submission.assignment.get_max_question_scores())
)
return render(
request,
'submissions/detail.html',
{'submission': submission,
'grading_form': grading_form,
'grades_zipped': grades_zipped,
'collection_pks': collection_pks,
'filter_pks': filter_pks,
'query_params': query_params_dict,
})
else:
print("form is not valid")
else:
grading_form = GradingForm(None)

grading_form = GradingForm(None)

return render(
request,
Expand All @@ -251,6 +178,8 @@ def submission_detail_view(request, course_pk, assignment_pk, submission_pk):
'grades_zipped': grades_zipped,
'collection_pks': collection_pks,
'filter_pks': filter_pks,
'has_previous': has_previous,
'has_next': has_next,
'query_params': query_params_dict,
})

Expand Down

0 comments on commit 8c2dc3b

Please sign in to comment.