12 # distributed under the License is distributed on an "AS IS" BASIS, |
12 # distributed under the License is distributed on an "AS IS" BASIS, |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
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 """This module contains the Answer Model.""" |
17 """This module contains the Answer Model""" |
18 |
18 |
19 __authors__ = [ |
19 __authors__ = [ |
20 '"Todd Larsen" <tlarsen@google.com>', |
20 '"Todd Larsen" <tlarsen@google.com>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
21 '"Sverre Rabbelier" <sverre@rabbelier.nl>', |
22 ] |
22 ] |
23 |
23 |
24 |
24 |
|
25 import polymodel |
|
26 |
25 from google.appengine.ext import db |
27 from google.appengine.ext import db |
26 |
28 |
27 from soc import models |
|
28 from soc.models import base |
|
29 |
|
30 import soc.models.question |
29 import soc.models.question |
31 import soc.models.review |
30 import soc.models.quiz |
|
31 import soc.models.response |
32 |
32 |
33 |
33 |
34 class Answer(base.ModelWithFieldAttributes): |
34 class Answer(polymodel.PolyModel): |
35 """Model of a specific Answer to a Question in a specific Review.""" |
35 """Model of a specific Answer to a Question in a specific Response. |
|
36 |
|
37 The properties in this Model do not have verbose_name or help_text, |
|
38 because the dynamic nature of the forms required to create, edit, and |
|
39 use entities of this Model make them pretty useless. |
|
40 """ |
36 |
41 |
37 #: A required many:1 relationship, where each of many Answers is |
42 #: A required many:1 relationship, where each of many Answers is |
38 #: a specific answer to a single Question. An Answer must always |
43 #: a specific answer to a single Question. An Answer must always |
39 #: be associated with a Question in order to be interpreted. |
44 #: be associated with a Question in order to be interpreted. |
40 #: It is currently unclear how useful this back-reference will be, |
45 #: It is currently unclear how useful this back-reference will be, |
41 #: since the same question could be used in multiple different |
46 #: since the same Question could be used in multiple different |
42 #: Review "templates". Given this, 'answers' currently only exists |
47 #: Quizzes. Given this, 'answers' currently only exists for |
43 #: for completeness. |
48 #: completeness. |
44 # TODO: Uncomment when Question model is committed |
49 question = db.ReferenceProperty( |
45 #question = db.ReferenceProperty(reference_class=models.question.Question, |
50 reference_class=soc.models.question.Question, required=True, |
46 # required=True, collection_name="answers") |
51 collection_name="answers") |
47 |
52 |
48 #: A required many:1 relationship, where each of many Answers to |
53 #: A many:1 relationship, where each of many Answers to different |
49 #: different Questions represents the answer set of a specific |
54 #: Questions represents the answer set of a specific Response to a Quiz. |
50 #: Review. The back-reference in the Review model is a Query named |
55 #: The back-reference in the Response model is a Query named 'answers' |
51 #: 'answers' which represents all of the specific answers to |
56 #: which represents all of the specific Answers to Questions in that |
52 #: questions in that Review. |
57 #: Response. |
53 review = db.ReferenceProperty(reference_class=models.review.Review, |
58 #: |
54 required=True, collection_name="answers") |
59 #: One and only one of the response or quiz ReferenceProperties *must* |
|
60 #: be defined for an Answer entity. |
|
61 response = db.ReferenceProperty( |
|
62 reference_class=soc.models.response.Response, required=False, |
|
63 collection_name="answers") |
55 |
64 |
56 #: db.StringProperty storing the "short" answer to the question; |
65 #: A many:1 relationship, where each of many Answers to different |
57 #: the interpretation of this value depends on the Question entity |
66 #: Questions represents the solution set for the Questions in a Quiz. |
58 #: referred to by 'question'. Answers can be indexed, filtered, and |
67 #: The back-reference in the Quiz model is a Query named 'solutions' |
59 #: sorted by their "short" answer. Depending on the Question type, |
68 #: which represents all of the solutions to Questions in that Quiz. |
60 #: some Answers will use only 'short', some only 'long', some both. |
69 #: |
61 short = db.StringProperty() |
70 #: One and only one of the response or quiz ReferenceProperties *must* |
|
71 #: be defined for an Answer entity. |
|
72 quiz = db.ReferenceProperty( |
|
73 reference_class=soc.models.quiz.Quiz, required=False, |
|
74 collection_name="solutions") |
62 |
75 |
63 #: db.TextProperty storing the "long" answer to the question; |
76 #: db.ListProperty of strings representing the answer value or values. |
64 #: the interpretation of this value depends on the Question entity |
77 #: |
65 #: referred to by 'question'. |
78 #: For Questions that are not multiple-choice (see the choice_ids and |
66 long = db.TextProperty() |
79 #: choices properties of soc.models.question.Question), this list will |
67 |
80 #: contain a single string that is a free-form text answer. |
68 #: db.ListProperty of short strings from the list of possible |
81 #: |
69 #: picks in the question.pick_choices list. |
82 #: For Questions that *are* multiple-choice, this list will contain one |
70 picks = db.ListProperty(item_type=str) |
83 #: or more short, plain-text, "link_name-like" strings representing the |
71 |
84 #: "encoded" answer choices (see the choice_ids property in |
|
85 #: soc.models.question.Question). For such multiple-choice Questions, |
|
86 #: how many strings are stored depends on the max_answers property of |
|
87 #: the soc.models.question.Question entity for which this is an Answer. |
|
88 #: |
|
89 #: If question.is_optional is True, 'answers' may even be None or an |
|
90 #: empty list if no answers were provided. |
|
91 #: |
|
92 #: Answers can be indexed, filtered, and sorted by this list, but only in |
|
93 #: the way that query operators work with a db.ListProperty. |
|
94 answers = db.ListProperty(item_type=str) |