diff options
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/forms.py | 9 | ||||
-rw-r--r-- | testapp/exam/models.py | 6 | ||||
-rw-r--r-- | testapp/exam/views.py | 385 | ||||
-rw-r--r-- | testapp/settings.py | 1 | ||||
-rw-r--r-- | testapp/static/exam/css/autotaggit.css | 48 | ||||
-rw-r--r-- | testapp/static/exam/js/add_question.js | 109 | ||||
-rw-r--r-- | testapp/static/exam/js/edit_question.js | 172 | ||||
-rw-r--r-- | testapp/static/exam/js/min.js (renamed from testapp/static/exam/css/min.js) | 0 | ||||
-rw-r--r-- | testapp/static/exam/js/question.js | 37 | ||||
-rw-r--r-- | testapp/static/exam/js/show_question.js | 23 | ||||
-rw-r--r-- | testapp/static/exam/js/show_quiz.js | 23 | ||||
-rw-r--r-- | testapp/templates/exam/add_question.html | 121 | ||||
-rw-r--r-- | testapp/templates/exam/add_quiz.html | 3 | ||||
-rw-r--r-- | testapp/templates/exam/edit_question.html | 171 | ||||
-rw-r--r-- | testapp/templates/exam/question.html | 40 | ||||
-rw-r--r-- | testapp/templates/exam/show_quiz.html | 28 | ||||
-rw-r--r-- | testapp/templates/exam/showquestions.html | 26 |
17 files changed, 651 insertions, 551 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 1a25312..a6844bb 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -3,7 +3,11 @@ 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 taggit.managers import TaggableManager +from taggit.forms import TagField +from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete +from taggit_autocomplete_modified.widgets import TagAutocomplete +from taggit_autocomplete_modified import settings from string import letters, punctuation, digits import datetime @@ -113,6 +117,7 @@ class QuizForm(forms.Form): start_date = forms.DateField(initial=datetime.date.today) duration = forms.IntegerField() active = forms.BooleanField(required = False) + tags = TagField(widget=TagAutocomplete()) description = forms.CharField(max_length=256, widget=forms.Textarea(attrs={'cols':20,'rows':1})) def save(self): @@ -138,7 +143,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() + tags = TagField(widget=TagAutocomplete(),required=False) def save(self): summary = self.cleaned_data["summary"] diff --git a/testapp/exam/models.py b/testapp/exam/models.py index 689e931..da45e7d 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -44,6 +44,8 @@ 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 for the Question. tags = TaggableManager() def __unicode__(self): @@ -91,6 +93,10 @@ class Quiz(models.Model): # Description of quiz. description = models.CharField(max_length=256) + + #Tags for the Quiz. + tags = TaggableManager() + class Meta: verbose_name_plural = "Quizzes" diff --git a/testapp/exam/views.py b/testapp/exam/views.py index a529983..325d0aa 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -21,7 +21,6 @@ from settings import URL_ROOT # The directory where user data can be saved. OUTPUT_DIR = abspath(join(dirname(__file__), pardir, 'output')) - def my_redirect(url): """An overridden redirect to deal with URL_ROOT-ing. See settings.py for details.""" @@ -36,7 +35,6 @@ def my_render_to_response(template, context=None, **kwargs): context['URL_ROOT'] = URL_ROOT return render_to_response(template, context, **kwargs) - def gen_key(no_of_chars): """Generate a random key of the number of characters.""" allowed_chars = string.digits+string.uppercase @@ -44,10 +42,11 @@ def gen_key(no_of_chars): def get_user_dir(user): """Return the output directory for the user.""" + user_dir = join(OUTPUT_DIR, str(user.username)) if not exists(user_dir): os.mkdir(user_dir) - # Make it rwx by others. + # Make it rwx by others. os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH \ | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR \ | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) @@ -58,8 +57,8 @@ def index(request): """ user = request.user if user.is_authenticated(): - if user.groups.filter(name='moderator').count() > 0: - return my_redirect('/exam/manage/') + if user.groups.filter(name='moderator').count() > 0: + return my_redirect('/exam/manage/') return my_redirect("/exam/start/") return my_redirect("/exam/login/") @@ -81,7 +80,7 @@ def user_register(request): new_user = authenticate(username = u_name, password = pwd) login(request, new_user) return my_redirect("/exam/quizlist/") - + else: return my_render_to_response('exam/register.html', {'form':form}, @@ -93,108 +92,132 @@ def user_register(request): context_instance=RequestContext(request)) def edit_quiz(request): - """Edit the list of quizzes seleted by the user for editing.""" + """Edit the list of quizzes seleted by the user for editing.""" - 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!') + 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!') - start_date = request.POST.getlist('start_date') - duration = request.POST.getlist('duration') - active = request.POST.getlist('active') - description = request.POST.getlist('description') - - j = 0 - for i in quizlist: - quiz = Quiz.objects.get(id=i) - quiz.start_date = start_date[j] - quiz.duration = duration[j] - quiz.active = active[j] - quiz.description = description[j] - quiz.save() - j += 1 - return my_redirect("/exam/manage/showquiz/") + start_date = request.POST.getlist('start_date') + duration = request.POST.getlist('duration') + active = request.POST.getlist('active') + description = request.POST.getlist('description') + + j = 0 + for i in quizlist: + quiz = Quiz.objects.get(id=i) + quiz.start_date = start_date[j] + quiz.duration = duration[j] + quiz.active = active[j] + quiz.description = description[j] + quiz.save() + j += 1 + return my_redirect("/exam/manage/showquiz/") def edit_question(request): - """Edit the list of quizzes seleted by the user for editing.""" - 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!') - - summary = request.POST.getlist('summary') - description = request.POST.getlist('description') - points = request.POST.getlist('points') - test = request.POST.getlist('test') - options = request.POST.getlist('options') - type = request.POST.getlist('type') - active = request.POST.getlist('active') - j = 0 - for id_list in editquestionlist: - question = Question.objects.get(id=id_list) - question.summary = summary[j] - question.description = description[j] - question.points = points[j] - question.test = test[j] - question.options = options[j] - question.type = type[j] - question.active = active[j] - question.save() - j += 1 - return my_redirect("/exam/manage/questions") + """Edit the list of questions seleted by the user for editing.""" + 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!') + + summary = request.POST.getlist('summary') + description = request.POST.getlist('description') + points = request.POST.getlist('points') + test = request.POST.getlist('test') + options = request.POST.getlist('options') + type = request.POST.getlist('type') + active = request.POST.getlist('active') + tags = request.POST.getlist('tags') + j = 0 + for id_list in editquestionlist: + question = Question.objects.get(id=id_list) + question.summary = summary[j] + question.description = description[j] + question.points = points[j] + question.test = test[j] + question.options = options[j] + question.type = type[j] + edit_tags=tags[j] + question.active = active[j] + question.save() + for tag in question.tags.all(): + question.tags.remove(tag) + tags_split = edit_tags.split(',') + for i in range(0,len(tags_split)-1): + tag = tags_split[i].strip() + question.tags.add(tag) + j += 1 + return my_redirect("/exam/manage/questions") def add_question(request,question_id=None): """To add a new question in the database. Create a new question and store it.""" - 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!') + raise Http404('You are not allowed to view this page!') if request.method == "POST": - form = QuestionForm(request.POST) + 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) - d.summary = form['summary'].data - d.description = form['description'].data - d.points = form['points'].data - d.test = form['test'].data - d.options = form['options'].data - d.type = form['type'].data - d.active = form['active'].data - d.save() - return my_redirect("/exam/manage/questions") + tags = form['tags'].data.split(',') + for i in range(0,len(tags)-1): + tag = tags[i].strip() + question.tags.add(tag) + return my_redirect("/exam/manage/questions") + + else: + d = Question.objects.get(id=question_id) + d.summary = form['summary'].data + d.description = form['description'].data + d.points = form['points'].data + d.test = form['test'].data + d.options = form['options'].data + d.type = form['type'].data + d.active = form['active'].data + d.save() + question = Question.objects.get(id=question_id) + for tag in question.tags.all(): + question.tags.remove(tag) + tags = form['tags'].data.split(',') + for i in range(0,len(tags)-1): + tag = tags[i].strip() + question.tags.add(tag) + return my_redirect("/exam/manage/questions") else: return my_render_to_response('exam/add_question.html', {'form':form}, context_instance=RequestContext(request)) else: - if question_id == None: + if question_id == None: form = QuestionForm() return my_render_to_response('exam/add_question.html', {'form':form}, context_instance=RequestContext(request)) - else: + else: - d = Question.objects.get(id=question_id) - form = QuestionForm() - form.initial['summary']= d.summary - form.initial['description'] = d.description - form.initial['points']= d.points - form.initial['test'] = d.test - form.initial['options'] = d.options - form.initial['type'] = d.type - form.initial['active'] = d.active - - return my_render_to_response('exam/add_question.html', - {'form':form}, - context_instance=RequestContext(request)) + d = Question.objects.get(id=question_id) + form = QuestionForm() + form.initial['summary']= d.summary + form.initial['description'] = d.description + form.initial['points']= d.points + form.initial['test'] = d.test + form.initial['options'] = d.options + form.initial['type'] = d.type + form.initial['active'] = d.active + form_tags = d.tags.all() + form_tags_split = form_tags.values('name') + initial_tags = "" + + for tag in form_tags_split: + initial_tags = initial_tags + str(tag['name']).strip() + "," + if (initial_tags == ","): + initial_tags = "" + form.initial['tags']=initial_tags + return my_render_to_response('exam/add_question.html',{'form':form},context_instance=RequestContext(request)) def add_quiz(request,quiz_id=None): @@ -202,54 +225,55 @@ def add_quiz(request,quiz_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!') + raise Http404('You are not allowed to view this page!') if request.method == "POST": - form = QuizForm(request.POST) + form = QuizForm(request.POST) if form.is_valid(): data = form.cleaned_data - if quiz_id == None: + if quiz_id == None: form.save() - return my_redirect("/exam/manage/showquiz") - else: - d = Quiz.objects.get(id=quiz_id) - d.start_date = form['start_date'].data - d.duration = form['duration'].data - d.active = form['active'].data - d.description = form['description'].data - d.save() - return my_redirect("/exam/manage/showquiz") + quiz = Quiz.objects.order_by("-id")[0] + tags = form['tags'].data.split(',') + for tag in tags: + tag = tag.strip() + quiz.tags.add(tag) + return my_redirect("/exam/manage/showquiz") + else: + d = Quiz.objects.get(id=quiz_id) + d.start_date = form['start_date'].data + d.duration = form['duration'].data + d.active = form['active'].data + d.description = form['description'].data + d.save() + return my_redirect("/exam/manage/showquiz") else: return my_render_to_response('exam/add_quiz.html', {'form':form}, context_instance=RequestContext(request)) else: - if quiz_id == None: + if quiz_id == None: form = QuizForm() return my_render_to_response('exam/add_quiz.html', {'form':form}, context_instance=RequestContext(request)) - else: - - d = Quiz.objects.get(id=quiz_id) - form = QuizForm() - form.initial['start_date']= d.start_date - form.initial['duration'] = d.duration - form.initial['description']= d.description - form.initial['active'] = d.active - - return my_render_to_response('exam/add_quiz.html', - {'form':form}, - context_instance=RequestContext(request)) + else: + d = Quiz.objects.get(id=quiz_id) + form = QuizForm() + form.initial['start_date']= d.start_date + form.initial['duration'] = d.duration + form.initial['description']= d.description + form.initial['active'] = d.active + return my_render_to_response('exam/add_quiz.html',{'form':form},context_instance=RequestContext(request)) def prof_manage(request): """Take credentials of the user with professor/moderator rights/permissions and log in.""" - + user = request.user if user.is_authenticated() and user.groups.filter(name='moderator').count() > 0: - context = {'user':user} - return render_to_response('manage.html',context) + context = {'user':user} + return render_to_response('manage.html',context) return my_redirect('/exam/login/') def user_login(request): @@ -257,8 +281,8 @@ def user_login(request): user = request.user if user.is_authenticated(): - if user.groups.filter(name='moderator').count() > 0 : - return my_redirect('/exam/manage/') + if user.groups.filter(name='moderator').count() > 0 : + return my_redirect('/exam/manage/') return my_redirect("/exam/quizlist/") if request.method == "POST": @@ -266,8 +290,8 @@ def user_login(request): if form.is_valid(): user = form.cleaned_data login(request, user) - if user.groups.filter(name='moderator').count() > 0 : - return my_redirect('/exam/manage/') + if user.groups.filter(name='moderator').count() > 0 : + return my_redirect('/exam/manage/') return my_redirect('/exam/login/') else: context = {"form": form} @@ -289,7 +313,7 @@ def start(request,quiz_id=None): quiz = Quiz.objects.get(id=quiz_id) except Quiz.DoesNotExist: msg = 'Quiz not found, please contact your '\ - 'instructor/administrator. Please login again thereafter.' + 'instructor/administrator. Please login again thereafter.' return complete(request, reason=msg) try: @@ -432,7 +456,7 @@ def complete(request,reason = None): no = False message = reason or 'The quiz has been completed. Thank you.' if user.groups.filter(name='moderator').count() > 0: - message = 'You are successfully Logged out. Thanks for spending some time with the application' + message = 'You are successfully Logged out. Thanks for spending some time with the application' if request.method == 'POST' and 'no' in request.POST: no = True if not no: @@ -494,11 +518,10 @@ def show_all_users(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 !') + raise Http404('You are not allowed to view this page !') user = User.objects.filter(username__contains="") questionpaper = QuestionPaper.objects.all() context = { 'question': questionpaper } - print context return my_render_to_response('exam/showusers.html',context,context_instance=RequestContext(request)) def quizlist(request): @@ -512,59 +535,58 @@ def quizlist(request): context_instance=RequestContext(request)) - - def show_all_quiz(request): """Generates a list of all the quizzes that are currently in the database.""" 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 !') + raise Http404('You are not allowed to view this page !') if request.method == 'POST' and request.POST.get('delete')=='delete': - data = request.POST.getlist('quiz') - if data == None: - quizzes = Quiz.objects.all() + data = request.POST.getlist('quiz') + + if data == None: + quizzes = Quiz.objects.all() context = {'papers': [], 'quiz': None, 'quizzes':quizzes} return my_render_to_response('exam/show_quiz.html', context, context_instance=RequestContext(request)) - for i in data: - quiz = Quiz.objects.get(id=i).delete() - quizzes = Quiz.objects.all() - context = {'papers': [], + else: + for i in data: + quiz = Quiz.objects.get(id=i).delete() + quizzes = Quiz.objects.all() + context = {'papers': [], 'quiz': None, 'quizzes':quizzes} - return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/show_quiz.html', context, + context_instance=RequestContext(request)) elif request.method == 'POST' and request.POST.get('edit')=='edit': data = request.POST.getlist('quiz') - global quizlist - quizlist = data - if data == None: + global quizlist + quizlist = data + if data == None: quiz = Quiz.objects.all() context = {'papers': [], - 'quiz': None, - 'quizzes':quiz} + 'quiz': None, + 'quizzes':quiz} return my_render_to_response('exam/showquiz.html', context, context_instance=RequestContext(request)) - - forms = [] - for j in data: - d = Quiz.objects.get(id=j) - form = QuizForm() - form.initial['start_date']= d.start_date - form.initial['duration'] = d.duration - form.initial['active']= d.active - form.initial['description'] = d.description - forms.append(form) - - return my_render_to_response('exam/edit_quiz.html', + else: + forms = [] + for j in data: + d = Quiz.objects.get(id=j) + form = QuizForm() + form.initial['start_date']= d.start_date + form.initial['duration'] = d.duration + form.initial['active']= d.active + form.initial['description'] = d.description + forms.append(form) + return my_render_to_response('exam/edit_quiz.html', {'forms':forms}, context_instance=RequestContext(request)) - + else: quizzes = Quiz.objects.all() context = {'papers': [], @@ -579,7 +601,7 @@ def show_all_questions(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 !") + 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') @@ -590,43 +612,50 @@ def show_all_questions(request): 'questions':questions} return my_render_to_response('exam/showquestions.html', context, context_instance=RequestContext(request)) - for i in data: - question = Question.objects.get(id=i).delete() - questions = Question.objects.all() - context = {'papers': [], - 'question': None, - 'questions':questions} - return my_render_to_response('exam/showquestions.html', context, + else: + for i in data: + question = Question.objects.get(id=i).delete() + questions = Question.objects.all() + context = {'papers': [], + 'question': None, + 'questions':questions} + return my_render_to_response('exam/showquestions.html', context, context_instance=RequestContext(request)) elif request.method == 'POST' and request.POST.get('edit')=='edit': data = request.POST.getlist('question') - global editquestionlist - editquestionlist = data - if data == None: + global editquestionlist + editquestionlist = data + if data == None: questions = Question.objects.all() context = {'papers': [], - 'question': None, - 'questions':questions} + 'question': None, + 'questions':questions} return my_render_to_response('exam/showquestions.html', context, context_instance=RequestContext(request)) - - forms = [] - for j in data: - d = Question.objects.get(id=j) - form = QuestionForm() - form.initial['summary']= d.summary - form.initial['description'] = d.description - form.initial['points']= d.points - form.initial['test'] = d.test - form.initial['options'] = d.options - form.initial['type'] = d.type - form.initial['active'] = d.active - forms.append(form) - - return my_render_to_response('exam/edit_question.html', - {'forms':forms}, - context_instance=RequestContext(request)) + else: + forms = [] + for j in data: + d = Question.objects.get(id=j) + form = QuestionForm() + form.initial['summary']= d.summary + form.initial['description'] = d.description + form.initial['points']= d.points + form.initial['test'] = d.test + form.initial['options'] = d.options + form.initial['type'] = d.type + form.initial['active'] = d.active + form_tags = d.tags.all() + form_tags_split = form_tags.values('name') + initial_tags = "" + for tag in form_tags_split: + initial_tags = initial_tags + str(tag['name']).strip() + "," + if (initial_tags == ","): + initial_tags = "" + form.initial['tags']=initial_tags + forms.append(form) + return my_render_to_response('exam/edit_question.html',{'forms':forms},context_instance=RequestContext(request)) + else: questions = Question.objects.all() context = {'papers': [], diff --git a/testapp/settings.py b/testapp/settings.py index fd22639..6edf08c 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -148,6 +148,7 @@ INSTALLED_APPS = ( # 'django.contrib.admindocs', 'south', 'exam', + 'taggit_autocomplete_modified', ) # A sample logging configuration. The only tangible logging diff --git a/testapp/static/exam/css/autotaggit.css b/testapp/static/exam/css/autotaggit.css new file mode 100644 index 0000000..ed856ce --- /dev/null +++ b/testapp/static/exam/css/autotaggit.css @@ -0,0 +1,48 @@ +.ac_results { + padding: 0px; + border: 1px solid #efefef; + background-color: white; + overflow: hidden; + z-index: 99999; +} + +.ac_results ul { + width: 100%; + list-style-position: outside; + list-style: none; + padding: 0; + margin: 0; +} + +.ac_results li { + margin: 0px; + padding: 2px 5px; + cursor: default; + display: block; + /* + if width will be 100% horizontal scrollbar will apear + when scroll mode will be used + */ + /*width: 100%;*/ + font: menu; + font-size: 12px; + /* + it is very important, if line-height not setted or setted + in relative units scroll will be broken in firefox + */ + line-height: 16px; + overflow: hidden; +} + +.ac_loading { + background: white url('indicator.gif') right center no-repeat; +} + +.ac_odd { + background-color: #CACACA; +} + +.ac_over { + background-color: #f5f5f5; + color: black; +} diff --git a/testapp/static/exam/js/add_question.js b/testapp/static/exam/js/add_question.js new file mode 100644 index 0000000..1f08c79 --- /dev/null +++ b/testapp/static/exam/js/add_question.js @@ -0,0 +1,109 @@ +function increase(frm) +{ + if(frm.points.value == "") + { + frm.points.value = "0.5"; + return; + } + frm.points.value = parseFloat(frm.points.value) + 0.5; +} + +function decrease(frm) +{ + if(frm.points.value > 0) + { + frm.points.value = parseFloat(frm.points.value) - 0.5; + } + else + { + frm.points.value=0; + } + + +} + +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; + document.getElementById("id_description").cols=40; + }); + + $('#id_description').bind('blur', function( event ){ + document.getElementById("id_description").rows=1; + document.getElementById("id_description").cols=40; + }); + + $('#id_description').bind('keypress', function (event){ + document.getElementById('my').innerHTML = document.getElementById('id_description').value ; + }); + + $('#id_test').bind('focus', function( event ){ + document.getElementById("id_test").rows=5; + document.getElementById("id_test").cols=40; + }); + + $('#id_test').bind('blur', function( event ){ + document.getElementById("id_test").rows=1; + document.getElementById("id_test").cols=40; + }); + $('#id_options').bind('focus', function( event ){ + document.getElementById("id_options").rows=5; + document.getElementById("id_options").cols=40; + }); + + $('#id_options').bind('blur', function( event ){ + document.getElementById("id_options").rows=1; + document.getElementById("id_options").cols=40; + }); + + $('#id_type').bind('change',function(event){ + var value = document.getElementById('id_type').value; + if(value == 'mcq') + { + document.getElementById('id_options').style.visibility='visible'; + document.getElementById('label_option').innerHTML="Options :" + + } + else + { + document.getElementById('id_options').style.visibility='hidden'; + document.getElementById('label_option').innerHTML = ""; + } + }); + + document.getElementById('my').innerHTML = document.getElementById('id_description').value ; + var value = document.getElementById('id_type').value; + if(value == 'mcq') + { + document.getElementById('id_options').style.visibility='visible'; + document.getElementById('label_option').innerHTML="Options :" + + } + else + { + document.getElementById('id_options').style.visibility='hidden'; + document.getElementById('label_option').innerHTML = ""; + } +} + +function autosubmit() +{ + if (document.getElementById('id_type').value == 'mcq') + { + var value = document.getElementById('id_options').value; + if(value.split('\n').length != 4) + { + alert("Enter 4 options. One option per line."); + return false; + } + return true; + } + +} diff --git a/testapp/static/exam/js/edit_question.js b/testapp/static/exam/js/edit_question.js new file mode 100644 index 0000000..69e0d97 --- /dev/null +++ b/testapp/static/exam/js/edit_question.js @@ -0,0 +1,172 @@ +function render_question(frm) +{ + for(var i=1;i<=frm.description.length;i++) + { + document.getElementById('my'+i).innerHTML = frm.description[i-1].value; + } + +} + +function increase(frm,n) +{ + var newValue = document.getElementById('id_points'+ (n-1)).value ; + + if( newValue == "") + { + document.getElementById('id_points'+(n-1)).value = "0.5"; + return; + } + document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) + 0.5; +} + +function decrease(frm,n) +{ + var newValue = document.getElementById('id_points'+ (n-1)).value ; + + if( newValue > 0) + { + document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) - 0.5; + } + else + { + document.getElementById('id_points' + (n-1)).value = 0; + } +} + + +function data(showContent,showHideDiv,a,summary) +{ + var con = document.getElementById(showContent); + var ele=document.getElementById(showHideDiv); + var atag=document.getElementById(a); + if (ele.style.display=="block") + { + con.style.display = "none" + ele.style.display = "none"; + atag.text = summary; + } + else + { + con.style.display = "block"; + ele.style.display = "block"; + } +} + +function textareaformat() +{ + var point = document.getElementsByName('points'); + var test = document.getElementsByName('test'); + var option = document.getElementsByName('options'); + var descriptions = document.getElementsByName('description'); + var type = document.getElementsByName('type'); + var tags = document.getElementsByName('tags'); + + for (var i=0;i<point.length;i++) + { + point[i].id = point[i].id + i; + descriptions[i+1].id=descriptions[i+1].id + i; + test[i].id=test[i].id + i; + option[i].id=option[i].id + i; + type[i].id = type[i].id + i; + tags[i].id = tags[i].id + i; + } + + for(var i=0;i<point.length;i++) + { + var point_id = document.getElementById('id_points'+i); + point_id.setAttribute('class','mini-text'); + + var tags_id = document.getElementById('id_tags'+i); + tags_id.setAttribute('class','ac_input'); + tags_id.setAttribute('autocomplete','off'); + + jQuery().ready(function() + { + jQuery("#id_tags" + i).autocomplete("/taggit_autocomplete_modified/json", { multiple: true }); + }); + + var type_id = document.getElementById('id_type'+i); + type_id.setAttribute('class','select-type'); + type_id.onchange = showOptions; + var value = type_id.value; + + var desc_id = document.getElementById('id_description'+i); + desc_id.onfocus = gainfocus; + desc_id.onblur = lostfocus; + + var test_id = document.getElementById('id_test' + i); + test_id.onfocus = gainfocus; + test_id.onblur = lostfocus; + + var option_id = document.getElementById('id_options' + i); + option_id.onfocus = gainfocus; + option_id.onblur = lostfocus; + + if(value != 'mcq') + { + document.getElementById('id_options'+i).style.visibility='hidden'; + document.getElementById('label_option'+(i+1)).innerHTML = ""; + + } + + document.getElementById('my'+ (i+1)).innerHTML = desc_id.value; + } +} + +function showOptions(e) +{ + var value = this.value; + var no = parseInt(this.id.substring(this.id.length-1)); + if( value == 'mcq') + { + document.getElementById('id_options'+no).style.visibility = 'visible'; + document.getElementById('label_option'+ (no+1)).innerHTML = "Options : " + } + else + { + document.getElementById('id_options'+no).value = ""; + document.getElementById('id_options'+no).style.visibility = 'hidden'; + document.getElementById('label_option'+ (no+1)).innerHTML = ""; + } + + + +} + +function gainfocus(e) +{ + this.rows = 5; +} +function lostfocus(e) +{ + this.rows = 1; +} + +function autosubmit() +{ + var total_form = document.getElementsByName('summary').length; + var empty_options = 0 ; + var count_mcq = 0; + + for (var i=0;i<total_form;i++) + { + if (document.getElementById('id_type' + i).value != 'mcq') + { + continue; + } + else + { + count_mcq = count_mcq + 1; + var options = document.getElementById('id_options' + i).value; + var total_words = options.split("\n").length ; + if ( total_words < 4) + empty_options = empty_options + 1 ; + } + } + if (empty_options > 0) + { + alert('Enter 4 options. One option per line.'); + return false; + } + return true; +} diff --git a/testapp/static/exam/css/min.js b/testapp/static/exam/js/min.js index b1ae21d..b1ae21d 100644 --- a/testapp/static/exam/css/min.js +++ b/testapp/static/exam/js/min.js diff --git a/testapp/static/exam/js/question.js b/testapp/static/exam/js/question.js new file mode 100644 index 0000000..554a948 --- /dev/null +++ b/testapp/static/exam/js/question.js @@ -0,0 +1,37 @@ + var time_left = {{ time_left }}; + function submitCode() + { + document.forms["code"].submit(); + var x = document.getElementById("status"); + x.innerHTML = "<strong>Checking answer ...</strong>"; + x = document.getElementById("check"); + x.disabled = true; + x.value = "Checking Answer ..."; + document.getElementById("skip").disabled = true; + } + + function secs_to_time(secs) + { + var h = Math.floor(secs/3600); + var h_s = (h > 0) ? h+'h:' : ''; + var m = Math.floor((secs%3600)/60); + var m_s = (m > 0) ? m+'m:' : ''; + var s_s = Math.floor(secs%60) + 's'; + return h_s + m_s + s_s; + } + + function update_time() + { + time_left -= 1; + if (time_left) + { + var elem = document.getElementById("time_left"); + var t_str = secs_to_time(time_left); + elem.innerHTML = "<strong>" + t_str + "</strong>"; + setTimeout("update_time()", 1000); + } + else + { + document.forms["code"].submit(); + } + } diff --git a/testapp/static/exam/js/show_question.js b/testapp/static/exam/js/show_question.js new file mode 100644 index 0000000..ccacbdd --- /dev/null +++ b/testapp/static/exam/js/show_question.js @@ -0,0 +1,23 @@ +function confirm_delete(frm) + { + var r = confirm("Are you Sure ?"); + if(r==false) + { + for(i=0;i<frm.question.length;i++) + { + frm.question[i].checked=false; + } + location.replace("{{URL_ROOT}}/exam/manage/showquestion"); + } + } + function confirm_edit(frm) + { + var n = 0; + for(i=0;i<frm.question.length;i++) + { + if(frm.question[i].checked==true) + n = n+1; + } + if(n==0) + location.replace("{{URL_ROOT}}/exam/manage/showquestion"); + } diff --git a/testapp/static/exam/js/show_quiz.js b/testapp/static/exam/js/show_quiz.js new file mode 100644 index 0000000..db48a37 --- /dev/null +++ b/testapp/static/exam/js/show_quiz.js @@ -0,0 +1,23 @@ + function my_confirm(frm) + { + var r = confirm("Are you Sure ?"); + if(r==false) + { + for(i=0;i<frm.quiz.length;i++) + { + frm.quiz[i].checked=false; + } + location.replace("{{URL_ROOT}}/exam/manage/showquiz"); + } + } + function confirm_edit(frm) + { + var n = 0; + for (var i =0;i<frm.quiz.length;i++) + { + if (frm.quiz[i].checked == false) + n = n + 1 ; + } + if(n == frm.quiz.length) + location.replace("{{URL_ROOT}}/exam/manage/showquiz"); + } diff --git a/testapp/templates/exam/add_question.html b/testapp/templates/exam/add_question.html index 3f8637e..9651600 100644 --- a/testapp/templates/exam/add_question.html +++ b/testapp/templates/exam/add_question.html @@ -4,124 +4,15 @@ {% block subtitle %}Add Question{% endblock %} {% block css %} -<link rel="stylesheet" href="{{ URL_ROOT }}/static/exam/css/question_quiz.css" type="text/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" /> {% endblock %} {% block script %} -<script type="text/javascript" src="{{ URL_ROOT }}/static/exam/css/min.js"></script> -<script type="text/javascript"> - - -function increase(frm) -{ - if(frm.points.value == "") - { - frm.points.value = "0.5"; - return; - } - frm.points.value = parseFloat(frm.points.value) + 0.5; -} - -function decrease(frm) -{ - if(frm.points.value > 0) - { - frm.points.value = parseFloat(frm.points.value) - 0.5; - } - else - { - frm.points.value=0; - } - - -} - -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; - document.getElementById("id_description").cols=40; - }); - - $('#id_description').bind('blur', function( event ){ - document.getElementById("id_description").rows=1; - document.getElementById("id_description").cols=40; - }); - - $('#id_description').bind('keypress', function (event){ - document.getElementById('my').innerHTML = document.getElementById('id_description').value ; - }); - - $('#id_test').bind('focus', function( event ){ - document.getElementById("id_test").rows=5; - document.getElementById("id_test").cols=40; - }); - - $('#id_test').bind('blur', function( event ){ - document.getElementById("id_test").rows=1; - document.getElementById("id_test").cols=40; - }); - $('#id_options').bind('focus', function( event ){ - document.getElementById("id_options").rows=5; - document.getElementById("id_options").cols=40; - }); - - $('#id_options').bind('blur', function( event ){ - document.getElementById("id_options").rows=1; - document.getElementById("id_options").cols=40; - }); - - $('#id_type').bind('change',function(event){ - var value = document.getElementById('id_type').value; - if(value == 'mcq') - { - document.getElementById('id_options').style.visibility='visible'; - document.getElementById('label_option').innerHTML="Options :" - - } - else - { - document.getElementById('id_options').style.visibility='hidden'; - document.getElementById('label_option').innerHTML = ""; - } - }); - - document.getElementById('my').innerHTML = document.getElementById('id_description').value ; - var value = document.getElementById('id_type').value; - if(value == 'mcq') - { - document.getElementById('id_options').style.visibility='visible'; - document.getElementById('label_option').innerHTML="Options :" - - } - else - { - document.getElementById('id_options').style.visibility='hidden'; - document.getElementById('label_option').innerHTML = ""; - } -} - -function autosubmit() -{ - if (document.getElementById('id_type').value == 'mcq') - { - var value = document.getElementById('id_options').value; - if(value.split('\n').length != 4) - { - alert("Enter 4 options. One option per line."); - return false; - } - return true; - } - -} -</script> +<script type="text/javascript" src="{{ URL_ROOT }}/static/exam/js/min.js"></script> +<script src="/static/taggit_autocomplete_modified/jquery.min.js" type="text/javascript"></script> +<script src="/static/taggit_autocomplete_modified/jquery.autocomplete.js" type="text/javascript"></script> +<script src="{{ URL_ROOT }}/static/exam/js/add_question.js"></script> {% endblock %} {% block onload %} onload='javascript:textareaformat();' {% endblock %} diff --git a/testapp/templates/exam/add_quiz.html b/testapp/templates/exam/add_quiz.html index 570b3c2..c5998d8 100644 --- a/testapp/templates/exam/add_quiz.html +++ b/testapp/templates/exam/add_quiz.html @@ -5,8 +5,11 @@ {% 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" /> {% endblock %} {% block script %} +<script src="/static/taggit_autocomplete_modified/jquery.min.js" type="text/javascript"></script> +<script src="/static/taggit_autocomplete_modified/jquery.autocomplete.js" type="text/javascript"></script> <script type='text/javascript'> function test() { diff --git a/testapp/templates/exam/edit_question.html b/testapp/templates/exam/edit_question.html index 9d92a71..8ede7f0 100644 --- a/testapp/templates/exam/edit_question.html +++ b/testapp/templates/exam/edit_question.html @@ -4,173 +4,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" /> {% endblock %} {% block script %} -<script type='text/javascript'> -function render_question(frm) -{ - for(var i=1;i<=frm.description.length;i++) - { - document.getElementById('my'+i).innerHTML = frm.description[i-1].value; - } - -} - -function increase(frm,n) -{ - var newValue = document.getElementById('id_points'+ (n-1)).value ; - - if( newValue == "") - { - document.getElementById('id_points'+(n-1)).value = "0.5"; - return; - } - document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) + 0.5; -} - -function decrease(frm,n) -{ - var newValue = document.getElementById('id_points'+ (n-1)).value ; - - if( newValue > 0) - { - document.getElementById('id_points' + (n-1)).value = parseFloat(newValue) - 0.5; - } - else - { - document.getElementById('id_points' + (n-1)).value = 0; - } -} - - -function data(showContent,showHideDiv,a,summary) -{ - var con = document.getElementById(showContent); - var ele=document.getElementById(showHideDiv); - var atag=document.getElementById(a); - if (ele.style.display=="block") - { - con.style.display = "none" - ele.style.display = "none"; - atag.text = summary; - } - else - { - con.style.display = "block"; - ele.style.display = "block"; - } -} - -function textareaformat() -{ - var point = document.getElementsByName('points'); - var test = document.getElementsByName('test'); - var option = document.getElementsByName('options'); - var descriptions = document.getElementsByName('description'); - var type = document.getElementsByName('type'); - - for (var i=0;i<point.length;i++) - { - point[i].id = point[i].id + i; - descriptions[i+1].id=descriptions[i+1].id + i; - test[i].id=test[i].id + i; - option[i].id=option[i].id + i; - type[i].id = type[i].id + i; - - - } - - for(var i=0;i<point.length;i++) - { - var point_id = document.getElementById('id_points'+i); - point_id.setAttribute('class','mini-text'); - - var type_id = document.getElementById('id_type'+i); - type_id.setAttribute('class','select-type'); - type_id.onchange = showOptions; - var value = type_id.value; - - var desc_id = document.getElementById('id_description'+i); - desc_id.onfocus = gainfocus; - desc_id.onblur = lostfocus; - - var test_id = document.getElementById('id_test' + i); - test_id.onfocus = gainfocus; - test_id.onblur = lostfocus; - - var option_id = document.getElementById('id_options' + i); - option_id.onfocus = gainfocus; - option_id.onblur = lostfocus; - - if(value != 'mcq') - { - document.getElementById('id_options'+i).style.visibility='hidden'; - document.getElementById('label_option'+(i+1)).innerHTML = ""; - - } - - document.getElementById('my'+ (i+1)).innerHTML = desc_id.value; - } -} - -function showOptions(e) -{ - var value = this.value; - var no = parseInt(this.id.substring(this.id.length-1)); - if( value == 'mcq') - { - document.getElementById('id_options'+no).style.visibility = 'visible'; - document.getElementById('label_option'+ (no+1)).innerHTML = "Options : " - } - else - { - document.getElementById('id_options'+no).value = ""; - document.getElementById('id_options'+no).style.visibility = 'hidden'; - document.getElementById('label_option'+ (no+1)).innerHTML = ""; - } - - - -} - -function gainfocus(e) -{ - this.rows = 5; -} -function lostfocus(e) -{ - this.rows = 1; -} - -function autosubmit() -{ - var total_form = document.getElementsByName('summary').length; - var empty_options = 0 ; - var count_mcq = 0; - - for (var i=0;i<total_form;i++) - { - if (document.getElementById('id_type' + i).value != 'mcq') - { - continue; - } - else - { - count_mcq = count_mcq + 1; - var options = document.getElementById('id_options' + i).value; - var total_words = options.split("\n").length ; - if ( total_words < 4) - empty_options = empty_options + 1 ; - } - } - if (empty_options > 0) - { - alert('Enter 4 options. One option per line.'); - return false; - } - return true; -} -</script> +<script src="{{ URL_ROOT }}/static/exam/js/edit_question.js"></script> +<script src="/static/taggit_autocomplete_modified/jquery.min.js" type="text/javascript"></script> +<script src="/static/taggit_autocomplete_modified/jquery.autocomplete.js" type="text/javascript"></script> {% endblock %} {% block onload %} onload = 'javascript:textareaformat();' {% endblock %} @@ -196,9 +35,9 @@ function autosubmit() <tr><td><strong>Rendered: </strong><td><p id='my{{forloop.counter}}'></p> <tr><td><b>Description: <td>{{ form.description }} {{form.description.errors}} <tr><td><b>Test: <td>{{ form.test }}{{form.test.errors}} + <tr><td>Tags: <td>{{ form.tags }} <tr><td id='label_option{{forloop.counter}}'><b>Options: <td>{{ form.options }} {{form.options.errors}} {{form.options.helptext}} </table></center> - </div> </div> {% endfor %} diff --git a/testapp/templates/exam/question.html b/testapp/templates/exam/question.html index b4b171e..981af7f 100644 --- a/testapp/templates/exam/question.html +++ b/testapp/templates/exam/question.html @@ -9,45 +9,7 @@ {% endblock %} {% block script %} - <script type="text/javascript"> - var time_left = {{ time_left }}; - function submitCode() - { - document.forms["code"].submit(); - var x = document.getElementById("status"); - x.innerHTML = "<strong>Checking answer ...</strong>"; - x = document.getElementById("check"); - x.disabled = true; - x.value = "Checking Answer ..."; - document.getElementById("skip").disabled = true; - } - - function secs_to_time(secs) - { - var h = Math.floor(secs/3600); - var h_s = (h > 0) ? h+'h:' : ''; - var m = Math.floor((secs%3600)/60); - var m_s = (m > 0) ? m+'m:' : ''; - var s_s = Math.floor(secs%60) + 's'; - return h_s + m_s + s_s; - } - - function update_time() - { - time_left -= 1; - if (time_left) - { - var elem = document.getElementById("time_left"); - var t_str = secs_to_time(time_left); - elem.innerHTML = "<strong>" + t_str + "</strong>"; - setTimeout("update_time()", 1000); - } - else - { - document.forms["code"].submit(); - } - } - </script> +<script src="{{ URL_ROOT }}/static/exam/js/question.js"></script> {% endblock script %} {% block onload %} onload="update_time()" {% endblock onload %} diff --git a/testapp/templates/exam/show_quiz.html b/testapp/templates/exam/show_quiz.html index 684cfd2..1a4c289 100644 --- a/testapp/templates/exam/show_quiz.html +++ b/testapp/templates/exam/show_quiz.html @@ -3,33 +3,9 @@ {% block title %} Quiz List {% endblock title %} {% block script %} - <script type='text/javascript'> - function my_confirm(frm) - { - var r = confirm("Are you Sure ?"); - if(r==false) - { - for(i=0;i<frm.quiz.length;i++) - { - frm.quiz[i].checked=false; - } - location.replace("{{URL_ROOT}}/exam/manage/showquiz"); - } - } - function confirm_edit(frm) - { - var n = 0; - for (var i =0;i<frm.quiz.length;i++) - { - if (frm.quiz[i].checked == false) - n = n + 1 ; - } - if(n == frm.quiz.length) - location.replace("{{URL_ROOT}}/exam/manage/showquiz"); - } - - </script> +<script src="{{ URL_ROOT }}/static/exam/js/show_quiz.js"></script> {% endblock %} + {% block subtitle %} Quiz List {% endblock %} {% block manage %} {% if not quizzes and not quiz %} diff --git a/testapp/templates/exam/showquestions.html b/testapp/templates/exam/showquestions.html index 116e747..d406522 100644 --- a/testapp/templates/exam/showquestions.html +++ b/testapp/templates/exam/showquestions.html @@ -4,31 +4,7 @@ {% block subtitle %}List of Questions {% endblock %} {% block script %} - <script type='text/javascript'> - function confirm_delete(frm) - { - var r = confirm("Are you Sure ?"); - if(r==false) - { - for(i=0;i<frm.question.length;i++) - { - frm.question[i].checked=false; - } - location.replace("{{URL_ROOT}}/exam/manage/showquestion"); - } - } - function confirm_edit(frm) - { - var n = 0; - for(i=0;i<frm.question.length;i++) - { - if(frm.question[i].checked==true) - n = n+1; - } - if(n==0) - location.replace("{{URL_ROOT}}/exam/manage/showquestion"); - } - </script> +<script src="{{ URL_ROOT }}/static/exam/js/show_question.js"></script> {% endblock %} {% block manage %} |