From 2f21a4a007ae9b51fadd7832fe90506f19e309e2 Mon Sep 17 00:00:00 2001 From: jayparikh111 Date: Wed, 21 Mar 2012 17:11:33 +0530 Subject: changes for adding tags in questions --- testapp/exam/forms.py | 3 ++- testapp/exam/models.py | 3 ++- testapp/exam/urls.py | 1 + testapp/exam/views.py | 4 +++- testapp/settings.py | 1 + testapp/static/exam/css/question_quiz.css | 4 ++++ testapp/templates/exam/add_question.html | 6 +++++- testapp/urls.py | 1 + 8 files changed, 19 insertions(+), 4 deletions(-) diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 2a1ae6d..1a25312 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -3,7 +3,7 @@ from exam.models import Profile,Quiz,Question from django.contrib.auth import authenticate from django.contrib.auth.models import User - +from taggit.forms import * from string import letters, punctuation, digits import datetime @@ -138,6 +138,7 @@ class QuestionForm(forms.Form): options = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1}),required=False) type = forms.CharField(max_length=8, widget=forms.Select(choices=QUESTION_TYPE_CHOICES)) active = forms.BooleanField(required=False) + tags = TagField() def save(self): summary = self.cleaned_data["summary"] diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 717e02e..4931e44 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -1,7 +1,7 @@ import datetime from django.db import models from django.contrib.auth.models import User - +from taggit.managers import TaggableManager ################################################################################ class Profile(models.Model): """Profile for a user to store roll number and other details.""" @@ -43,6 +43,7 @@ class Question(models.Model): # Is this question active or not. If it is inactive it will not be used # when creating a QuestionPaper. active = models.BooleanField(default=True) + tags = TaggableManager() def __unicode__(self): return self.summary diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index a8b81f7..9e42093 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -10,6 +10,7 @@ urlpatterns = patterns('exam.views', url(r'^(?P\d+)/$', 'question'), url(r'^(?P\d+)/check/$', 'check'), + url(r'^manage/$', 'prof_manage'), url(r'^manage/addquestion/$', 'add_question'), url(r'^manage/addquestion/(?P\d+)/$', 'add_question'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 0504bde..7216f5b 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -153,8 +153,10 @@ def add_question(request,question_id=None): form = QuestionForm(request.POST) if form.is_valid(): data = form.cleaned_data - if question_id == None: + if question_id == None: form.save() + question = Question.objects.order_by("-id")[0] + question.tags.add(form['tags'].data) return my_redirect("/exam/manage/questions") else: d = Question.objects.get(id=question_id) diff --git a/testapp/settings.py b/testapp/settings.py index f1c48b9..fd22639 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -143,6 +143,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: 'django.contrib.admin', + 'taggit', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'south', diff --git a/testapp/static/exam/css/question_quiz.css b/testapp/static/exam/css/question_quiz.css index 1668bad..b702bd4 100644 --- a/testapp/static/exam/css/question_quiz.css +++ b/testapp/static/exam/css/question_quiz.css @@ -12,3 +12,7 @@ table th, table td { width : 80px; } +.tag-text +{ + width : 290px; +} diff --git a/testapp/templates/exam/add_question.html b/testapp/templates/exam/add_question.html index f832d46..3f8637e 100644 --- a/testapp/templates/exam/add_question.html +++ b/testapp/templates/exam/add_question.html @@ -42,6 +42,7 @@ function textareaformat() document.getElementById('id_type').setAttribute('class','select-type'); document.getElementById('id_points').setAttribute('class','mini-text'); + document.getElementById('id_tags').setAttribute('class','tag-text'); $('#id_description').bind('focus', function( event ){ document.getElementById("id_description").rows=5; @@ -134,7 +135,10 @@ function autosubmit() Rendered:

Description: {{ form.description}} {{form.description.errors}} Test: {{ form.test }}{{form.test.errors}} - Options: {{ form.options }} {{form.options.errors}} + Tags: {{ form.tags }} + Options: {{ form.options }} {{form.options.errors}} + +
diff --git a/testapp/urls.py b/testapp/urls.py index d956bfc..4fce4ea 100644 --- a/testapp/urls.py +++ b/testapp/urls.py @@ -20,4 +20,5 @@ urlpatterns = patterns('', # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(ADMIN_BASE, include(admin.site.urls)), + ) -- cgit