Commits

Stefan Zimmermann committed 9626ff6

some formal changes + no redirect on invalid post data in voting index generator

  • Participants
  • Parent commits 463dbbf

Comments (0)

Files changed (1)

File app/views.py

 class _Index(object):
   """Voting page generator.
   """
-  __slots__ = ('_voting', '_poll', '_questions', '_voter')
+  __slots__ = '_voting', '_poll', '_questions', '_voter',
 
   def _Form(self, question, *args):
     """Generate the form instance for given poll question.
 
       else: #... choice fields for choice questions
         choice = (forms.ChoiceField, forms.MultipleChoiceField)[qtype](
-          choices = [(r.id, r.title) for r in responses],
-          widget = (
+          choices = [(r.id, r.title) for r in responses], widget = (
             (forms.RadioSelect, forms.CheckboxSelectMultiple)[qtype]()))
 
     return Form(*args)
     """Apply submitted vote and update data for next question.
     """
     form = self._Form(question, request.POST)
-    if not form.is_valid(): return form, question, qn
+    if not form.is_valid(): return form #, question, qn
 
     qtype = question.qtype
     if qtype == 2:
 
       value = Decimal(request.POST['num'])
       if value < numresponse.bottom or value > numresponse.top:
-        return form, question, qn
+        return form #, question, qn
 
     # save that voter has answered the question
     self._voter.question = question
     voterefs = dict(voting = self._voting, voter = self._voter)
     if qtype == 2: NumVote(
       response = numresponse, value = request.POST['num'], **voterefs
-
       ).save()
 
     else:
       for id in request.POST.getlist('choice'):
         Vote(response = Response.objects.get(id = id), **voterefs).save()
 
-    # get next poll question and generate new form
-    qn += 1
-    question = self._question(qn)
-    return self._Form(question), question, qn
+    ## # get next poll question and generate new form
+    ## qn += 1
+    ## question = self._question(qn)
+    ## return self._Form(question), question, qn
 
   def _response(self, request, templatefile, context = None):
     """Generate the HttpResponse from template and context.
     try:
       question = self._question(qn)
       if request.POST: # apply the submitted vote and get next question
-        form, question, qn = self._applyvote(request, question, qn)
-        # get browser out of post context
-        return HttpResponseRedirect('.')
+        ## form, question, qn = self._applyvote(request, question, qn)
+        form = self._applyvote(request, question, qn)
+        if form is None: # all valid
+          # get browser out of post context
+          return HttpResponseRedirect('.')
 
       # if initial request just generate first form
       else: form = self._Form(question)