Jernej Kos avatar Jernej Kos committed 48b207f

Minor fixes.

Comments (0)

Files changed (5)

 admin.site.register(survey_models.NumericEntryQuestion)
 
 admin.site.register(survey_models.SeparatorQuestion)
+
+admin.site.register(survey_models.Subject)
+
 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):
 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():

Empty file added.

Empty file added.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.