author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 21 Feb 2009 10:36:04 +0000 | |
changeset 1420 | c49d6f79663d |
parent 1308 | 35b75ffcbb37 |
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 |
# |
1308
35b75ffcbb37
Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents:
1307
diff
changeset
|
3 |
# Copyright 2008 the Melange authors. |
339
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 |
|
645
262b27ed23af
Remov unused import from Quiz model and add missing blank line.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents:
533
diff
changeset
|
23 |
|
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
24 |
import reflistprop |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
25 |
|
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 |
|
351
b37fc4c1e189
Eliminate the Work.abstract property and move the Document.content property
Todd Larsen <tlarsen@google.com>
parents:
342
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
|
533
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
513
diff
changeset
|
58 |
linkable.scope/linkable.link_id: used to scope and uniquely |
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
513
diff
changeset
|
59 |
identify a Quiz in the same way these properties are used with |
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
513
diff
changeset
|
60 |
Documents, etc. |
ba3309b2fd30
Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents:
513
diff
changeset
|
61 |
|
339
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
62 |
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
|
63 |
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
|
64 |
relationships: |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
65 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
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
|
69 |
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
|
70 |
Model 'quiz' reference. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
71 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
'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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
"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
|
82 |
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
|
83 |
|
72482d8e5b34
Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents:
339
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
""" |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
89 |
|
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
90 |
#: 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
|
91 |
#: 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
|
92 |
#: 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
|
93 |
#: form. |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
94 |
#: |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
95 |
#: 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
|
96 |
#; 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
|
97 |
#: 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
|
98 |
#: 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
|
99 |
#: 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
|
100 |
#: 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
|
101 |
#: 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
|
102 |
#: not a real concern |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
103 |
questions = reflistprop.ReferenceListProperty( |
b9be44e09530
Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff
changeset
|
104 |
soc.models.question.Question, default=None) |