|
1 #!/usr/bin/python2.5 |
|
2 # |
|
3 # Copyright 2009 the Melange authors. |
|
4 # |
|
5 # Licensed under the Apache License, Version 2.0 (the "License"); |
|
6 # you may not use this file except in compliance with the License. |
|
7 # You may obtain a copy of the License at |
|
8 # |
|
9 # http://www.apache.org/licenses/LICENSE-2.0 |
|
10 # |
|
11 # Unless required by applicable law or agreed to in writing, software |
|
12 # distributed under the License is distributed on an "AS IS" BASIS, |
|
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 # See the License for the specific language governing permissions and |
|
15 # limitations under the License. |
|
16 |
|
17 """SurveyRecord represents a single Survey result. |
|
18 |
|
19 SurveyRecordGroup represents a cluster (mentor/student) of SurveyRecords |
|
20 for an evaluation period. |
|
21 """ |
|
22 |
|
23 __authors__ = [ |
|
24 '"Daniel Diniz" <ajaksu@gmail.com>', |
|
25 '"James Levy" <jamesalexanderlevy@gmail.com>', |
|
26 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
|
27 ] |
|
28 |
|
29 |
|
30 from google.appengine.ext import db |
|
31 |
|
32 from django.utils.translation import ugettext |
|
33 |
|
34 from soc.models.survey import Survey |
|
35 import soc.models.student_project |
|
36 import soc.models.user |
|
37 |
|
38 |
|
39 class SurveyRecord(db.Expando): |
|
40 """Record produced each time Survey is taken. |
|
41 |
|
42 Like SurveyContent, this model includes dynamic properties |
|
43 corresponding to the fields of the survey. |
|
44 |
|
45 This also contains a Binary grade value that can be added/edited |
|
46 by the administrator of the Survey. |
|
47 """ |
|
48 |
|
49 #: The survey for which this entity is a record. |
|
50 survey = db.ReferenceProperty(Survey, collection_name="survey_records") |
|
51 |
|
52 #: Reference to the User entity which took this survey. |
|
53 user = db.ReferenceProperty(reference_class=soc.models.user.User, |
|
54 required=True, collection_name="surveys_taken", |
|
55 verbose_name=ugettext('Created by')) |
|
56 |
|
57 #: Reference to the Project that this record belongs to. |
|
58 # TODO should be moved to its own subclass |
|
59 project = db.ReferenceProperty(soc.models.student_project.StudentProject, |
|
60 collection_name="survey_records") |
|
61 |
|
62 #: Grade given to the project that this survey is about. |
|
63 # TODO should be moved to its own subclass |
|
64 grade = db.BooleanProperty(required=False) |
|
65 |
|
66 #: Date when this record was created. |
|
67 created = db.DateTimeProperty(auto_now_add=True) |
|
68 |
|
69 #: Date when this record was last modified. |
|
70 modified = db.DateTimeProperty(auto_now=True) |
|
71 |
|
72 def getValues(self): |
|
73 """Method to get dynamic property values for a survey record. |
|
74 |
|
75 Right now it gets all dynamic values, but it could also be confined to |
|
76 the SurveyContent entity linked to the survey entity. |
|
77 """ |
|
78 survey_order = self.survey.survey_content.getSurveyOrder() |
|
79 values = [] |
|
80 for position, property in survey_order.items(): |
|
81 values.insert(position, getattr(self, property, None)) |
|
82 return values |