author | Augie Fackler <durin42@gmail.com> |
Sun, 12 Jul 2009 11:46:36 -0500 | |
changeset 2613 | 169d69967431 |
parent 2588 | db306bbda381 |
child 2763 | 80d625f78176 |
permissions | -rw-r--r-- |
2429
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
2 |
# |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
4 |
# |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
8 |
# |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
10 |
# |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
16 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
17 |
"""SurveyRecord represents a single Survey result. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
18 |
""" |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
19 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
21 |
'"Daniel Diniz" <ajaksu@gmail.com>', |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
22 |
'"James Levy" <jamesalexanderlevy@gmail.com>', |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
23 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
24 |
] |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
25 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
26 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
27 |
from google.appengine.ext import db |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
28 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
29 |
from django.utils.translation import ugettext |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
30 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
31 |
from soc.models.survey import Survey |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
32 |
import soc.models.user |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
33 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
34 |
|
2442
dd1f94c3594c
Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents:
2429
diff
changeset
|
35 |
class BaseSurveyRecord(db.Expando): |
2429
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
36 |
"""Record produced each time Survey is taken. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
37 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
38 |
Like SurveyContent, this model includes dynamic properties |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
39 |
corresponding to the fields of the survey. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
40 |
""" |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
41 |
|
2493
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
42 |
#: The survey for which this entity is a record. |
2588
db306bbda381
Indention fixes and adding "reference_class=" in ReferenceProperty params.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2515
diff
changeset
|
43 |
survey = db.ReferenceProperty( |
db306bbda381
Indention fixes and adding "reference_class=" in ReferenceProperty params.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
2515
diff
changeset
|
44 |
reference_class=Survey, collection_name="survey_records") |
2429
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
45 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
46 |
#: Date when this record was created. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
47 |
created = db.DateTimeProperty(auto_now_add=True) |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
48 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
49 |
#: Date when this record was last modified. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
50 |
modified = db.DateTimeProperty(auto_now=True) |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
51 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
52 |
def getValues(self): |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
53 |
"""Method to get dynamic property values for a survey record. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
54 |
|
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
55 |
Right now it gets all dynamic values, but it could also be confined to |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
56 |
the SurveyContent entity linked to the survey entity. |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
57 |
""" |
2493
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
58 |
survey_order = self.survey.survey_content.getSurveyOrder() |
2429
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
59 |
values = [] |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
60 |
for position, property in survey_order.items(): |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
61 |
values.insert(position, getattr(self, property, None)) |
a0a1dd1cc69e
Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff
changeset
|
62 |
return values |
2442
dd1f94c3594c
Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents:
2429
diff
changeset
|
63 |
|
dd1f94c3594c
Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents:
2429
diff
changeset
|
64 |
|
dd1f94c3594c
Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents:
2429
diff
changeset
|
65 |
class SurveyRecord(BaseSurveyRecord): |
2515
a3513142ae01
Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
66 |
"""Record produced by taking a Survey. |
a3513142ae01
Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2493
diff
changeset
|
67 |
""" |
2442
dd1f94c3594c
Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents:
2429
diff
changeset
|
68 |
|
2493
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
69 |
#: Reference to the User entity which took this survey. |
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
70 |
user = db.ReferenceProperty(reference_class=soc.models.user.User, |
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
71 |
required=True, collection_name="surveys_taken", |
0aabd2d76606
Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
2446
diff
changeset
|
72 |
verbose_name=ugettext('Taken by')) |