summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
authorhardythe12012-04-02 18:04:43 +0530
committerhardythe12012-04-02 18:04:43 +0530
commitc0fcc1181e209192f6d11f2ca521e55e33a4ead7 (patch)
tree576b100053a4ef35d4e686ce198f2882d98efbb2 /testapp/exam
parent64b38d3365f1d65132942fce6e29fed7da076bba (diff)
downloadonline_test-c0fcc1181e209192f6d11f2ca521e55e33a4ead7.tar.gz
online_test-c0fcc1181e209192f6d11f2ca521e55e33a4ead7.tar.bz2
online_test-c0fcc1181e209192f6d11f2ca521e55e33a4ead7.zip
Question Paper generator changes
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/migrations/0001_initial.py193
-rw-r--r--testapp/exam/migrations/__init__.py0
-rw-r--r--testapp/exam/models.py15
-rw-r--r--testapp/exam/urls.py8
-rw-r--r--testapp/exam/views.py108
5 files changed, 119 insertions, 205 deletions
diff --git a/testapp/exam/migrations/0001_initial.py b/testapp/exam/migrations/0001_initial.py
deleted file mode 100644
index 49048cc..0000000
--- a/testapp/exam/migrations/0001_initial.py
+++ /dev/null
@@ -1,193 +0,0 @@
-# encoding: utf-8
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
-
- # Adding model 'Profile'
- db.create_table('exam_profile', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('user', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['auth.User'], unique=True)),
- ('roll_number', self.gf('django.db.models.fields.CharField')(max_length=20)),
- ('institute', self.gf('django.db.models.fields.CharField')(max_length=128)),
- ('department', self.gf('django.db.models.fields.CharField')(max_length=64)),
- ('position', self.gf('django.db.models.fields.CharField')(max_length=64)),
- ))
- db.send_create_signal('exam', ['Profile'])
-
- # Adding model 'Question'
- db.create_table('exam_question', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('summary', self.gf('django.db.models.fields.CharField')(max_length=256)),
- ('description', self.gf('django.db.models.fields.TextField')()),
- ('points', self.gf('django.db.models.fields.FloatField')(default=1.0)),
- ('test', self.gf('django.db.models.fields.TextField')(blank=True)),
- ('options', self.gf('django.db.models.fields.TextField')(blank=True)),
- ('type', self.gf('django.db.models.fields.CharField')(max_length=24)),
- ('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
- ))
- db.send_create_signal('exam', ['Question'])
-
- # Adding model 'Answer'
- db.create_table('exam_answer', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('question', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['exam.Question'])),
- ('answer', self.gf('django.db.models.fields.TextField')()),
- ('error', self.gf('django.db.models.fields.TextField')()),
- ('marks', self.gf('django.db.models.fields.FloatField')(default=0.0)),
- ('correct', self.gf('django.db.models.fields.BooleanField')(default=False)),
- ))
- db.send_create_signal('exam', ['Answer'])
-
- # Adding model 'Quiz'
- db.create_table('exam_quiz', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('start_date', self.gf('django.db.models.fields.DateField')()),
- ('duration', self.gf('django.db.models.fields.IntegerField')(default=20)),
- ('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
- ('description', self.gf('django.db.models.fields.CharField')(max_length=256)),
- ))
- db.send_create_signal('exam', ['Quiz'])
-
- # Adding model 'QuestionPaper'
- db.create_table('exam_questionpaper', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])),
- ('profile', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['exam.Profile'])),
- ('quiz', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['exam.Quiz'])),
- ('start_time', self.gf('django.db.models.fields.DateTimeField')()),
- ('user_ip', self.gf('django.db.models.fields.CharField')(max_length=15)),
- ('key', self.gf('django.db.models.fields.CharField')(max_length=10)),
- ('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
- ('questions', self.gf('django.db.models.fields.CharField')(max_length=128)),
- ('questions_answered', self.gf('django.db.models.fields.CharField')(max_length=128)),
- ('comments', self.gf('django.db.models.fields.TextField')()),
- ))
- db.send_create_signal('exam', ['QuestionPaper'])
-
- # Adding M2M table for field answers on 'QuestionPaper'
- db.create_table('exam_questionpaper_answers', (
- ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
- ('questionpaper', models.ForeignKey(orm['exam.questionpaper'], null=False)),
- ('answer', models.ForeignKey(orm['exam.answer'], null=False))
- ))
- db.create_unique('exam_questionpaper_answers', ['questionpaper_id', 'answer_id'])
-
-
- def backwards(self, orm):
-
- # Deleting model 'Profile'
- db.delete_table('exam_profile')
-
- # Deleting model 'Question'
- db.delete_table('exam_question')
-
- # Deleting model 'Answer'
- db.delete_table('exam_answer')
-
- # Deleting model 'Quiz'
- db.delete_table('exam_quiz')
-
- # Deleting model 'QuestionPaper'
- db.delete_table('exam_questionpaper')
-
- # Removing M2M table for field answers on 'QuestionPaper'
- db.delete_table('exam_questionpaper_answers')
-
-
- models = {
- 'auth.group': {
- 'Meta': {'object_name': 'Group'},
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
- 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
- },
- 'auth.permission': {
- 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
- 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
- },
- 'auth.user': {
- 'Meta': {'object_name': 'User'},
- 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
- 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
- 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
- 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
- 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
- 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
- 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
- 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
- },
- 'contenttypes.contenttype': {
- 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
- 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
- },
- 'exam.answer': {
- 'Meta': {'object_name': 'Answer'},
- 'answer': ('django.db.models.fields.TextField', [], {}),
- 'correct': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
- 'error': ('django.db.models.fields.TextField', [], {}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'marks': ('django.db.models.fields.FloatField', [], {'default': '0.0'}),
- 'question': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exam.Question']"})
- },
- 'exam.profile': {
- 'Meta': {'object_name': 'Profile'},
- 'department': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'institute': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'position': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
- 'roll_number': ('django.db.models.fields.CharField', [], {'max_length': '20'}),
- 'user': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True'})
- },
- 'exam.question': {
- 'Meta': {'object_name': 'Question'},
- 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
- 'description': ('django.db.models.fields.TextField', [], {}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'options': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
- 'points': ('django.db.models.fields.FloatField', [], {'default': '1.0'}),
- 'summary': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
- 'test': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
- 'type': ('django.db.models.fields.CharField', [], {'max_length': '24'})
- },
- 'exam.questionpaper': {
- 'Meta': {'object_name': 'QuestionPaper'},
- 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
- 'answers': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['exam.Answer']", 'symmetrical': 'False'}),
- 'comments': ('django.db.models.fields.TextField', [], {}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'key': ('django.db.models.fields.CharField', [], {'max_length': '10'}),
- 'profile': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exam.Profile']"}),
- 'questions': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'questions_answered': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
- 'quiz': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['exam.Quiz']"}),
- 'start_time': ('django.db.models.fields.DateTimeField', [], {}),
- 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
- 'user_ip': ('django.db.models.fields.CharField', [], {'max_length': '15'})
- },
- 'exam.quiz': {
- 'Meta': {'object_name': 'Quiz'},
- 'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
- 'description': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
- 'duration': ('django.db.models.fields.IntegerField', [], {'default': '20'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'start_date': ('django.db.models.fields.DateField', [], {})
- }
- }
-
- complete_apps = ['exam']
diff --git a/testapp/exam/migrations/__init__.py b/testapp/exam/migrations/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/testapp/exam/migrations/__init__.py
+++ /dev/null
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index da45e7d..ad3dad8 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -105,9 +105,13 @@ class Quiz(models.Model):
desc = self.description or 'Quiz'
return '%s: on %s for %d minutes'%(desc, self.start_date, self.duration)
-
################################################################################
class QuestionPaper(models.Model):
+ quiz = models.ForeignKey(Quiz)
+ questions = models.ManyToManyField(Question)
+
+################################################################################
+class AnswerPaper(models.Model):
"""A question paper for a student -- one per student typically.
"""
# The user taking this question paper.
@@ -118,21 +122,14 @@ class QuestionPaper(models.Model):
profile = models.ForeignKey(Profile)
# The Quiz to which this question paper is attached to.
- quiz = models.ForeignKey(Quiz)
+ question_paper = models.ForeignKey(QuestionPaper)
# The time when this paper was started by the user.
start_time = models.DateTimeField()
# User's IP which is logged.
user_ip = models.CharField(max_length=15)
- # Unused currently.
- key = models.CharField(max_length=10)
- # used to allow/stop a user from retaking the question paper.
- active = models.BooleanField(default = True)
-
- # The questions (a list of ids separated by '|')
- questions = models.CharField(max_length=128)
# The questions successfully answered (a list of ids separated by '|')
questions_answered = models.CharField(max_length=128)
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py
index f435e63..4651204 100644
--- a/testapp/exam/urls.py
+++ b/testapp/exam/urls.py
@@ -24,9 +24,15 @@ urlpatterns = patterns('exam.views',
url(r'^manage/questions/$', 'show_all_questions'),
url(r'^manage/showquiz/$','show_all_quiz'),
url(r'^manage/monitor/$', 'monitor'),
+ url(r'^manage/showquestionpapers/$','show_all_questionpapers'),
+ url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$', 'show_all_questionpapers'),
url(r'^manage/monitor/(?P<quiz_id>\d+)/$', 'monitor'),
url(r'^manage/user_data/(?P<username>[a-zA-Z0-9_.]+)/$', 'user_data'),
-
+ url(r'^manage/designquestionpaper/$','design_questionpaper'),
+ url(r'^manage/designquestionpaper/(?P<questionpaper_id>\d+)/$', 'design_questionpaper'),
+ 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'),
)
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 5b980f5..464bc3c 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -11,7 +11,8 @@ from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from django.http import Http404
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.forms import UserRegisterForm, UserLoginForm, QuizForm , QuestionForm
@@ -20,6 +21,8 @@ from settings import URL_ROOT
# The directory where user data can be saved.
OUTPUT_DIR = abspath(join(dirname(__file__), pardir, 'output'))
+set1 = set()
+set2 = set()
def my_redirect(url):
"""An overridden redirect to deal with URL_ROOT-ing. See settings.py
@@ -245,7 +248,7 @@ def add_quiz(request,quiz_id=None):
for tag in tags:
tag = tag.strip()
quiz.tags.add(tag)
- return my_redirect("/exam/manage/showquiz")
+ return my_redirect("/exam/manage/designquestionpaper")
else:
d = Quiz.objects.get(id=quiz_id)
d.start_date = form['start_date'].data
@@ -291,6 +294,107 @@ def add_quiz(request,quiz_id=None):
return my_render_to_response('exam/add_quiz.html',{'form':form},context_instance=RequestContext(request))
+def design_questionpaper(request,questionpaper_id=None):
+ user=request.user
+ 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/add_questionpaper.html',{},context_instance=RequestContext(request))
+
+
+def show_all_questionpapers(request,questionpaper_id=None):
+ user=request.user
+ if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 :
+ raise Http404('You are not allowed to view this page!')
+
+ if request.method=="POST" and request.POST.get('add') == "add":
+ return my_redirect("/exam/manage/designquestionpaper/" + questionpaper_id)
+
+ if questionpaper_id == None:
+ qu_papers = QuestionPaper.objects.all()
+ context = {'papers':qu_papers}
+ return my_render_to_response('exam/showquestionpapers.html',context,context_instance=RequestContext(request))
+ else:
+ qu_papers = QuestionPaper.objects.get(id=questionpaper_id)
+ quiz = qu_papers.quiz
+ questions = qu_papers.questions.all()
+ q = []
+ for i in questions:
+ q.append(i)
+ context = {'papers':{'quiz':quiz,'questions':q}}
+ return my_render_to_response('exam/editquestionpaper.html',context,context_instance=RequestContext(request))
+
+
+def automatic_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!')
+
+ if questionpaper_id == None:
+ if request.method=="POST":
+ if request.POST.get('save') == 'save' :
+ quiz = Quiz.objects.order_by("-id")[0]
+ quest_paper = QuestionPaper()
+ 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')
+ 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))
+
+ else:
+ return HttpResponse("eni mane pochi gaya ayan... ")
+
+def manual_questionpaper(request):
+ user=request.user
+ 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))
+
+
+
def prof_manage(request):
"""Take credentials of the user with professor/moderator rights/permissions and log in."""