From f1eb06d3740eb21558576e5f5489972e45cab038 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 15 Mar 2017 15:38:01 +0530 Subject: Changes in Views and Models - Add new boolean field in Question model whether to check assignment upload or not - In views before uploading a assignment file, check if it already exists and delete previous file - Grade assignment file with hook code --- yaksh/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 398f508..9134663 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -66,7 +66,7 @@ test_status = ( def get_assignment_dir(instance, filename): return os.sep.join(( - instance.user.user, instance.assignmentQuestion.id, filename + str(instance.user.user), str(instance.assignmentQuestion.id), filename )) @@ -264,6 +264,9 @@ class Question(models.Model): # Does this question allow partial grading partial_grading = models.BooleanField(default=False) + # Check assignment upload based question + grade_assignment_upload = models.BooleanField(default=False) + def consolidate_answer_data(self, user_answer): question_data = {} metadata = {} @@ -280,9 +283,13 @@ class Question(models.Model): metadata['language'] = self.language metadata['partial_grading'] = self.partial_grading files = FileUpload.objects.filter(question=self) + assignment_files = AssignmentUpload.objects.filter() if files: metadata['file_paths'] = [(file.file.path, file.extract) for file in files] + if assignment_files: + metadata['assign_files'] = [(file.assignmentFile.path, False) + for file in assignment_files] question_data['metadata'] = metadata return json.dumps(question_data) @@ -1201,7 +1208,7 @@ class AnswerPaper(models.Model): ############################################################################### class AssignmentUpload(models.Model): - user = models.ForeignKey(Profile) + user = models.ForeignKey(User) assignmentQuestion = models.ForeignKey(Question) assignmentFile = models.FileField(upload_to=get_assignment_dir) -- cgit From e937c2a3a17bfc127af89a86e213e434350cd360 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 15 Mar 2017 18:12:31 +0530 Subject: Change assignment dir path and add condition for json data --- yaksh/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 9134663..4dcd2ec 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -66,7 +66,7 @@ test_status = ( def get_assignment_dir(instance, filename): return os.sep.join(( - str(instance.user.user), str(instance.assignmentQuestion.id), filename + instance.user.username, str(instance.assignmentQuestion.id), filename )) @@ -1145,7 +1145,7 @@ class AnswerPaper(models.Model): if set(user_answer) == set(expected_answers): result['success'] = True result['error'] = ['Correct answer'] - elif question.type == 'code': + elif question.type == 'code' or question.type == "upload": user_dir = self.user.profile.get_user_dir() json_result = code_server.run_code( question.language, json_data, user_dir -- cgit From 5ae3841e4c432d5c0ee378ac9a4142f205b1dbb6 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 17 Mar 2017 20:47:55 +0530 Subject: Change consolidate_answer_data to get assignment uploads --- yaksh/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'yaksh/models.py') diff --git a/yaksh/models.py b/yaksh/models.py index 4dcd2ec..f6efeba 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -267,7 +267,7 @@ class Question(models.Model): # Check assignment upload based question grade_assignment_upload = models.BooleanField(default=False) - def consolidate_answer_data(self, user_answer): + def consolidate_answer_data(self, user_answer, user=None): question_data = {} metadata = {} test_case_data = [] @@ -283,13 +283,16 @@ class Question(models.Model): metadata['language'] = self.language metadata['partial_grading'] = self.partial_grading files = FileUpload.objects.filter(question=self) - assignment_files = AssignmentUpload.objects.filter() if files: metadata['file_paths'] = [(file.file.path, file.extract) for file in files] - if assignment_files: - metadata['assign_files'] = [(file.assignmentFile.path, False) - for file in assignment_files] + if self.type == "upload": + assignment_files = AssignmentUpload.objects.filter( + assignmentQuestion=self, user=user + ) + if assignment_files: + metadata['assign_files'] = [(file.assignmentFile.path, False) + for file in assignment_files] question_data['metadata'] = metadata return json.dumps(question_data) @@ -1272,7 +1275,8 @@ class HookTestCase(TestCase): success - Boolean, indicating if code was executed correctly mark_fraction - Float, indicating fraction of the weight to a test case - error - String, error message if success is false''' + error - String, error message if success is false + In case of assignment upload there will be no user answer ''' success = False err = "Incorrect Answer" # Please make this more specific mark_fraction = 0.0 -- cgit