app/soc/views/models/survey.py
changeset 2442 dd1f94c3594c
parent 2440 05c430d1c147
child 2447 dae6715a2f19
--- a/app/soc/views/models/survey.py	Sun Jun 28 22:12:33 2009 +0200
+++ b/app/soc/views/models/survey.py	Sun Jun 28 23:58:03 2009 +0200
@@ -29,18 +29,21 @@
 import StringIO
 import string
 
+from google.appengine.ext import db
+
 from django import forms
 from django import http
 from django.utils import simplejson
 
-from google.appengine.ext import db
-
 from soc.cache import home
 from soc.logic import cleaning
 from soc.logic import dicts
 from soc.logic.models.survey import GRADES
 from soc.logic.models.survey import logic as survey_logic
+from soc.logic.models.survey import project_logic
+from soc.logic.models.survey import grading_logic
 from soc.logic.models.survey_record import logic as results_logic
+from soc.logic.models.survey_record import updateSurveyRecord
 from soc.logic.models.user import logic as user_logic
 from soc.models.survey import Survey
 from soc.models.survey_record import SurveyRecord
@@ -108,6 +111,7 @@
     rights['grade'] = ['checkIsSurveyGradable']
 
     new_params = {}
+    # TODO(ajaksu) pass logic in a way views can use them
     new_params['logic'] = survey_logic
     new_params['rights'] = rights
 
@@ -268,8 +272,8 @@
       else:
         # save/update the submitted survey
         context['notice'] = "Survey Submission Saved"
-        survey_record = survey_logic.updateSurveyRecord(user, survey,
-        survey_record, request.POST)
+        survey_record = updateSurveyRecord(user, survey, survey_record,
+                                           request.POST)
     survey_content = survey.survey_content
 
     if not survey_record and read_only:
@@ -392,6 +396,19 @@
 
     super(View, self)._editContext(request, context)
 
+  def createPost(self, request, context, params):
+
+    # TODO(ajaksu) create new View class for other surveys
+    survey_type = request.POST.get('survey_type')
+    if not survey_type:
+      self._logic = params['logic'] = survey_logic
+    elif survey_type == 'project':
+      self._logic =  params['logic'] = project_logic
+    elif survey_type == 'grading':
+      self._logic = params['logic'] = grading_logic
+
+    return super(View, self).createPost(request, context, params)
+
   def _editPost(self, request, entity, fields):
     """See base.View._editPost().
 
@@ -908,13 +925,13 @@
   properties = leading + survey.survey_content.orderedProperties()
 
   try:
-    first = survey.survey_records.run().next()
+    first = survey.getRecords().run().next()
   except StopIteration:
     # bail out early if survey_records.run() is empty
     return header, survey.link_id
 
   # generate results list
-  recs = survey.survey_records.run()
+  recs = survey.getRecords().run()
   recs = _get_records(recs, properties)
 
   # write results to CSV