37 |
37 |
38 Like SurveyContent, this model includes dynamic properties |
38 Like SurveyContent, this model includes dynamic properties |
39 corresponding to the fields of the survey. |
39 corresponding to the fields of the survey. |
40 """ |
40 """ |
41 |
41 |
42 #: Reference to the User entity which took this survey. |
42 #: The survey for which this entity is a record. |
43 user = db.ReferenceProperty(reference_class=soc.models.user.User, |
43 survey = db.ReferenceProperty(Survey, |
44 required=True, collection_name="surveys_taken", |
44 collection_name="survey_records") |
45 verbose_name=ugettext('Created by')) |
|
46 |
45 |
47 #: Date when this record was created. |
46 #: Date when this record was created. |
48 created = db.DateTimeProperty(auto_now_add=True) |
47 created = db.DateTimeProperty(auto_now_add=True) |
49 |
48 |
50 #: Date when this record was last modified. |
49 #: Date when this record was last modified. |
54 """Method to get dynamic property values for a survey record. |
53 """Method to get dynamic property values for a survey record. |
55 |
54 |
56 Right now it gets all dynamic values, but it could also be confined to |
55 Right now it gets all dynamic values, but it could also be confined to |
57 the SurveyContent entity linked to the survey entity. |
56 the SurveyContent entity linked to the survey entity. |
58 """ |
57 """ |
59 survey_order = self.getSurvey().survey_content.getSurveyOrder() |
58 survey_order = self.survey.survey_content.getSurveyOrder() |
60 values = [] |
59 values = [] |
61 for position, property in survey_order.items(): |
60 for position, property in survey_order.items(): |
62 values.insert(position, getattr(self, property, None)) |
61 values.insert(position, getattr(self, property, None)) |
63 return values |
62 return values |
64 |
63 |
65 |
64 |
66 # TODO(ajaksu) think of a better way to handle the survey reference |
|
67 class SurveyRecord(BaseSurveyRecord): |
65 class SurveyRecord(BaseSurveyRecord): |
68 |
66 |
69 #: The survey for which this entity is a record. |
67 #: Reference to the User entity which took this survey. |
70 survey = db.ReferenceProperty(Survey, collection_name="survey_records") |
68 user = db.ReferenceProperty(reference_class=soc.models.user.User, |
71 |
69 required=True, collection_name="surveys_taken", |
72 def getSurvey(self): |
70 verbose_name=ugettext('Taken by')) |
73 """Returns the Survey belonging to this record. |
|
74 """ |
|
75 return self.survey |
|