summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2018-03-08 11:53:39 +0530
committeradityacp2018-03-08 11:53:39 +0530
commit02705e4c676750291b6a5c4ea14e2947f29cb6c7 (patch)
tree9ddb47401e4937abb9d3157e2fe058c744950221 /yaksh
parent438f8657021981fc7b2e5adbacc13eb332a2e6d3 (diff)
downloadonline_test-02705e4c676750291b6a5c4ea14e2947f29cb6c7.tar.gz
online_test-02705e4c676750291b6a5c4ea14e2947f29cb6c7.tar.bz2
online_test-02705e4c676750291b6a5c4ea14e2947f29cb6c7.zip
Allow to search the questions in design question paper
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/static/yaksh/js/question_paper_creation.js9
-rw-r--r--yaksh/templates/yaksh/ajax_question_filter.html57
-rw-r--r--yaksh/templates/yaksh/design_questionpaper.html38
-rw-r--r--yaksh/test_views.py17
-rw-r--r--yaksh/views.py80
5 files changed, 154 insertions, 47 deletions
diff --git a/yaksh/static/yaksh/js/question_paper_creation.js b/yaksh/static/yaksh/js/question_paper_creation.js
index 430ec4b..86294b3 100644
--- a/yaksh/static/yaksh/js/question_paper_creation.js
+++ b/yaksh/static/yaksh/js/question_paper_creation.js
@@ -61,3 +61,12 @@ $(document).ready(function(){
});
});//document
+function append_tag(tag){
+ var tag_name = document.getElementById("question_tags");
+ if (tag_name.value != null){
+ tag_name.value = tag.value+", "+tag_name.value;
+ }
+ else{
+ tag_name.value = tag.value;
+ }
+} \ No newline at end of file
diff --git a/yaksh/templates/yaksh/ajax_question_filter.html b/yaksh/templates/yaksh/ajax_question_filter.html
index a63354c..ea0d0b5 100644
--- a/yaksh/templates/yaksh/ajax_question_filter.html
+++ b/yaksh/templates/yaksh/ajax_question_filter.html
@@ -1,16 +1,49 @@
<div id="questions">
+ <script>
+ $(document).ready(function(){
+ $("#checkall").change(function(){
+ if($(this).prop("checked")) {
+ $("#filtered-questions input:checkbox").each(function(index, element) {
+ $(this).prop('checked', true);
+ });
+ }
+ else {
+ $("#filtered-questions input:checkbox").each(function(index, element) {
+ $(this).prop('checked', false);
+ });
+ }
+ });
+ });
+ </script>
{% if questions %}
- <h5 class="highlight"><input type="checkbox" id="checkall" class="ignore"> Select All </h5>
+ <h5 class="highlight"><input type="checkbox" id="checkall">
+ Select All
+ </h5>
+ <ul class="inputs-list">
+ <table id="questions-table" class="tablesorter table table table-striped">
+ <thead>
+ <tr>
+ <th> Select </th>
+ <th> Summary </th>
+ <th> Language </th>
+ <th> Type </th>
+ <th> Marks </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for question in questions %}
+ <tr>
+ <td>
+ <input type="checkbox" name="question" value="{{ question.id }}">
+ </td>
+ <td><a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{question.summary|capfirst}}</a></td>
+ <td>{{question.language|capfirst}}</td>
+ <td>{{question.type|capfirst}}</td>
+ <td>{{question.points}}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ </ul>
{% endif %}
- <ul class="inputs-list">
-
- {% for question in questions %}
- <li>
- <label>
- <input type="checkbox" name="question" data-qid="{{question.id}}" value=
- "{{question.id}}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ question.id }}">{{ question }}</a><br>
- </label>
- </li>
- {% endfor %}
- </ul>
</div>
diff --git a/yaksh/templates/yaksh/design_questionpaper.html b/yaksh/templates/yaksh/design_questionpaper.html
index 1656e2b..c56a955 100644
--- a/yaksh/templates/yaksh/design_questionpaper.html
+++ b/yaksh/templates/yaksh/design_questionpaper.html
@@ -68,8 +68,36 @@ select
</div>
</div> <!-- /.row -->
<br><br>
-
+ {% csrf_token %}
<div class="tab-pane active" id="fixed-questions">
+ <h4 style="padding-left: 20px;">Or</h4>
+ <!-- Search questions using tags -->
+ <h4 style="padding-left: 20px;">Search using Tags: </h4>
+ <div class="col-md-14">
+ <div class="input-group">
+ <span class="input-group-addon" id="basic-addon1">Search Questions </span>
+ <input type="text" id="question_tags" name="question_tags" class="form-control"
+ placeholder="Search using comma separated Tags">
+ <span class="input-group-btn">
+ <button class="btn btn-default" type="submit">Search</button>
+ </span>
+ <div class="col-md-6">
+ <select class="form-control" id="sel1" onchange="append_tag(this);">
+ {% if all_tags %}
+ <option value="" disabled selected>Available Tags</option>
+ {% for tag in all_tags %}
+ <option>
+ {{tag}}
+ </option>
+ {% endfor %}
+ {% else %}
+ <option value="" disabled selected>No Available Tags</option>
+ {% endif %}
+ </select>
+ </div>
+ </div>
+ </div>
+ <br><br>
<div class="row">
<div class="col-md-6">
<div id="fixed-available-wrapper">
@@ -116,7 +144,7 @@ select
</div> <!-- /.row -->
<br>
<div class="pull-right">
- <a class="btn" id="fixed-next">Next &gt;</a>
+ <a class="btn btn-primary" id="fixed-next">Next &gt;</a>
</div>
</div> <!-- /#fixed-questions -->
@@ -183,10 +211,10 @@ select
</div> <!-- /.row -->
<br>
<div class="pull-left">
- <a class="btn" id="random-prev">&lt; Previous</a>
+ <a class="btn btn-primary" id="random-prev">&lt; Previous</a>
</div>
<div class="pull-right">
- <a class="btn" id="random-next">Next &gt;</a>
+ <a class="btn btn-primary" id="random-next">Next &gt;</a>
</div>
</div> <!-- /#random-questions -->
@@ -200,7 +228,7 @@ select
<input class ="btn primary large" type="submit" name="save" id="save" value="Save question paper">
<br>
<div class="pull-left">
- <a class="btn" id="finish-prev">&lt; Previous</a>
+ <a class="btn btn-primary" id="finish-prev">&lt; Previous</a>
</div>
</center>
</div> <!-- /#finish -->
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 3b27338..8fa4747 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -4156,6 +4156,13 @@ class TestQuestionPaper(TestCase):
)
self.float_based_testcase.save()
+ # Question with tag
+ self.tagged_que = Question.objects.create(
+ summary="Test_tag_question", description="Test Tag",
+ points=1.0, language="python", type="float", user=self.teacher
+ )
+ self.tagged_que.tags.add("test_tag")
+
self.questions_list = [self.question_mcq, self.question_mcc,
self.question_int, self.question_str,
self.question_float]
@@ -4510,6 +4517,16 @@ class TestQuestionPaper(TestCase):
self.questions_list)
self.assertEqual(response.context['qpaper'], self.question_paper)
+ # Get questions using tags for question paper
+ search_tag = [tag for tag in self.tagged_que.tags.all()]
+ response = self.client.post(
+ reverse('yaksh:designquestionpaper',
+ kwargs={"quiz_id": self.quiz.id,
+ "course_id": self.course.id,
+ "questionpaper_id": self.question_paper.id}),
+ data={"question_tags": search_tag})
+ self.assertEqual(response.context["questions"][0], self.tagged_que)
+
class TestLearningModule(TestCase):
def setUp(self):
diff --git a/yaksh/views.py b/yaksh/views.py
index 011b417..5772df1 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1259,16 +1259,15 @@ def ajax_questions_filter(request):
question_type = request.POST.get('question_type')
marks = request.POST.get('marks')
language = request.POST.get('language')
-
- if question_type != "select":
+ if question_type:
filter_dict['type'] = str(question_type)
- if marks != "select":
+ if marks:
filter_dict['points'] = marks
- if language != "select":
+ if language:
filter_dict['language'] = str(language)
- questions = list(Question.objects.filter(**filter_dict))
+ questions = Question.objects.filter(**filter_dict)
return my_render_to_response(
'yaksh/ajax_question_filter.html', {'questions': questions}
@@ -1294,19 +1293,29 @@ def _remove_already_present(questionpaper_id, questions):
return questions
questionpaper = QuestionPaper.objects.get(pk=questionpaper_id)
questions = questions.exclude(
- id__in=questionpaper.fixed_questions.values_list('id', flat=True))
+ id__in=questionpaper.fixed_questions.values_list('id', flat=True))
for random_set in questionpaper.random_questions.all():
questions = questions.exclude(
- id__in=random_set.questions.values_list('id', flat=True))
+ id__in=random_set.questions.values_list('id', flat=True))
return questions
+def _get_questions_from_tags(question_tags, user):
+ search_tags = []
+ for tags in question_tags:
+ search_tags.extend(re.split('[; |, |\*|\n]', tags))
+ return Question.objects.filter(tags__name__in=search_tags,
+ user=user).distinct()
+
+
@login_required
@email_verified
def design_questionpaper(request, quiz_id, questionpaper_id=None,
course_id=None):
user = request.user
-
+ que_tags = Question.objects.filter(
+ active=True, user=user).values_list('tags', flat=True).distinct()
+ all_tags = Tag.objects.filter(id__in=que_tags)
if not is_moderator(user):
raise Http404('You are not allowed to view this page!')
if quiz_id:
@@ -1323,7 +1332,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None,
marks = None
state = None
if questionpaper_id is None:
- question_paper = QuestionPaper.objects.get_or_create(quiz_id=quiz_id)[0]
+ question_paper = QuestionPaper.objects.get_or_create(
+ quiz_id=quiz_id)[0]
else:
question_paper = get_object_or_404(QuestionPaper, id=questionpaper_id,
quiz_id=quiz_id)
@@ -1336,19 +1346,25 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None,
question_type = request.POST.get('question_type', None)
marks = request.POST.get('marks', None)
state = request.POST.get('is_active', None)
+ tags = request.POST.get('question_tags', None)
if 'add-fixed' in request.POST:
question_ids = request.POST.get('checked_ques', None)
- if question_paper.fixed_question_order:
- ques_order = question_paper.fixed_question_order.split(",") +\
- question_ids.split(",")
- questions_order = ",".join(ques_order)
- else:
- questions_order = question_ids
- questions = Question.objects.filter(id__in=question_ids.split(','))
- question_paper.fixed_question_order = questions_order
- question_paper.save()
- question_paper.fixed_questions.add(*questions)
+ if question_ids:
+ if question_paper.fixed_question_order:
+ ques_order = (
+ question_paper.fixed_question_order.split(",") +
+ question_ids.split(",")
+ )
+ questions_order = ",".join(ques_order)
+ else:
+ questions_order = question_ids
+ questions = Question.objects.filter(
+ id__in=question_ids.split(',')
+ )
+ question_paper.fixed_question_order = questions_order
+ question_paper.save()
+ question_paper.fixed_questions.add(*questions)
if 'remove-fixed' in request.POST:
question_ids = request.POST.getlist('added-questions', None)
@@ -1367,7 +1383,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None,
question_ids = request.POST.getlist('random_questions', None)
num_of_questions = request.POST.get('num_of_questions', 1)
if question_ids and marks:
- random_set = QuestionSet(marks=marks, num_questions=num_of_questions)
+ random_set = QuestionSet(marks=marks,
+ num_questions=num_of_questions)
random_set.save()
for question in Question.objects.filter(id__in=question_ids):
random_set.questions.add(question)
@@ -1383,6 +1400,11 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None,
if marks:
questions = _get_questions(user, question_type, marks)
+ elif tags:
+ que_tags = request.POST.getlist('question_tags', None)
+ questions = _get_questions_from_tags(que_tags, user)
+
+ if questions:
questions = _remove_already_present(questionpaper_id, questions)
question_paper.update_total_marks()
@@ -1397,7 +1419,8 @@ def design_questionpaper(request, quiz_id, questionpaper_id=None,
'fixed_questions': fixed_questions,
'state': state,
'random_sets': random_sets,
- 'course_id': course_id
+ 'course_id': course_id,
+ 'all_tags': all_tags
}
return my_render_to_response(
'yaksh/design_questionpaper.html',
@@ -1420,7 +1443,7 @@ def show_all_questions(request):
questions = Question.objects.filter(user_id=user.id, active=True)
form = QuestionFilterForm(user=user)
user_tags = questions.values_list('tags', flat=True).distinct()
- all_tags = Tag.objects.filter(id__in = user_tags)
+ all_tags = Tag.objects.filter(id__in=user_tags)
upload_form = UploadFileForm()
context['questions'] = questions
context['all_tags'] = all_tags
@@ -1433,8 +1456,8 @@ def show_all_questions(request):
if request.POST.get('delete') == 'delete':
data = request.POST.getlist('question')
if data is not None:
- questions = Question.objects.filter(id__in=data, user_id=user.id,
- active=True)
+ questions = Question.objects.filter(
+ id__in=data, user_id=user.id, active=True)
for question in questions:
question.active = False
question.save()
@@ -1466,7 +1489,8 @@ def show_all_questions(request):
response.write(zip_file.read())
return response
else:
- context['msg'] = "Please select atleast one question to download"
+ context['msg'] = """Please select atleast one
+ question to download"""
if request.POST.get('test') == 'test':
question_ids = request.POST.getlist("question")
@@ -1482,11 +1506,7 @@ def show_all_questions(request):
if request.POST.get('question_tags'):
question_tags = request.POST.getlist("question_tags")
- search_tags = []
- for tags in question_tags:
- search_tags.extend(re.split('[; |, |\*|\n]',tags))
- search_result = Question.objects.filter(tags__name__in=search_tags,
- user=user).distinct()
+ search_result = _get_questions_from_tags(question_tags, user)
context['questions'] = search_result
return my_render_to_response('yaksh/showquestions.html', context,