summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/models.py7
-rw-r--r--yaksh/test_views.py48
-rw-r--r--yaksh/views.py1
3 files changed, 35 insertions, 21 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index ca0f2d8..30c69c3 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -121,15 +121,16 @@ MOD_GROUP_NAME = 'moderator'
def get_assignment_dir(instance, filename):
- folder = str(instance.answer_paper.course_id)
- sub_folder = str(instance.answer_paper.question_paper.quiz_id)
+ course = instance.answer_paper.course
+ quiz = instance.answer_paper.question_paper.quiz
+ folder = f'{course.name.replace(" ", "_")}_{course.id}'
+ sub_folder = f'{quiz.description.replace(" ","_")}_{quiz.id}'
user = instance.answer_paper.user.username
return os.sep.join((folder, sub_folder, user,
str(instance.assignmentQuestion.id),
filename
))
-
def get_model_class(model):
ctype = ContentType.objects.get(app_label="yaksh", model=model)
model_class = ctype.model_class()
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 822a6bc..9d14490 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -944,9 +944,14 @@ class TestDownloadAssignment(TestCase):
self.student1, ip, attempt, self.course.id
)
+ self.answerpaper2 = self.question_paper.make_answerpaper(
+ self.student2, ip, attempt, self.course.id
+ )
+
# create assignment file
assignment_file1 = SimpleUploadedFile("file1.txt", b"Test")
assignment_file2 = SimpleUploadedFile("file2.txt", b"Test")
+
self.assignment1 = AssignmentUpload.objects.create(
assignmentQuestion=self.question,
assignmentFile=assignment_file1, answer_paper=self.answerpaper1
@@ -956,22 +961,15 @@ class TestDownloadAssignment(TestCase):
assignmentFile=assignment_file2, answer_paper=self.answerpaper1
)
- def tearDown(self):
- self.client.logout()
- self.user.delete()
- self.student1.delete()
- self.student2.delete()
- self.assignment1.delete()
- self.assignment2.delete()
- self.quiz.delete()
- self.course.delete()
- self.learning_module.delete()
- self.learning_unit.delete()
- self.mod_group.delete()
- dir_name = self.course.name.replace(" ", "_")
- file_path = os.sep.join((settings.MEDIA_ROOT, dir_name))
- if os.path.exists(file_path):
- shutil.rmtree(file_path)
+ self.assignment1 = AssignmentUpload.objects.create(
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file1, answer_paper=self.answerpaper2
+ )
+ self.assignment2 = AssignmentUpload.objects.create(
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file2, answer_paper=self.answerpaper2
+ )
+
def test_download_assignment_denies_student(self):
"""
@@ -1042,10 +1040,26 @@ class TestDownloadAssignment(TestCase):
zipped_file = zipfile.ZipFile(zip_file, 'r')
self.assertIsNone(zipped_file.testzip())
self.assertIn('file1.txt', zipped_file.namelist()[0])
-
zip_file.close()
zipped_file.close()
+ def tearDown(self):
+ self.client.logout()
+ self.user.delete()
+ self.student1.delete()
+ self.student2.delete()
+ self.assignment1.delete()
+ self.assignment2.delete()
+ self.quiz.delete()
+ self.learning_module.delete()
+ self.learning_unit.delete()
+ self.mod_group.delete()
+ dir_name = f'{self.course.name.replace(" ", "_")}_{self.course.id}'
+ file_path = os.sep.join((settings.MEDIA_ROOT, dir_name))
+ if os.path.exists(file_path):
+ shutil.rmtree(file_path)
+ self.course.delete()
+
class TestAddQuiz(TestCase):
def setUp(self):
diff --git a/yaksh/views.py b/yaksh/views.py
index ea18541..3cff7f5 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1866,7 +1866,6 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
"""
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: