diff options
author | CruiseDevice | 2021-02-26 08:37:27 +0530 |
---|---|---|
committer | CruiseDevice | 2021-02-26 08:37:27 +0530 |
commit | 3e23a631e9c8e25fd13c7f1f8b0fed54d0c34b8f (patch) | |
tree | a07018d25d470708dd5367e455681b06f1562f0f /yaksh | |
parent | 9a2717b662c7dd3fca54e8b8f2e526454ad72d83 (diff) | |
download | online_test-3e23a631e9c8e25fd13c7f1f8b0fed54d0c34b8f.tar.gz online_test-3e23a631e9c8e25fd13c7f1f8b0fed54d0c34b8f.tar.bz2 online_test-3e23a631e9c8e25fd13c7f1f8b0fed54d0c34b8f.zip |
Fix assignment download on grade user interface
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/admin.py | 3 | ||||
-rw-r--r-- | yaksh/base_evaluator.py | 2 | ||||
-rw-r--r-- | yaksh/models.py | 26 | ||||
-rw-r--r-- | yaksh/views.py | 36 |
4 files changed, 33 insertions, 34 deletions
diff --git a/yaksh/admin.py b/yaksh/admin.py index e98c7c5..011e24f 100644 --- a/yaksh/admin.py +++ b/yaksh/admin.py @@ -2,7 +2,7 @@ from yaksh.models import Question, Quiz, QuestionPaper, Profile from yaksh.models import (TestCase, StandardTestCase, StdIOBasedTestCase, Course, AnswerPaper, CourseStatus, LearningModule, Lesson, Post, Comment, Topic, TableOfContents, - LessonQuizAnswer, Answer + LessonQuizAnswer, Answer, AssignmentUpload ) from django.contrib import admin @@ -64,3 +64,4 @@ admin.site.register(Topic) admin.site.register(TableOfContents) admin.site.register(LessonQuizAnswer) admin.site.register(Answer) +admin.site.register(AssignmentUpload)
\ No newline at end of file diff --git a/yaksh/base_evaluator.py b/yaksh/base_evaluator.py index 567d5ad..c7b5c54 100644 --- a/yaksh/base_evaluator.py +++ b/yaksh/base_evaluator.py @@ -44,7 +44,7 @@ class BaseEvaluator(object): """Returns a string without any null and substitute characters""" stripped = "" for c in string: - if ord(c) is not 26 and ord(c) is not 0: + if ord(c) != 26 and ord(c) != 0: stripped = stripped + c return ''.join(stripped) diff --git a/yaksh/models.py b/yaksh/models.py index 6a745d1..b80f98c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -121,10 +121,10 @@ MOD_GROUP_NAME = 'moderator' def get_assignment_dir(instance, filename): - folder_name = instance.course.name.replace(" ", "_") - sub_folder_name = instance.answer_paper.question_paper.quiz.description.replace( - " ", "_") - return os.sep.join((folder_name, sub_folder_name, instance.user.username, + folder = str(instance.answer_paper.course.id) + sub_folder = str(instance.answer_paper.question_paper.quiz.id) + user = instance.answer_paper.user.username + return os.sep.join((folder, sub_folder, user, str(instance.assignmentQuestion.id), filename )) @@ -1439,7 +1439,7 @@ class Question(models.Model): for file in files] if self.type == "upload": assignment_files = AssignmentUpload.objects.filter( - assignmentQuestion=self, user=user + assignmentQuestion=self ) if assignment_files: metadata['assign_files'] = [(file.assignmentFile.path, False) @@ -2642,16 +2642,16 @@ class AssignmentUploadManager(models.Manager): def get_assignments(self, qp, que_id=None, user_id=None, course_id=None): if que_id and user_id: assignment_files = AssignmentUpload.objects.filter( - assignmentQuestion_id=que_id, user_id=user_id, - question_paper=qp, course_id=course_id + assignmentQuestion_id=que_id, answer_paper__user_id=user_id, + answer_paper__question_paper=qp, answer_paper__course_id=course_id ) file_name = User.objects.get(id=user_id).get_full_name() else: assignment_files = AssignmentUpload.objects.filter( - question_paper=qp, course_id=course_id + answer_paper__question_paper=qp, answer_paper__course_id=course_id ) file_name = "{0}_Assignment_files".format( - assignment_files[0].course.name + assignment_files[0].answer_paper.course.name ) return assignment_files, file_name @@ -2659,16 +2659,18 @@ class AssignmentUploadManager(models.Manager): ############################################################################## class AssignmentUpload(models.Model): - user = models.ForeignKey(User, on_delete=models.CASCADE) assignmentQuestion = models.ForeignKey(Question, on_delete=models.CASCADE) assignmentFile = models.FileField(upload_to=get_assignment_dir, max_length=255) answer_paper = models.ForeignKey(AnswerPaper, blank=True, null=True, on_delete=models.CASCADE) - course = models.ForeignKey(Course, null=True, blank=True, - on_delete=models.CASCADE) + upload_date = models.DateTimeField(auto_now=True) + objects = AssignmentUploadManager() + def __str__(self): + return f'Assignment File of the user {self.answer_paper.user}' + ############################################################################## class TestCase(models.Model): diff --git a/yaksh/views.py b/yaksh/views.py index ceebda6..7d4f788 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -720,8 +720,6 @@ 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, answer_paper=paper ) files = FileUpload.objects.filter(question_id=question.id, hide=False) @@ -856,22 +854,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, - answer_paper=paper.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, answer_paper_id=paper.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( @@ -1874,6 +1865,8 @@ 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) + print('Paper: ', papers) if not is_moderator(current_user): raise Http404('You are not allowed to view this page!') if not course_id: @@ -1898,7 +1891,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, @@ -1917,9 +1911,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( @@ -2383,7 +2379,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)) |