summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2016-05-04 22:55:19 +0530
committeradityacp2016-05-04 22:55:19 +0530
commit2f7891874aec1dec962d55e3b2aaed1c61d7acaa (patch)
tree8c95b44a16ec6359d18975d0d4f5ab229ba98f24
parent5bb441584628e65fe08ce1f240ad43f5f3ca88a8 (diff)
downloadonline_test-2f7891874aec1dec962d55e3b2aaed1c61d7acaa.tar.gz
online_test-2f7891874aec1dec962d55e3b2aaed1c61d7acaa.tar.bz2
online_test-2f7891874aec1dec962d55e3b2aaed1c61d7acaa.zip
rebase changes and changes as per comments
-rw-r--r--yaksh/templates/yaksh/showquestions.html9
-rw-r--r--yaksh/tests.py14
-rw-r--r--yaksh/urls.py4
-rw-r--r--yaksh/views.py54
4 files changed, 39 insertions, 42 deletions
diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html
index 19fc06e..6e2253a 100644
--- a/yaksh/templates/yaksh/showquestions.html
+++ b/yaksh/templates/yaksh/showquestions.html
@@ -19,9 +19,11 @@
<form action="{{URL_ROOT}}/exam/manage/upload_questions/" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ upload_form.as_p }}
-<button class="btn" type="submit">Upload File</button>
+<button class="btn" type="submit" name="upload" value="upload">Upload File</button>
</form>
-
+{% if message %}
+<h4>{{ message }}</h4>
+{% endif %}
<form name=frm action="" method="post">
{% csrf_token %}
<div class="row" id="selectors">
@@ -45,9 +47,12 @@
<br>
<div id="filtered-questions">
+{% if questions %}
+<h5 class="highlight"><input id="checkall" class="ignore" type="checkbox"> Select All </h5>
{% for i in questions %}
<input type="checkbox" name="question" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{ i }}</a><br>
{% endfor %}
+{% endif %}
</div>
<br>
<button class="btn" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button>&nbsp;&nbsp;
diff --git a/yaksh/tests.py b/yaksh/tests.py
index eedcd30..a3f3880 100644
--- a/yaksh/tests.py
+++ b/yaksh/tests.py
@@ -135,14 +135,14 @@ class QuestionTestCases(unittest.TestCase):
""" Test dump questions into json """
question = Question()
questions = json.loads(question.dump_into_json(self.user1))
- for que in questions:
- self.assertEqual(self.question1.summary, que['summary'])
- self.assertEqual(self.question1.language, que['language'])
- self.assertEqual(self.question1.type, que['type'])
- self.assertEqual(self.question1.description, que['description'])
- self.assertEqual(self.question1.points, que['points'])
+ for q in questions:
+ self.assertEqual(self.question1.summary, q['summary'])
+ self.assertEqual(self.question1.language, q['language'])
+ self.assertEqual(self.question1.type, q['type'])
+ self.assertEqual(self.question1.description, q['description'])
+ self.assertEqual(self.question1.points, q['points'])
self.assertTrue(self.question1.active)
- self.assertEqual(self.question1.snippet, que['snippet'])
+ self.assertEqual(self.question1.snippet, q['snippet'])
def test_load_questions_from_json(self):
""" Test load questions into database from json """
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 533a6f9..f660ed7 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -88,9 +88,9 @@ urlpatterns += [
url(r'^manage/searchteacher/(?P<course_id>\d+)/$', views.search_teacher),
url(r'^manage/addteacher/(?P<course_id>\d+)/$', views.add_teacher),
url(r'^manage/allotted_course/$', views.allotted_courses),
- url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers)
+ url(r'^manage/remove_teachers/(?P<course_id>\d+)/$', views.remove_teachers),
url(r'^manage/download_questions/$', views.download_questions),
- url(r'^manage/upload_questions/$', views.upload_questions)
+ url(r'^manage/upload_questions/$', views.show_all_questions)
]
diff --git a/yaksh/views.py b/yaksh/views.py
index 8b69619..2dde09f 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -783,7 +783,7 @@ def ajax_questions_filter(request):
"""Ajax call made when filtering displayed questions."""
user = request.user
- filter_dict = {}
+ filter_dict = {"user_id":user.id}
question_type = request.POST.get('question_type')
marks = request.POST.get('marks')
language = request.POST.get('language')
@@ -797,7 +797,7 @@ def ajax_questions_filter(request):
if language != "select":
filter_dict['language'] = str(language)
- questions = list(Question.objects.filter(**filter_dict).filter(user_id=user.id))
+ questions = list(Question.objects.filter(**filter_dict))
return my_render_to_response('yaksh/ajax_question_filter.html',
{'questions': questions})
@@ -809,23 +809,35 @@ def show_all_questions(request):
user = request.user
ci = RequestContext(request)
- if not user.is_authenticated() or not is_moderator(user):
+ context = {}
+ if not is_moderator(user):
raise Http404("You are not allowed to view this page !")
if request.method == 'POST' and request.POST.get('delete') == 'delete':
data = request.POST.getlist('question')
if data is not None:
- for i in data:
- question = Question.objects.get(id=i).delete()
+ question = Question.objects.filter(id__in=data, user_id=user.id).delete()
+
+ if request.method == 'POST' and request.POST.get('upload') == 'upload':
+ form = UploadFileForm(request.POST, request.FILES)
+ if form.is_valid():
+ questions_file = request.FILES['file']
+ if questions_file.name.split('.')[-1] == "json":
+ questions_list = questions_file.read()
+ question = Question()
+ question.load_from_json(questions_list, user)
+ else:
+ message = "Please Upload a JSON file"
+ context['message'] = message
+
questions = Question.objects.filter(user_id=user.id)
form = QuestionFilterForm(user=user)
upload_form = UploadFileForm()
- context = {'papers': [],
- 'question': None,
- 'questions': questions,
- 'form': form,
- 'upload_form': upload_form
- }
+ context['papers'] = []
+ context['question'] = None
+ context['questions'] = questions
+ context['form'] = form
+ context['upload_form'] = upload_form
return my_render_to_response('yaksh/showquestions.html', context,
context_instance=ci)
@@ -1172,23 +1184,3 @@ def download_questions(request):
.format(user)
return response
-
-@login_required
-def upload_questions(request):
- user = request.user
- ci = RequestContext(request)
-
- if not is_moderator(user):
- raise Http404('You are not allowed to view this page!')
- if request.method == 'POST':
- form = UploadFileForm(request.POST, request.FILES)
- if form.is_valid():
- questions_file = request.FILES['file']
- if questions_file.name.split('.')[1] == "json":
- questions_list = questions_file.read()
- question = Question()
- question.load_from_json(questions_list, user)
- return my_redirect('/exam/manage/questions')
- else:
- raise Http404("Please Upload a JSON file")
- return my_redirect('/exam/manage/questions')