14 # See the License for the specific language governing permissions and |
14 # See the License for the specific language governing permissions and |
15 # limitations under the License. |
15 # limitations under the License. |
16 |
16 |
17 """SurveyRecord represents a single Survey result. |
17 """SurveyRecord represents a single Survey result. |
18 |
18 |
19 SurveyRecordGroup represents a cluster (mentor/student) of SurveyRecords |
19 ProjectSurveyRecord allows linking two result sets by StudentProject. |
20 for an evaluation period. |
20 |
|
21 GradingProjectSurveyRecord stores the grade in an evaluation survey. |
21 """ |
22 """ |
22 |
23 |
23 __authors__ = [ |
24 __authors__ = [ |
24 '"Daniel Diniz" <ajaksu@gmail.com>', |
25 '"Daniel Diniz" <ajaksu@gmail.com>', |
25 '"James Levy" <jamesalexanderlevy@gmail.com>', |
26 '"James Levy" <jamesalexanderlevy@gmail.com>', |
30 from google.appengine.ext import db |
31 from google.appengine.ext import db |
31 |
32 |
32 from django.utils.translation import ugettext |
33 from django.utils.translation import ugettext |
33 |
34 |
34 from soc.models.survey import Survey |
35 from soc.models.survey import Survey |
|
36 from soc.models.survey import GradingProjectSurvey |
|
37 from soc.models.survey import ProjectSurvey |
35 import soc.models.student_project |
38 import soc.models.student_project |
36 import soc.models.user |
39 import soc.models.user |
37 |
40 |
38 |
41 |
39 class SurveyRecord(db.Expando): |
42 class BaseSurveyRecord(db.Expando): |
40 """Record produced each time Survey is taken. |
43 """Record produced each time Survey is taken. |
41 |
44 |
42 Like SurveyContent, this model includes dynamic properties |
45 Like SurveyContent, this model includes dynamic properties |
43 corresponding to the fields of the survey. |
46 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 """ |
47 """ |
48 |
|
49 #: The survey for which this entity is a record. |
|
50 survey = db.ReferenceProperty(Survey, collection_name="survey_records") |
|
51 |
48 |
52 #: Reference to the User entity which took this survey. |
49 #: Reference to the User entity which took this survey. |
53 user = db.ReferenceProperty(reference_class=soc.models.user.User, |
50 user = db.ReferenceProperty(reference_class=soc.models.user.User, |
54 required=True, collection_name="surveys_taken", |
51 required=True, collection_name="surveys_taken", |
55 verbose_name=ugettext('Created by')) |
52 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 |
53 |
66 #: Date when this record was created. |
54 #: Date when this record was created. |
67 created = db.DateTimeProperty(auto_now_add=True) |
55 created = db.DateTimeProperty(auto_now_add=True) |
68 |
56 |
69 #: Date when this record was last modified. |
57 #: Date when this record was last modified. |
73 """Method to get dynamic property values for a survey record. |
61 """Method to get dynamic property values for a survey record. |
74 |
62 |
75 Right now it gets all dynamic values, but it could also be confined to |
63 Right now it gets all dynamic values, but it could also be confined to |
76 the SurveyContent entity linked to the survey entity. |
64 the SurveyContent entity linked to the survey entity. |
77 """ |
65 """ |
78 survey_order = self.survey.survey_content.getSurveyOrder() |
66 survey_order = self.getSurvey().survey_content.getSurveyOrder() |
79 values = [] |
67 values = [] |
80 for position, property in survey_order.items(): |
68 for position, property in survey_order.items(): |
81 values.insert(position, getattr(self, property, None)) |
69 values.insert(position, getattr(self, property, None)) |
82 return values |
70 return values |
|
71 |
|
72 |
|
73 # TODO(ajaksu) think of a better way to handle the survey reference |
|
74 class SurveyRecord(BaseSurveyRecord): |
|
75 |
|
76 #: The survey for which this entity is a record. |
|
77 survey = db.ReferenceProperty(Survey, collection_name="survey_records") |
|
78 |
|
79 def getSurvey(self): |
|
80 """Returns the Survey belonging to this record. |
|
81 """ |
|
82 return self.survey |
|
83 |
|
84 class ProjectSurveyRecord(SurveyRecord): |
|
85 """Record linked to a Project, enabling to store which Projects had their |
|
86 Survey done. |
|
87 """ |
|
88 |
|
89 #: The survey for which this entity is a record. |
|
90 project_survey = db.ReferenceProperty(ProjectSurvey, |
|
91 collection_name="project_survey_records") |
|
92 |
|
93 #: Reference to the Project that this record belongs to. |
|
94 project = db.ReferenceProperty(soc.models.student_project.StudentProject, |
|
95 collection_name="survey_records") |
|
96 |
|
97 def getSurvey(self): |
|
98 """Returns the ProjectSurvey that belongs to this record. |
|
99 """ |
|
100 return self.project_survey |
|
101 |
|
102 |
|
103 class GradingProjectSurveyRecord(ProjectSurveyRecord): |
|
104 """Grading record for evaluation surveys. |
|
105 |
|
106 Represents the grading part of a evaluation survey group (usually a pair) |
|
107 where the grading (e.g. Mentor's) survey is linked to a non-grading (e.g |
|
108 Student's) one by a project. |
|
109 """ |
|
110 |
|
111 #: The survey for which this entity is a record. |
|
112 grading_survey = db.ReferenceProperty(GradingProjectSurvey, |
|
113 collection_name="grading_survey_records") |
|
114 |
|
115 #: Required grade given to the project that this survey is about. |
|
116 grade = db.BooleanProperty(required=True) |
|
117 |
|
118 def getSurvey(self): |
|
119 """Returns the GradingProjectSurvey that belongs to this record. |
|
120 """ |
|
121 return self.grading_survey |