From e1e334964aaaed89e7e6d85094048518cb7ad88c Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Sat, 8 Aug 2020 00:56:26 +0530 Subject: Add select all checkbox in design qp for fixed questions. --- yaksh/models.py | 2 +- yaksh/static/yaksh/js/question_paper_creation.js | 34 ++++++++++- yaksh/templates/yaksh/add_quiz.html | 2 +- yaksh/templates/yaksh/design_questionpaper.html | 72 +++++++++++++----------- yaksh/views.py | 13 +++++ 5 files changed, 87 insertions(+), 36 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index 6542daa..d3d90c9 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1729,7 +1729,7 @@ class QuestionPaper(models.Model): total_marks = models.FloatField(default=0.0, blank=True) # Sequence or Order of fixed questions - fixed_question_order = models.CharField(max_length=255, blank=True) + fixed_question_order = models.TextField(blank=True) # Shuffle testcase order. shuffle_testcases = models.BooleanField("Shuffle testcase for each user", diff --git a/yaksh/static/yaksh/js/question_paper_creation.js b/yaksh/static/yaksh/js/question_paper_creation.js index 9d04728..871d6cc 100644 --- a/yaksh/static/yaksh/js/question_paper_creation.js +++ b/yaksh/static/yaksh/js/question_paper_creation.js @@ -57,7 +57,38 @@ $(document).ready(function(){ $('#design_q').submit(function(eventObj) { $(this).append(''); return true; -}); + }); + + $('#add_checkall').change(function () { + if($(this).prop("checked")) { + $("#fixed-available input:checkbox").each(function(index, element) { + if(isNaN($(this).val())) {return}; + $(this).prop("checked", true); + checked_vals.push(parseInt($(this).val())) + }); + } else { + $("#fixed-available input:checkbox").each(function(index, element){ + $(this).prop('checked', false); + checked_vals.pop(parseInt($(this).val())); + }); + } + }); + + $('#remove_checkall').change(function () { + if($(this).prop("checked")) { + $("#fixed-added input:checkbox").each(function (index, element) { + if(isNaN($(this).val())) { return }; + $(this).prop('checked', true); + checked_vals.push(parseInt($(this).val())); + }); + } else { + $("#fixed-added input:checkbox").each(function (index, element) { + console.log('unchecked'); + $(this).prop('checked', false); + checked_vals.pop(parseInt($(this).val())); + }); + } + }); });//document function append_tag(tag){ @@ -69,3 +100,4 @@ function append_tag(tag){ tag_name.value = tag.value; } } + diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index 55e3bd6..01b6f8c 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -55,7 +55,7 @@ {% if quiz and course_id %} {% if quiz.questionpaper_set.get.id %}
- + Edit Question Paper diff --git a/yaksh/templates/yaksh/design_questionpaper.html b/yaksh/templates/yaksh/design_questionpaper.html index ffbdf5f..fcc3ed5 100644 --- a/yaksh/templates/yaksh/design_questionpaper.html +++ b/yaksh/templates/yaksh/design_questionpaper.html @@ -114,12 +114,47 @@

Select questions to add:

+
+
+ + +
+
+

Fixed questions currently in paper:

+
+ {% if fixed_questions %}
    - {% for question in questions %} +
    Select All
    + {% for question in fixed_questions %}
  • {% endfor %} @@ -136,35 +171,6 @@

- -
-
-
-

Fixed questions currently in paper:

-
-
    - {% for question in fixed_questions %} -
  • - -
  • - {% endfor %} -
-
-
-
diff --git a/yaksh/views.py b/yaksh/views.py index 3adb536..a1d4e05 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1444,6 +1444,13 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): question_paper.save() question_paper.fixed_questions.add(*questions) messages.success(request, "Questions added successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) + else: messages.warning(request, "Please select atleast one question") @@ -1462,6 +1469,12 @@ def design_questionpaper(request, course_id, quiz_id, questionpaper_id=None): question_paper.save() question_paper.fixed_questions.remove(*question_ids) messages.success(request, "Questions removed successfully") + return redirect( + 'yaksh:designquestionpaper', + course_id=course_id, + quiz_id=quiz_id, + questionpaper_id=questionpaper_id + ) else: messages.warning(request, "Please select atleast one question") -- cgit From 570b141055f9baa27c539842b14756838949ba60 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Wed, 26 Aug 2020 18:51:25 +0530 Subject: Avoid duplicate user entry with same email address during upload. Django allows multiple usernames with same email id. Preventing this, as we identify users with their email id or username. --- yaksh/fixtures/user_existing_email.csv | 2 ++ yaksh/fixtures/users_add_update_reject.csv | 4 ++-- yaksh/test_views.py | 27 +++++++++++++++++++++++++++ yaksh/views.py | 4 +++- 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 yaksh/fixtures/user_existing_email.csv diff --git a/yaksh/fixtures/user_existing_email.csv b/yaksh/fixtures/user_existing_email.csv new file mode 100644 index 0000000..ee5fcd0 --- /dev/null +++ b/yaksh/fixtures/user_existing_email.csv @@ -0,0 +1,2 @@ +firstname, lastname, email +abc, abc, demo_student@test.com diff --git a/yaksh/fixtures/users_add_update_reject.csv b/yaksh/fixtures/users_add_update_reject.csv index 1990179..2b8fcf6 100644 --- a/yaksh/fixtures/users_add_update_reject.csv +++ b/yaksh/fixtures/users_add_update_reject.csv @@ -1,4 +1,4 @@ firstname, lastname, email, institute,department,roll_no,remove,password,username test, test, test@g.com, TEST, TEST, TEST101, FALSE, TEST, test -test2, test, test@g.com, TEST, TEST, TEST101, FALSE, TEST, test2 -test2, test, test@g.com, TEST, TEST, TEST101, TRUE, TEST, test2 +test2, test, test2@g.com, TEST, TEST, TEST101, FALSE, TEST, test2 +test2, test, test2@g.com, TEST, TEST, TEST101, TRUE, TEST, test2 diff --git a/yaksh/test_views.py b/yaksh/test_views.py index a7ccac2..5876f03 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -2755,6 +2755,33 @@ class TestCourseDetail(TestCase): id=uploaded_users.first().id).exists() ) + def test_upload_existing_user_email(self): + # Given + self.client.login( + username=self.user1.username, password=self.user1_plaintext_pass) + csv_file_path = os.path.join(FIXTURES_DIR_PATH, + 'user_existing_email.csv') + csv_file = open(csv_file_path, 'rb') + upload_file = SimpleUploadedFile(csv_file_path, csv_file.read()) + csv_file.close() + + # When + response = self.client.post( + reverse('yaksh:upload_users', + kwargs={'course_id': self.user1_course.id}), + data={'csv_file': upload_file}) + + # Then + uploaded_users = User.objects.filter(email='demo_student@test.com') + self.assertEqual(response.status_code, 302) + messages = [m.message for m in get_messages(response.wsgi_request)] + self.assertIn('demo_student', messages[0]) + self.assertTrue( + self.user1_course.students.filter( + id=uploaded_users.first().id).exists() + ) + self.assertEqual(uploaded_users.count(), 1) + def test_upload_users_add_update_reject(self): # Given self.client.login( diff --git a/yaksh/views.py b/yaksh/views.py index 3adb536..9f8468d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2409,8 +2409,10 @@ def _read_user_csv(request, reader, course): messages.info(request, "{0} -- Missing Values".format(counter)) continue users = User.objects.filter(username=username) + if not users.exists(): + users = User.objects.filter(email=email) if users.exists(): - user = users[0] + user = users.last() if remove.strip().lower() == 'true': _remove_from_course(user, course) messages.info(request, "{0} -- {1} -- User rejected".format( -- cgit