Add more flexibility to the Survey helper for use with the new Survey types.
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 30 Jun 2009 14:55:55 +0200
changeset 2463 05af53239799
parent 2462 2d5d2961f774
child 2464 64b241a237b2
Add more flexibility to the Survey helper for use with the new Survey types. This includes using the new SurveyLogic methods from an earlier commit. And passing on the Logic from the view where necessary.
app/soc/views/helper/surveys.py
app/soc/views/models/survey.py
--- a/app/soc/views/helper/surveys.py	Tue Jun 30 14:45:11 2009 +0200
+++ b/app/soc/views/helper/surveys.py	Tue Jun 30 14:55:55 2009 +0200
@@ -40,8 +40,6 @@
 
 from soc.logic import dicts
 from soc.logic.lists import Lists
-from soc.logic.models.survey import logic as survey_logic
-from soc.logic.models.survey_record import logic as results_logic
 from soc.models.survey import SurveyContent
 
 
@@ -69,6 +67,7 @@
     self.survey_content = self.kwargs.pop('survey_content', None)
     self.this_user = self.kwargs.pop('this_user', None)
     self.project = self.kwargs.pop('project', None)
+    self.survey_logic = self.kwargs.pop('survey_logic', None)
     self.survey_record = self.kwargs.pop('survey_record', None)
 
     self.read_only = self.kwargs.pop('read_only', None)
@@ -104,7 +103,9 @@
       read_only = self.read_only
 
       if not read_only:
-        deadline = self.survey_content.survey_parent.get().survey_end
+        survey_content = self.survey_content
+        survey_entity = self.survey_logic.getSurveyForContent(survey_content)
+        deadline = survey_entity.survey_end
         read_only =  deadline and (datetime.datetime.now() > deadline)
       else:
         extra_attrs['disabled'] = 'disabled'
@@ -548,9 +549,10 @@
       context: context dict for template
     """
 
-    logic = results_logic
+    survey_logic = params['logic']
+    record_logic = survey_logic.getRecordLogic()
     filter = {'survey': survey}
-    data = logic.getForFields(filter=filter, limit=limit, offset=offset,
+    data = record_logic.getForFields(filter=filter, limit=limit, offset=offset,
                               order=order)
 
     params['name'] = "Survey Results"
--- a/app/soc/views/models/survey.py	Tue Jun 30 14:45:11 2009 +0200
+++ b/app/soc/views/models/survey.py	Tue Jun 30 14:55:55 2009 +0200
@@ -20,6 +20,7 @@
 __authors__ = [
   '"Daniel Diniz" <ajaksu@gmail.com>',
   '"James Levy" <jamesalexanderlevy@gmail.com>',
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
   ]
 
 import csv
@@ -183,6 +184,7 @@
         }
 
     params = dicts.merge(params, new_params)
+
     super(View, self).__init__(params=params)
 
   def list(self, request, access_type, page_name=None, params=None,
@@ -288,6 +290,7 @@
     survey_form = surveys.SurveyForm(survey_content=survey_content,
                                      this_user=user,
                                      project=project,
+                                     survey_logic=self._params['logic'],
                                      survey_record=survey_record,
                                      read_only=read_only,
                                      editing=False)
@@ -626,7 +629,9 @@
 
 
     survey_form = surveys.SurveyForm(survey_content=survey_content,
-                                     this_user=user, project=project, survey_record=survey_record,
+                                     this_user=user, project=project,
+                                     survey_logic=params['logic'],
+                                     survey_record=survey_record,
                                      editing=True, read_only=False)
     survey_form.getFields()