Added getSurveyForContent method to SurveyLogic.
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 30 Jun 2009 08:50:56 +0200
changeset 2460 b8b0c631bcfe
parent 2459 accd8ba94b44
child 2461 c3e3df63e683
Added getSurveyForContent method to SurveyLogic. This method returns a Survey for a given content. The backreferenceproperty will not work because of inheritance.
app/soc/logic/models/survey.py
--- a/app/soc/logic/models/survey.py	Tue Jun 30 08:49:34 2009 +0200
+++ b/app/soc/logic/models/survey.py	Tue Jun 30 08:50:56 2009 +0200
@@ -172,6 +172,20 @@
 
     return survey_record_group
 
+  def getSurveyForContent(self, survey_content):
+    """Returns the Survey belonging to the given SurveyContent.
+
+    params:
+      survey_content: the SurveyContent to retrieve the Survey for.
+
+    returns:
+      Survey or subclass if possible else None.
+    """
+
+    fields = {'survey_content': survey_content}
+
+    return self.getForFields(fields, unique=True)
+
   def getUserRole(self, user, survey, project):
     """Gets the role of a user for a project, used for SurveyRecordGroup.