summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildout.cfg1
-rw-r--r--testapp/exam/models.py11
-rw-r--r--testapp/exam/urls.py1
-rw-r--r--testapp/exam/views.py197
-rw-r--r--testapp/settings.py2
-rw-r--r--testapp/templates/exam/manual_questionpaper.html69
-rw-r--r--testapp/templates/exam/showquestionpapers.html2
7 files changed, 245 insertions, 38 deletions
diff --git a/buildout.cfg b/buildout.cfg
index 02aba05..486e68e 100644
--- a/buildout.cfg
+++ b/buildout.cfg
@@ -7,6 +7,7 @@ eggs =
django-taggit-autocomplete-modified
django-debug-toolbar
+versions = versions
[versions]
django = 1.3
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index ad3dad8..dd0c033 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -2,7 +2,7 @@ import datetime
from django.db import models
from django.contrib.auth.models import User
from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete as TaggableManager
-
+from django.http import HttpResponse
################################################################################
class Profile(models.Model):
"""Profile for a user to store roll number and other details."""
@@ -120,7 +120,10 @@ class AnswerPaper(models.Model):
# The user's profile, we store a reference to make it easier to access the
# data.
profile = models.ForeignKey(Profile)
-
+
+ # All questions that remains to attempt to perticular Student
+ questions = models.CharField(max_length=128)
+
# The Quiz to which this question paper is attached to.
question_paper = models.ForeignKey(QuestionPaper)
@@ -157,7 +160,7 @@ class AnswerPaper(models.Model):
def completed_question(self, question_id):
"""Removes the question from the list of questions and returns
- the next."""
+the next."""
qa = self.questions_answered
if len(qa) > 0:
self.questions_answered = '|'.join([qa, str(question_id)])
@@ -193,7 +196,7 @@ class AnswerPaper(models.Model):
except AttributeError:
# total_seconds is new in Python 2.7. :(
secs = dt.seconds + dt.days*24*3600
- total = self.quiz.duration*60.0
+ total = self.question_paper.quiz.duration*60.0
remain = max(total - secs, 0)
return int(remain)
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index 4651204..e7284f2 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -33,6 +33,7 @@ urlpatterns = patterns('exam.views',
url(r'^manage/designquestionpaper/automatic/(?P<questionpaper_id>\d+)/$','automatic_questionpaper'),
url(r'^manage/designquestionpaper/automatic$','automatic_questionpaper'),
url(r'^manage/designquestionpaper/manual$','manual_questionpaper'),
+ url(r'^manage/designquestionpaper/manual/(?P<questionpaper_id>\d+)/$','manual_questionpaper'),
)
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 464bc3c..b742785 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -14,7 +14,7 @@ from django.db.models import Sum
from taggit.models import Tag
from itertools import chain
# Local imports.
-from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, User
+from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, AnswerPaper, User
from exam.forms import UserRegisterForm, UserLoginForm, QuizForm , QuestionForm
from exam.xmlrpc_clients import code_server
from settings import URL_ROOT
@@ -308,7 +308,19 @@ def show_all_questionpapers(request,questionpaper_id=None):
if request.method=="POST" and request.POST.get('add') == "add":
return my_redirect("/exam/manage/designquestionpaper/" + questionpaper_id)
-
+
+ if request.method=="POST" and request.POST.get('delete') == "delete":
+ data = request.POST.getlist('papers')
+ for i in data:
+ q_paper = QuestionPaper.objects.get(id=i).delete()
+ question_paper= QuestionPaper.objects.all()
+ context = {'papers': question_paper, }
+ return my_render_to_response('exam/showquestionpapers.html', context,
+ context_instance=RequestContext(request))
+ qu_papers = QuestionPaper.objects.all()
+ context = {'papers':qu_papers}
+ return my_render_to_response('exam/showquestionpapers.html',context,context_instance=RequestContext(request))
+
if questionpaper_id == None:
qu_papers = QuestionPaper.objects.all()
context = {'papers':qu_papers}
@@ -340,7 +352,6 @@ def automatic_questionpaper(request,questionpaper_id=None):
quest_paper.quiz = quiz
quest_paper.save()
for i in set2:
- print str(i.id) + " " + i.summary
q = Question.objects.get(summary=i)
quest_paper.questions.add(q)
return my_redirect('/exam/manage/showquiz')
@@ -385,13 +396,152 @@ def automatic_questionpaper(request,questionpaper_id=None):
return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request))
else:
- return HttpResponse("eni mane pochi gaya ayan... ")
+ if request.method=="POST":
+ if request.POST.get('save') == 'save' :
+ quest_paper = QuestionPaper.objects.get(id=questionpaper_id)
+ for i in set2:
+ print str(i.id) + " " + i.summary
+ q = Question.objects.get(summary=i)
+ quest_paper.questions.add(q)
+ return my_redirect('/exam/manage/showquiz')
+ else:
+ set1 = set()
+ set2 = set()
+ no_questions = int(request.POST.get('questions'))
+ first_tag = request.POST.get('first_tag')
+ first_condition = request.POST.get('first_condition')
+ second_tag = request.POST.get('second_tag')
+ second_condition = request.POST.get('second_condition')
+ third_tag = request.POST.get('third_tag')
+ question1 = set(Question.objects.filter(tags__name__in=[first_tag]))
+ question2 = set(Question.objects.filter(tags__name__in=[second_tag]))
+ question3 = set(Question.objects.filter(tags__name__in=[third_tag]))
+ if first_condition == 'and':
+ set1 = question1.intersection(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ else:
+ set1 = question1.union(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ n = len(set2)
+ msg = ''
+ if (no_questions < n ) :
+ i = n - no_questions
+ for i in range(0,i):
+ set2.pop()
+ elif( no_questions > n):
+ msg = 'The given Criteria does not satisfy the number of Questions...'
+ tags = Tag.objects.all()
+ context = {'data':{'questions':set2,'tags':tags,'msg':msg}}
+ return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request))
+ else:
+ tags = Tag.objects.all()
+ context = {'data':{'tags':tags}}
+ return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request))
-def manual_questionpaper(request):
+def manual_questionpaper(request,questionpaper_id=None):
user=request.user
+ global set1
+ global set2
if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 :
raise Http404('You are not allowed to view this page!')
- return my_render_to_response('exam/manual_questionpaper.html',{},context_instance=RequestContext(request))
+
+ if questionpaper_id == None:
+ if request.method=="POST":
+ if request.POST.get('save') == 'save' :
+ questions = request.POST.getlist('questions')
+ quiz = Quiz.objects.order_by("-id")[0]
+ quest_paper = QuestionPaper()
+ quest_paper.quiz = quiz
+ quest_paper.save()
+ for i in questions:
+ q = Question.objects.get(id=i)
+ quest_paper.questions.add(q)
+ return my_redirect('/exam/manage/showquiz')
+ else:
+ set1 = set()
+ set2 = set()
+ first_tag = request.POST.get('first_tag')
+ first_condition = request.POST.get('first_condition')
+ second_tag = request.POST.get('second_tag')
+ second_condition = request.POST.get('second_condition')
+ third_tag = request.POST.get('third_tag')
+ question1 = set(Question.objects.filter(tags__name__in=[first_tag]))
+ question2 = set(Question.objects.filter(tags__name__in=[second_tag]))
+ question3 = set(Question.objects.filter(tags__name__in=[third_tag]))
+ if first_condition == 'and':
+ set1 = question1.intersection(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ else:
+ set1 = question1.union(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ n = len(set2)
+ msg = ''
+ if (n == 0) :
+ msg = 'No matching Question found...'
+ tags = Tag.objects.all()
+ context = {'data':{'questions':set2,'tags':tags,'msg':msg}}
+ return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request))
+ else:
+ tags = Tag.objects.all()
+ context = {'data':{'tags':tags}}
+ return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request))
+
+ else:
+ if request.method=="POST":
+ if request.POST.get('save') == 'save' :
+ quest_paper = QuestionPaper.objects.get(id=questionpaper_id)
+ questions = request.POST.getlist('questions')
+ for i in questions:
+ q = Question.objects.get(id=i)
+ quest_paper.questions.add(q)
+ return my_redirect('/exam/manage/showquiz')
+ else:
+ set1 = set()
+ set2 = set()
+ first_tag = request.POST.get('first_tag')
+ first_condition = request.POST.get('first_condition')
+ second_tag = request.POST.get('second_tag')
+ second_condition = request.POST.get('second_condition')
+ third_tag = request.POST.get('third_tag')
+ question1 = set(Question.objects.filter(tags__name__in=[first_tag]))
+ question2 = set(Question.objects.filter(tags__name__in=[second_tag]))
+ question3 = set(Question.objects.filter(tags__name__in=[third_tag]))
+ if first_condition == 'and':
+ set1 = question1.intersection(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ else:
+ set1 = question1.union(question2)
+ if second_condition == 'and':
+ set2 = set1.intersection(question3)
+ else:
+ set2 = set1.union(question3)
+ n = len(set2)
+ msg = ''
+ if (n == 0) :
+ msg = 'No matching Question found...'
+ tags = Tag.objects.all()
+ context = {'data':{'questions':set2,'tags':tags,'msg':msg}}
+ return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request))
+ else:
+ tags = Tag.objects.all()
+ context = {'data':{'tags':tags}}
+ return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request))
+
@@ -438,17 +588,17 @@ def start(request):
try:
# Right now the app is designed so there is only one active quiz
# at a particular time.
- quiz = Quiz.objects.get(active=True)
- except Quiz.DoesNotExist:
+ questionpaper = QuestionPaper.objects.all()[0]
+ except QuestionPaper.DoesNotExist:
msg = 'Quiz not found, please contact your '\
'instructor/administrator. Please login again thereafter.'
return complete(request, reason=msg)
try:
- old_paper = QuestionPaper.objects.get(user=user, quiz=quiz)
+ old_paper = AnswerPaper.objects.get(user=user, question_paper=questionpaper)
q = old_paper.current_question()
return show_question(request, q)
- except QuestionPaper.DoesNotExist:
+ except AnswerPaper.DoesNotExist:
ip = request.META['REMOTE_ADDR']
key = gen_key(10)
try:
@@ -457,16 +607,18 @@ def start(request):
msg = 'You do not have a profile and cannot take the quiz!'
raise Http404(msg)
- new_paper = QuestionPaper(user=user, user_ip=ip, key=key,
- quiz=quiz, profile=profile)
+ new_paper = AnswerPaper(user=user, user_ip=ip,
+ question_paper=questionpaper, profile=profile)
new_paper.start_time = datetime.datetime.now()
# Make user directory.
user_dir = get_user_dir(user)
- questions = [ str(_.id) for _ in Question.objects.filter(active=True) ]
+ questions = [ str(_.id) for _ in questionpaper.questions.all() ]
random.shuffle(questions)
-
+
+ #questions = questionpaper.questions
+ #random.shuffle(questions)
new_paper.questions = "|".join(questions)
new_paper.save()
@@ -484,16 +636,17 @@ def question(request, q_id):
return my_redirect('/exam/login/')
q = get_object_or_404(Question, pk=q_id)
try:
- paper = QuestionPaper.objects.get(user=request.user, quiz__active=True)
- except QuestionPaper.DoesNotExist:
+ q_paper = QuestionPaper.objects.get(quiz__active=True)
+ paper = AnswerPaper.objects.get(user=request.user, question_paper=q_paper)
+ except AnswerPaper.DoesNotExist:
return my_redirect('/exam/start')
- if not paper.quiz.active:
+ if not paper.question_paper.quiz.active:
return complete(request, reason='The quiz has been deactivated!')
time_left = paper.time_left()
if time_left == 0:
return complete(request, reason='Your time is up!')
- quiz_name = paper.quiz.description
+ quiz_name = paper.question_paper.quiz.description
context = {'question': q, 'paper': paper, 'user': user,
'quiz_name': quiz_name,
'time_left': time_left}
@@ -503,7 +656,6 @@ def question(request, q_id):
def show_question(request, q_id):
"""Show a question if possible."""
-
if len(q_id) == 0:
msg = 'Congratulations! You have successfully completed the quiz.'
return complete(request, msg)
@@ -517,7 +669,8 @@ def check(request, q_id):
if not user.is_authenticated():
return my_redirect('/exam/login/')
question = get_object_or_404(Question, pk=q_id)
- paper = QuestionPaper.objects.get(user=user, quiz__active=True)
+ q_paper = QuestionPaper.objects.get(quiz__active=True)
+ paper = AnswerPaper.objects.get(user=request.user,question_paper = q_paper)
answer = request.POST.get('answer')
skip = request.POST.get('skip', None)
@@ -557,12 +710,12 @@ def check(request, q_id):
time_left = paper.time_left()
if time_left == 0:
return complete(request, reason='Your time is up!')
- if not paper.quiz.active:
+ if not paper.question_paper.quiz.active:
return complete(request, reason='The quiz has been deactivated!')
context = {'question': question, 'error_message': err_msg,
'paper': paper, 'last_attempt': answer,
- 'quiz_name': paper.quiz.description,
+ 'quiz_name': paper.question_paper.quiz.description,
'time_left': time_left}
ci = RequestContext(request)
diff --git a/testapp/settings.py b/testapp/settings.py
index 92a597b..39331ce 100644
--- a/testapp/settings.py
+++ b/testapp/settings.py
@@ -148,7 +148,7 @@ INSTALLED_APPS = (
'taggit',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
- 'south',
+# 'south',
'exam',
'taggit_autocomplete_modified',
'debug_toolbar',
diff --git a/testapp/templates/exam/manual_questionpaper.html b/testapp/templates/exam/manual_questionpaper.html
index 96370c0..47df1ed 100644
--- a/testapp/templates/exam/manual_questionpaper.html
+++ b/testapp/templates/exam/manual_questionpaper.html
@@ -6,6 +6,12 @@
{% block css %}
<link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/question_quiz.css" type="text/css" />
<link rel="stylesheet" media="all" type="text/css" href="{{ URL_ROOT }}/static/exam/css/autotaggit.css" />
+<style>
+select
+{
+ width:auto;
+}
+</style>
{% endblock %}
{% block script %}
<script src="/static/taggit_autocomplete_modified/jquery.min.js" type="text/javascript"></script>
@@ -28,15 +34,60 @@ function load_data()
{% endblock %}
{% block manage %}
-<form >
-{% csrf_token %}
-Select mode to design Question Paper:
-<select name='mode' id='mode' onChange='javascript:load_data();'>
- <option>Manual</option>
- <option>Automatic</option>
-</select>
-</form>
-
+<center><b>Manual mode to design the Question Paper</center><br>
+<form action="" method="post" name=frm>
+ {% csrf_token %}
+ <center>
+ Tag Conditions:
+ <select name='first_tag'>
+ <option value="">Select Tag </option>
+ {% for tag in data.tags %}
+ <option value={{tag}}>{{tag}}</option>
+ {% endfor %}
+ </select>
+ <select name='first_condition'>
+ <option value="or">OR</option>
+ <option value="and">AND</option>
+ </select>
+ <select name='second_tag'>
+ <option value="">Select Tag </option>
+ {% for tag in data.tags %}
+ <option value={{tag}}>{{tag}}</option>
+ {% endfor %}
+ </select>
+ <select name='second_condition'>
+ <option value="or">OR</option>
+ <option value="and">AND</option>
+ </select>
+ <select name='third_tag'>
+ <option value="null">Select Tag </option>
+ {% for tag in data.tags %}
+ <option value={{tag}}>{{tag}}</option>
+ {% endfor %}
+ </select>
+ </center>
+ <br>
+ <center><button class=btn type=submit name='fetch' value='fetch'>Fetch Questions</button>
+ <br><br><b>Below is the list of Questions fetched according to the given tag conditions</b></center>
+ <hr>
+ <center><table class=span10>
+ <th> &nbsp;
+ <th>Summary
+ <th>Type
+ <th>Points
+ <th>Tags
+ {% for question in data.questions %}
+ <tr><td><input type=checkbox name=questions value={{question.id}}> <td> {{ question.summary }} <td>{{ question.type }} <td>{{ question.points }} <td>
+ {% for tag in question.tags.all %}
+ {{ tag }}
+ {% endfor %}
+ </tr>
+ <br>
+ {% endfor %}
+ </table>
+ {% if data.msg %}<div class="alert alert-error">{{ data.msg }}</div>{% endif %}
+ <center><button class=btn type=submit name='save' value='save'>Save Question Paper</button></center>
+</form>
{% endblock %}
diff --git a/testapp/templates/exam/showquestionpapers.html b/testapp/templates/exam/showquestionpapers.html
index 7a77d2f..26b756d 100644
--- a/testapp/templates/exam/showquestionpapers.html
+++ b/testapp/templates/exam/showquestionpapers.html
@@ -14,8 +14,6 @@
<input type="checkbox" name="papers" value="{{ i.id }}">&nbsp;&nbsp;<a href="{{URL_ROOT}}/exam/manage/showquestionpapers/{{ i.id }}">{{ i.quiz.description }}</a><br>
{% endfor %}
<br>
-<button class="btn" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button>&nbsp;&nbsp;
-<button class="btn" type="submit" name='edit' value='edit' onClick="return confirm_edit(frm);">Edit Selected</button>&nbsp;&nbsp;
<button class="btn" type="submit" onClick="return confirm_delete(frm);" name='delete' value='delete'>Delete Selected</button>
</form>
{% endblock %}