author | Pawel Solyga <Pawel.Solyga@gmail.com> |
Mon, 17 Nov 2008 22:21:02 +0000 | |
changeset 502 | e1e24c0a4e82 |
parent 385 | 6d410bf49a82 |
child 512 | aae25d2b4464 |
permissions | -rw-r--r-- |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
2 |
# |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
4 |
# |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
8 |
# |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
10 |
# |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
16 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
17 |
"""This module contains the Quiz Model.""" |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
18 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
19 |
__authors__ = [ |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
20 |
'"Todd Larsen" <tlarsen@google.com>', |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
21 |
] |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
22 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
23 |
import reflistprop |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
import soc.models.answer |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
26 |
import soc.models.question |
351
b37fc4c1e189
Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents:
342
diff
changeset
|
27 |
import soc.models.work |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
28 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
29 |
|
351
b37fc4c1e189
Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents:
342
diff
changeset
|
30 |
class Quiz(soc.models.work.Work): |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
31 |
"""Model of a Quiz, a collection of Questions to be asked. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
32 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
33 |
(named Quiz because Questionnaire was too much to type...) |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
34 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
35 |
A Quiz collects a set of Questions to which Answers are given in the |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
36 |
form of a separate Model called a Response. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
37 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
38 |
Quizzes can even be used as templates for comments and scoring |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
39 |
annotations to various Works, such as Documents and Proposals. A |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
40 |
separate Review Model is derived from Quiz for these purposes. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
41 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
42 |
The specific way that the properties and relations inherited from |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
43 |
Document, and also indirectly from Work, are used with a Quiz are |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
44 |
described below. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
45 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
46 |
work.title: the title of the Quiz |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
47 |
|
342
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
48 |
work.author: the author of the Work referred to by this relation |
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
49 |
is the author of the Quiz (but not necessarily the individual |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
50 |
Questions themselves, see the Question Model) |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
51 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
52 |
work.reviews: even Quizzes can be "reviewed" (possibly commented |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
53 |
on during creation or annotated once put into use). |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
54 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
55 |
work.partial_path/work.link_name: used to scope and uniquely identify |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
56 |
a Quiz in the same way these properties are used with Documents, etc. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
57 |
|
351
b37fc4c1e189
Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents:
342
diff
changeset
|
58 |
work.content: the "preface" of the Quiz, displayed before any |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
59 |
of the Questions, usually containing instructions for the Quiz |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
60 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
61 |
In addition to any explicit ReferenceProperties in the Quiz Model and |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
those inherited as described above, a Quiz entity participates in these |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
63 |
relationships: |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
64 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
responses) a 1:many relationship where each Quiz can produce all of |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
its many Response entities that indicate they contain specific |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
67 |
Answers to each of the Questions contained in that Quiz. This relation |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
68 |
is implemented as the 'responses' back-reference Query of the Response |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
69 |
Model 'quiz' reference. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
70 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
solutions) a 1:many relationship where some (or none, or all) of the |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
Questions in the Quiz have "solutions" or "correct Answers". The |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
73 |
'solutions' back-reference Query of the Answer Model 'quiz' reference |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
74 |
is used to point these "correct Answers" at the Quiz to which they |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
75 |
apply. One example of a Quiz having a "correct Answer" is a GSoC |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
76 |
mentor survey that has a "pass" Question that gates if the student |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
77 |
gets paid. The desired Answer for this Question would be |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
78 |
associated with the Quiz via the 'quiz' property and some controller |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
79 |
logic could check if a survey "passed" by querying for these |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
80 |
"solution" Answers and seeing if the survey Response had the "right" |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
81 |
Answers (to the one Question that matters in this case...). |
342
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
82 |
|
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
83 |
proposals) a 1:many relationship where each Quiz can produce all of |
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
84 |
the Proposals that make use of the Quiz as part of the Proposal. |
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
85 |
This relation is implemented as the 'proposals' back-reference Query |
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
86 |
of the Proposal Model 'quiz' reference. |
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
87 |
""" |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
88 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
#: a many:many relationship (many:many because a given Question can be |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
#: reused in more than one Quiz, and each Quiz is made up of one or more |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
91 |
#: Questions) between Question entities and, when combined, the Quiz they |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
92 |
#: form. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
93 |
#: |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
#: A ReferenceListProperty is used instead of a special many:many |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
#; relation Model for a number of reasons: |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
96 |
#: 1) the Questions in a Quiz need to be ordered |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
97 |
#: 2) Quizzes will have relatively few Questions, so the performance |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
98 |
#: ReferenceListProperty is not a major concern |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
99 |
#: 3) querying a Question for all of the Quizzes that contain it is |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
100 |
#: a rare occurrence, so the expense of a ListProperty query is |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
101 |
#: not a real concern |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
102 |
questions = reflistprop.ReferenceListProperty( |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
soc.models.question.Question, default=None) |