Added SurveyRecordModel.
authorJames Levy <jamesalexanderlevy@gmail.com>
Sun, 28 Jun 2009 13:13:58 +0200
changeset 2429 a0a1dd1cc69e
parent 2428 8ca9f32d3fc4
child 2430 c9a5bf5ed3c5
Added SurveyRecordModel. Lennard: On top of the orginial patch I've added several comments to the fields and two TODO's for further subclassing. Patch by: James Levy, Daniel Diniz, Lennard de Rijk Reviewed by: Lennard de Rijk
app/soc/models/survey_record.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/models/survey_record.py	Sun Jun 28 13:13:58 2009 +0200
@@ -0,0 +1,82 @@
+#!/usr/bin/python2.5
+#
+# Copyright 2009 the Melange authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""SurveyRecord represents a single Survey result.
+
+SurveyRecordGroup represents a cluster (mentor/student) of SurveyRecords
+for an evaluation period.
+"""
+
+__authors__ = [
+  '"Daniel Diniz" <ajaksu@gmail.com>',
+  '"James Levy" <jamesalexanderlevy@gmail.com>',
+  '"Lennard de Rijk" <ljvderijk@gmail.com>',
+]
+
+
+from google.appengine.ext import db
+
+from django.utils.translation import ugettext
+
+from soc.models.survey import Survey
+import soc.models.student_project
+import soc.models.user
+
+
+class SurveyRecord(db.Expando):
+  """Record produced each time Survey is taken.
+
+  Like SurveyContent, this model includes dynamic properties
+  corresponding to the fields of the survey.
+
+  This also contains a Binary grade value that can be added/edited
+  by the administrator of the Survey.
+  """
+
+  #: The survey for which this entity is a record.
+  survey = db.ReferenceProperty(Survey, collection_name="survey_records")
+
+  #: Reference to the User entity which took this survey.
+  user = db.ReferenceProperty(reference_class=soc.models.user.User,
+                              required=True, collection_name="surveys_taken",
+                              verbose_name=ugettext('Created by'))
+
+  #: Reference to the Project that this record belongs to.
+  # TODO should be moved to its own subclass
+  project = db.ReferenceProperty(soc.models.student_project.StudentProject,
+                                 collection_name="survey_records")
+
+  #: Grade given to the project that this survey is about.
+  # TODO should be moved to its own subclass
+  grade = db.BooleanProperty(required=False)
+
+  #: Date when this record was created.
+  created = db.DateTimeProperty(auto_now_add=True)
+
+  #: Date when this record was last modified.
+  modified = db.DateTimeProperty(auto_now=True)
+
+  def getValues(self):
+    """Method to get dynamic property values for a survey record.
+
+    Right now it gets all dynamic values, but it could also be confined to
+    the SurveyContent entity linked to the survey entity.
+    """
+    survey_order = self.survey.survey_content.getSurveyOrder()
+    values = []
+    for position, property in survey_order.items():
+        values.insert(position, getattr(self, property, None))
+    return values