summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2021-01-11 10:08:48 +0530
committerGitHub2021-01-11 10:08:48 +0530
commit98124aaa624ea09e131b6e3563f78bc5d48061ad (patch)
tree52835b0f708d43d1f352a853cf672ca291d30444
parent30dd519ba7a5277348960a696f3a7cbd91f3f72f (diff)
parent49a494849a0498e309f6c97ec6ae6ab79961b87d (diff)
downloadonline_test-98124aaa624ea09e131b6e3563f78bc5d48061ad.tar.gz
online_test-98124aaa624ea09e131b6e3563f78bc5d48061ad.tar.bz2
online_test-98124aaa624ea09e131b6e3563f78bc5d48061ad.zip
Merge pull request #725 from ankitjavalkar/bugfix_08_06
Remove 'copy of' string in _create_lesson_copy()
-rw-r--r--yaksh/models.py11
-rw-r--r--yaksh/test_views.py15
-rw-r--r--yaksh/views.py3
3 files changed, 16 insertions, 13 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index a29e910..686d0e6 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -321,7 +321,6 @@ class Lesson(models.Model):
lesson_files = self.get_files()
new_lesson = self
new_lesson.id = None
- new_lesson.name = "Copy of {0}".format(self.name)
new_lesson.creator = user
new_lesson.save()
for _file in lesson_files:
@@ -600,7 +599,6 @@ class Quiz(models.Model):
question_papers = self.questionpaper_set.all()
new_quiz = self
new_quiz.id = None
- new_quiz.description = "Copy of {0}".format(self.description)
new_quiz.creator = user
new_quiz.save()
for qp in question_papers:
@@ -846,12 +844,13 @@ class LearningModule(models.Model):
percent = round((count / units.count()) * 100)
return percent
- def _create_module_copy(self, user, module_name):
+ def _create_module_copy(self, user, module_name=None):
learning_units = self.learning_unit.order_by("order")
new_module = self
new_module.id = None
- new_module.name = module_name
new_module.creator = user
+ if module_name:
+ new_module.name = module_name
new_module.save()
for unit in learning_units:
new_unit = unit._create_unit_copy(user)
@@ -957,8 +956,8 @@ class Course(models.Model):
copy_course_name = "Copy Of {0}".format(self.name)
new_course = self._create_duplicate_instance(user, copy_course_name)
for module in learning_modules:
- copy_module_name = "Copy of {0}".format(module.name)
- new_module = module._create_module_copy(user, copy_module_name)
+ copy_module_name = module.name
+ new_module = module._create_module_copy(user)
new_course.learning_module.add(new_module)
return new_course
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index c2fa4ac..b46a6d9 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -2168,7 +2168,8 @@ class TestCourses(TestCase):
# Teacher Login
# Given
# Add files to a lesson
- lesson_file = SimpleUploadedFile("file1.txt", b"Test")
+ file_content = b"Test"
+ lesson_file = SimpleUploadedFile("file1.txt", file_content)
django_file = File(lesson_file)
lesson_file_obj = LessonFile()
lesson_file_obj.lesson = self.lesson
@@ -2203,18 +2204,18 @@ class TestCourses(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(courses.last().creator, self.teacher)
self.assertEqual(courses.last().name, "Copy Of Python Course")
- self.assertEqual(module.name, "Copy of demo module")
+ self.assertEqual(module.name, "demo module")
self.assertEqual(module.creator, self.teacher)
self.assertEqual(module.order, 0)
self.assertEqual(len(units), 2)
- self.assertEqual(cloned_lesson.name, "Copy of demo lesson")
+ self.assertEqual(cloned_lesson.name, "demo lesson")
self.assertEqual(cloned_lesson.creator, self.teacher)
- self.assertEqual(cloned_quiz.description, "Copy of demo quiz")
+ self.assertEqual(cloned_quiz.description, "demo quiz")
self.assertEqual(cloned_quiz.creator, self.teacher)
self.assertEqual(cloned_qp.__str__(),
- "Question Paper for Copy of demo quiz")
- self.assertEqual(os.path.basename(expected_lesson_files[0].file.name),
- os.path.basename(actual_lesson_files[0].file.name))
+ "Question Paper for demo quiz")
+ self.assertTrue(expected_lesson_files.exists())
+ self.assertEquals(expected_lesson_files[0].file.read(), file_content)
for lesson_file in self.all_files:
file_path = lesson_file.file.path
diff --git a/yaksh/views.py b/yaksh/views.py
index 11a77b8..643b2ae 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -230,6 +230,9 @@ def results_user(request):
@email_verified
def add_question(request, question_id=None):
user = request.user
+ if not is_moderator(user):
+ raise Http404('You are not allowed to view this page !')
+
test_case_type = None
if question_id is not None: