Added hasAtLeastOneRecord method to Survey Logic.
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 28 Jul 2009 11:20:42 +0200
changeset 2684 08ec7ca16dce
parent 2683 8ea17736a10d
child 2685 506cda0463e8
Added hasAtLeastOneRecord method to Survey Logic.
app/soc/logic/models/survey.py
--- a/app/soc/logic/models/survey.py	Mon Jul 27 15:03:20 2009 +0200
+++ b/app/soc/logic/models/survey.py	Tue Jul 28 11:20:42 2009 +0200
@@ -346,6 +346,18 @@
     # return the scope
     return entity.scope
 
+  def hasAtLeastOneRecord(self, survey_entity):
+    """Returns True iff the given Survey has at least one SurveyRecord.
+
+    Args:
+      survey_entity: a Survey instance
+    """
+
+    fields = {'survey': survey_entity}
+
+    record_logic = self.getRecordLogic()
+    return record_logic.getQueryForFields(fields).count(1) > 0
+
   def _onCreate(self, entity):
     """Set the scope of the survey.
     """