diff options
author | ankitjavalkar | 2019-02-18 16:40:16 +0530 |
---|---|---|
committer | GitHub | 2019-02-18 16:40:16 +0530 |
commit | b71b517173cac8b4f266f36d0cbc918551b3ee73 (patch) | |
tree | f020ee332db3996d88d67bdab1cefddbcd82acf8 | |
parent | 01c476c535611c671c8b17ad1cb2e8f2b41a4378 (diff) | |
parent | 37ee0c9de91cac5bdb6275e12d35cb6b7697a7fb (diff) | |
download | online_test-b71b517173cac8b4f266f36d0cbc918551b3ee73.tar.gz online_test-b71b517173cac8b4f266f36d0cbc918551b3ee73.tar.bz2 online_test-b71b517173cac8b4f266f36d0cbc918551b3ee73.zip |
Merge pull request #575 from CruiseDevice/file_download_issue_in_quiz
Fix download file for a question in quiz
-rw-r--r-- | yaksh/models.py | 3 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 2 | ||||
-rw-r--r-- | yaksh/test_models.py | 20 |
3 files changed, 24 insertions, 1 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index cce90e7..7b80306 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1408,6 +1408,9 @@ class FileUpload(models.Model): self.hide = True self.save() + def get_filename(self): + return os.path.basename(self.file.name) + ############################################################################### class Answer(models.Model): diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 59dfaef..cb6d90a 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -160,7 +160,7 @@ question_type = "{{ question.type }}" <span> Files to download for this question </span> <hr> {% for f_name in files %} <div class="yakshwell"> - <a href="{{f.file.url}}" class="btn btn-outline-secondary"><b>{{forloop.counter}}.</b> {{f_name.file.name}}</a> + <a href="{{f_name.file.url}}" class="btn btn-outline-secondary btn-sm " target="_blank">{{f_name.get_filename}}</a> <br> </div> {% endfor %} diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 1f38d03..53ee656 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,5 +1,6 @@ import unittest from django.contrib.auth.models import Group +from django.core.files.uploadedfile import SimpleUploadedFile from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\ @@ -2130,3 +2131,22 @@ class CourseStatusTestCases(unittest.TestCase): # Test get course grade after completion self.assertEqual(self.course.get_grade(self.answerpaper1.user), 'B') + + +class FileUploadTestCases(unittest.TestCase): + def setUp(self): + self.question = Question.objects.get(summary='Q1') + self.filename = "uploadtest.txt" + self.uploaded_file = SimpleUploadedFile(self.filename, b'Test File') + self.file_upload = FileUpload.objects.create( + file=self.uploaded_file, + question=self.question + ) + + def test_get_file_name(self): + print((self.file_upload.file.path)) + self.assertEqual(self.file_upload.get_filename(), self.filename) + + def tearDown(self): + os.remove(self.file_upload.file.path) + self.file_upload.delete() |