app/soc/models/quiz.py
author Todd Larsen <tlarsen@google.com>
Wed, 15 Oct 2008 17:10:27 +0000
changeset 339 b9be44e09530
child 342 72482d8e5b34
permissions -rw-r--r--
Define the Models for implementing Quizzes (collections of Questions) and their Responses (collections of Answers to those Questions). These Models would form the basis of storage for such items as: Terms of Service (Quiz) Question ("I agree...") Response -> Answer (answer to "I agree..." confirmation) solution ("Yes" Answer to the "I agree..." Question) Mentor and Student surveys (Quiz) Questions (including "Pay this student?") Response -> Answers solution ("Yes" Answer to the "Pay this student?" Question) Organization applications Student Proposal review, comment, and scoring system GHOP task tracking (a specific task list item would be a Quiz) Patch by: Todd Larsen Review by: Pawel Solyga, Sverre Rabbelier, Chen Lunpeng Review URL: http://codereviews.googleopensourceprograms.com/1403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
from google.appengine.ext import db
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    26
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
from django.utils.translation import ugettext_lazy
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
import soc.models.answer
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
import soc.models.document
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
import soc.models.question
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
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
class Quiz(soc.models.document.Document):
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    35
  """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
    36
  
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  (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
    38
  
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
  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
    40
  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
    41
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
  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
    43
  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
    44
  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
    45
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    46
  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
    47
  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
    48
  described below.
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    49
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
    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
    51
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    52
    work.abstract:  summary displayed as a snippet in Quiz list views
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
    work.authors:  the Authors of the Work referred to by this relation
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
      are the authors of the Quiz (but not necessarily the individual
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
      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
    57
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
    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
    59
      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
    60
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
    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
    62
      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
    63
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
    document.content:  the "preface" of the Quiz, displayed before any
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
      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
    66
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    67
  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
    68
  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
    69
  relationships:
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
    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
    72
      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
    73
      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
    74
      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
    75
      Model 'quiz' reference.
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
      
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
    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
    78
      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
    79
      '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
    80
      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
    81
      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
    82
      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
    83
      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
    84
      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
    85
      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
    86
      "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
    87
      Answers (to the one Question that matters in this case...).
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)