summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/fixtures/user_existing_email.csv2
-rw-r--r--yaksh/fixtures/users_add_update_reject.csv4
-rw-r--r--yaksh/models.py2
-rw-r--r--yaksh/static/yaksh/js/question_paper_creation.js34
-rw-r--r--yaksh/templates/yaksh/design_questionpaper.html72
-rw-r--r--yaksh/test_views.py27
-rw-r--r--yaksh/views.py17
7 files changed, 120 insertions, 38 deletions
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/models.py b/yaksh/models.py
index 32632dd..1094bb0 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1727,7 +1727,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('<input type="hidden" name="checked_ques" value='+checked_vals+'>');
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/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 @@
<div id="fixed-available-wrapper">
<p><u>Select questions to add:</u></p>
<div id="fixed-available">
- {% if state == "fixed" or state == "None" %}
+ {% if questions %}
+ {% if state == "fixed" or state == "None" %}
+ <ul class="inputs-list">
+ <h5><input id="add_checkall" name="add_checkall" type="checkbox"> Select All </h5>
+ {% for question in questions %}
+ <li>
+ <label>
+ <input type="checkbox" name="questions" data-qid="{{question.id}}" value={{question.id}}>
+ <span>
+ {% if user == question.user %}
+ <a href="{% url 'yaksh:add_question' question.id %}" target="_blank">{{ question.summary }}</a>
+ {% else %}
+ {{question.summary}}
+ {% endif %}
+ </span>
+ <span> {{ question.points }}</span>
+ </label>
+ </li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ {% endif %}
+ </div>
+ </div>
+ <br />
+ <button id="add-fixed" name="add-fixed" class="btn btn-success pull-right" type="submit">
+ <i class="fa fa-plus-square"></i>&nbsp;Add to paper
+ </button>
+ </div>
+ <div class="col-md-6">
+ <div id="fixed-added-wrapper">
+ <p><u>Fixed questions currently in paper:</u></p>
+ <div id="fixed-added">
+ {% if fixed_questions %}
<ul class="inputs-list">
- {% for question in questions %}
+ <h5><input id="remove_checkall" type="checkbox"> Select All </h5>
+ {% for question in fixed_questions %}
<li>
<label>
- <input type="checkbox" name="questions" data-qid="{{question.id}}" value={{question.id}}>
+ <input type="checkbox" name="added-questions"
+ data-qid="{{question.id}}" value={{question.id}}>
<span>
{% if user == question.user %}
<a href="{% url 'yaksh:add_question' question.id %}" target="_blank">{{ question.summary }}</a>
@@ -127,7 +162,7 @@
{{question.summary}}
{% endif %}
</span>
- <span> {{ question.points }}</span>
+ <span> {{ question.points }} </span>
</label>
</li>
{% endfor %}
@@ -136,35 +171,6 @@
</div>
</div>
<br />
- <button id="add-fixed" name="add-fixed" class="btn btn-success pull-right" type="submit">
- <i class="fa fa-plus-square"></i>&nbsp;Add to paper
- </button>
- </div>
- <div class="col-md-6">
- <div id="fixed-added-wrapper">
- <p><u>Fixed questions currently in paper:</u></p>
- <div id="fixed-added">
- <ul class="inputs-list">
- {% for question in fixed_questions %}
- <li>
- <label>
- <input type="checkbox" name="added-questions"
- data-qid="{{question.id}}" value={{question.id}}>
- <span>
- {% if user == question.user %}
- <a href="{% url 'yaksh:add_question' question.id %}" target="_blank">{{ question.summary }}</a>
- {% else %}
- {{question.summary}}
- {% endif %}
- </span>
- <span> {{ question.points }} </span>
- </label>
- </li>
- {% endfor %}
- </ul>
- </div>
- </div>
- <br />
<button id="remove-fixed" name="remove-fixed" class="btn btn-danger pull-right" type="submit">
<i class="fa fa-minus-square"></i>&nbsp;Remove from paper
</button>
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 c1798b5..afa673f 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1446,6 +1446,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")
@@ -1464,6 +1471,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")
@@ -2411,8 +2424,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(