Commits

Jernej Kos  committed 48b207f

Minor fixes.

  • Participants
  • Parent commits 9ee024a

Comments (0)

Files changed (5)

File survey/admin.py

 admin.site.register(survey_models.NumericEntryQuestion)
 
 admin.site.register(survey_models.SeparatorQuestion)
+
+admin.site.register(survey_models.Subject)
+

File survey/models.py

 import simplejson
 import string
 
+class ValidationError(Exception):
+  pass
+
 class Question(polymorphic.PolymorphicModel):
   class Meta:
     ordering = ['order']
   def submit(self, data):
     form = self.get_form(data = data, prefix = 'q%s' % self.pk)
     if not form.is_valid():
-      raise Exception # TODO
+      raise ValidationError
     return form.cleaned_data
 
   def interpret_answer(self, data):

File survey/views.py

 def enter_survey_instance(request, survey_id):
   survey = get_object_or_404(survey_models.Survey, pk = survey_id)
   if request.method == 'POST':
-    subject = survey.submit(request.POST, user = request.user)
-    return render_to_response('survey/submit_done.html', dict(
-      survey = survey, subject = subject), context_instance = RequestContext(request))
+    try:
+      subject = survey.submit(request.POST, user = request.user)
+      return render_to_response('survey/submit_done.html', dict(
+        survey = survey, subject = subject), context_instance = RequestContext(request))
+    except survey_models.ValidationError:
+      pass
 
   return render_to_response('survey/enter.html', dict(
     survey = survey), context_instance = RequestContext(request))
   survey = get_object_or_404(survey_models.Survey, pk = survey_id)
   subject = get_object_or_404(survey_models.Subject, pk = subject_id)
   if request.method == 'POST':
-    survey.submit(request.POST, subject)
-    return render_to_response('survey/submit_done.html', dict(
-      survey = survey, subject = subject), context_instance = RequestContext(request))
+    try:
+      survey.submit(request.POST, subject)
+      return render_to_response('survey/submit_done.html', dict(
+        survey = survey, subject = subject), context_instance = RequestContext(request))
+    except survey_models.ValidationError:
+      pass
 
   answers = []
   for question in survey.questions.all():

File templates/404.html

Empty file added.

File templates/500.html

Empty file added.