diff options
author | jayparikh111 | 2012-02-16 13:02:49 +0530 |
---|---|---|
committer | jayparikh111 | 2012-02-16 13:02:49 +0530 |
commit | c20539ed5f879c945cc89323e00daad96047d247 (patch) | |
tree | 928b82fef403682ebc12251865d47441bd57b41c /testapp | |
parent | d18df85469fc993520ee397f4a28b422c550408a (diff) | |
download | online_test-c20539ed5f879c945cc89323e00daad96047d247.tar.gz online_test-c20539ed5f879c945cc89323e00daad96047d247.tar.bz2 online_test-c20539ed5f879c945cc89323e00daad96047d247.zip |
Form to add New Question
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/forms.py | 19 | ||||
-rw-r--r-- | testapp/exam/views.py | 19 | ||||
-rw-r--r-- | testapp/templates/exam/add_question.html | 21 |
3 files changed, 53 insertions, 6 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index a867f5f..6d431e7 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -6,6 +6,13 @@ from django.contrib.auth.models import User from string import letters, punctuation, digits import datetime + +QUESTION_TYPE_CHOICES = ( + ("python", "Python"), + ("bash", "Bash"), + ("mcq", "MultipleChoice"), + ) + UNAME_CHARS = letters + "._" + digits PWD_CHARS = letters + punctuation + digits @@ -96,10 +103,18 @@ class UserLoginForm(forms.Form): return user - - class QuizForm(forms.Form): start_date = forms.DateField(initial=datetime.date.today) duration = forms.IntegerField() active = forms.BooleanField(required = False) description = forms.CharField(max_length=256, widget=forms.Textarea(attrs={'cols':20,'rows':2})) + +class AddQuestionForm(forms.Form): + summary = forms.CharField(max_length = 128) + description = forms.CharField(widget = forms.Textarea(attrs={'cols': 20, 'rows': 3})) + points = forms.FloatField() + test = forms.CharField(widget = forms.Textarea(attrs={'cols': 20, 'rows': 3})) + options = forms.CharField(widget = forms.Textarea(attrs={'cols': 20, 'rows': 3})) + type = forms.CharField(max_length=24, widget=forms.Select(choices=QUESTION_TYPE_CHOICES)) + active = forms.BooleanField(required=False) + diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 22e701e..23534f5 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -14,7 +14,7 @@ from django.db.models import Sum # Local imports. from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, User -from exam.forms import UserRegisterForm, UserLoginForm, QuizForm +from exam.forms import UserRegisterForm, UserLoginForm, QuizForm , AddQuestionForm from exam.xmlrpc_clients import code_server from settings import URL_ROOT @@ -91,7 +91,22 @@ def user_register(request): context_instance=RequestContext(request)) def add_question(request): - return render_to_response('exam/add_question.html',{}) + + if request.method == "POST": + form = AddQuestionForm(request.POST) + if form.is_valid(): + data = form.cleaned_data + return my_redirect("/exam/start/") + + else: + return my_render_to_response('exam/add_question.html', + {'form':form}, + context_instance=RequestContext(request)) + else: + form = AddQuestionForm() + return my_render_to_response('exam/add_question.html', + {'form':form}, + context_instance=RequestContext(request)) def add_quiz(request): diff --git a/testapp/templates/exam/add_question.html b/testapp/templates/exam/add_question.html index fb5d38b..a0ba14d 100644 --- a/testapp/templates/exam/add_question.html +++ b/testapp/templates/exam/add_question.html @@ -1,9 +1,26 @@ {% extends "manage.html" %} -{% block subtitle %} +{% block subtitle %} Add Question {% endblock %} + {% block manage %} -<p>Add Question +<style type="text/css"> + +table th, table td { + padding: 10px 10px 9px; + line-height: 18px; + text-align: left; +} +</style> + +<form action="" method="post"> +{% csrf_token %} +<center><table class=span1> +{{ form.as_table }} +</table> +<center><button class="btn" type="submit" name="savequestion">Save</button> +</form> {% endblock %} + |