summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2021-03-15 19:02:27 +0530
committerGitHub2021-03-15 19:02:27 +0530
commit6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6 (patch)
treea589f0dfae0cd118432f7e45899439cfc2a98a13 /yaksh/views.py
parent85a2b6b61c74e2ed42d6c78f6b502a3c72dcf9ca (diff)
parent1793f445ec0cbc67df4b4cd3151859e01ed4b2a0 (diff)
downloadonline_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.tar.gz
online_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.tar.bz2
online_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.zip
Merge pull request #822 from CruiseDevice/fix_file_upload_assignments
Fix file upload assignments
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py41
1 files changed, 18 insertions, 23 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index bddea26..7b1e038 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -721,9 +721,7 @@ def show_question(request, question, paper, error_message=None,
if question.type == 'upload':
assignment_files = AssignmentUpload.objects.filter(
assignmentQuestion_id=question.id,
- course_id=course_id,
- user=request.user,
- question_paper_id=paper.question_paper_id
+ answer_paper=paper
)
files = FileUpload.objects.filter(question_id=question.id, hide=False)
course = Course.objects.get(id=course_id)
@@ -857,22 +855,15 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None,
course_id=course_id, module_id=module_id,
previous_question=current_question
)
+ uploaded_files = []
for fname in assignment_filename:
fname._name = fname._name.replace(" ", "_")
- assignment_files = AssignmentUpload.objects.filter(
- assignmentQuestion=current_question, course_id=course_id,
- assignmentFile__icontains=fname, user=user,
- question_paper=questionpaper_id)
- if assignment_files.exists():
- assign_file = assignment_files.first()
- if os.path.exists(assign_file.assignmentFile.path):
- os.remove(assign_file.assignmentFile.path)
- assign_file.delete()
- AssignmentUpload.objects.create(
- user=user, assignmentQuestion=current_question,
- course_id=course_id,
- assignmentFile=fname, question_paper_id=questionpaper_id
- )
+ uploaded_files.append(AssignmentUpload(
+ assignmentQuestion=current_question,
+ assignmentFile=fname,
+ answer_paper_id=paper.id
+ ))
+ AssignmentUpload.objects.bulk_create(uploaded_files)
user_answer = 'ASSIGNMENT UPLOADED'
if not current_question.grade_assignment_upload:
new_answer = Answer(
@@ -1878,6 +1869,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
and update all their marks and also give comments for each paper.
"""
current_user = request.user
+ papers = AnswerPaper.objects.filter(user=current_user)
if not is_moderator(current_user):
raise Http404('You are not allowed to view this page!')
if not course_id:
@@ -1902,7 +1894,8 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
course.is_teacher(current_user):
raise Http404('This course does not belong to you')
has_quiz_assignments = AssignmentUpload.objects.filter(
- course_id=course_id, question_paper_id__in=questionpaper_id
+ answer_paper__course_id=course_id,
+ answer_paper__question_paper_id__in=questionpaper_id
).exists()
context = {
"users": user_details,
@@ -1921,9 +1914,11 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
attempt_number = attempts[0].attempt_number
except IndexError:
raise Http404('No attempts for paper')
+
has_user_assignments = AssignmentUpload.objects.filter(
- course_id=course_id, question_paper_id__in=questionpaper_id,
- user_id=user_id
+ answer_paper__course_id=course_id,
+ answer_paper__question_paper_id__in=questionpaper_id,
+ answer_paper__user_id=user_id
).exists()
user = User.objects.get(id=user_id)
data = AnswerPaper.objects.get_user_data(
@@ -2190,8 +2185,8 @@ def view_answerpaper(request, questionpaper_id, course_id):
data = AnswerPaper.objects.get_user_data(user, questionpaper_id,
course_id)
has_user_assignments = AssignmentUpload.objects.filter(
- user=user, course_id=course.id,
- question_paper_id=questionpaper_id
+ answer_paper__user=user, answer_paper__course_id=course.id,
+ answer_paper__question_paper_id=questionpaper_id
).exists()
context = {'data': data, 'quiz': quiz, 'course_id': course.id,
"has_user_assignments": has_user_assignments}
@@ -2391,7 +2386,7 @@ def download_assignment_file(request, quiz_id, course_id,
zipfile_name = string_io()
zip_file = zipfile.ZipFile(zipfile_name, "w")
for f_name in assignment_files:
- folder = f_name.user.get_full_name().replace(" ", "_")
+ folder = f_name.answer_paper.user.get_full_name().replace(" ", "_")
sub_folder = f_name.assignmentQuestion.summary.replace(" ", "_")
folder_name = os.sep.join((folder, sub_folder, os.path.basename(
f_name.assignmentFile.name))