app/soc/models/response.py
author Todd Larsen <tlarsen@google.com>
Mon, 27 Oct 2008 19:19:44 +0000
changeset 426 114fe0f840c8
parent 385 6d410bf49a82
child 533 ba3309b2fd30
permissions -rw-r--r--
Add tooltips style display of help_text, instead of widening the form with another (often ridiculously large) column. Also, version the .css and .js files so that browsers won't display the wrong cached one when we change something. Patch by: Dmitri Gaskin, Todd Larsen Review by: Todd Larsen
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 Response 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
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
import polymodel
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
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
    27
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
import soc.models.quiz
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
import soc.models.user
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    31
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
class Response(polymodel.PolyModel):
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    33
  """Model of a Response to a Quiz.
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 Response is the "collection point" for a set of specific Answers to the
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    36
  Questions that make up a Quiz.
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
  In addition to the explicit ReferenceProperties in the Response Model, a
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    39
  Response entity participates in these relationships:
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    41
    answers)  a 1:many relationship between Answer entities and this
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    42
      Response.  Each Answer points to the Response to which it is a part.
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    43
      The collection of Answers that make up a Response is implemented as
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    44
      the 'answers' back-reference Query of the Answer model 'response'
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    45
      reference.
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    46
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    47
    proposal)  an optional 1:1 relationship where a Proposal placed its
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    48
      Answers to a Quiz associated with the Proposal.  This relation is
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    49
      implemented as the 'proposal' back-reference Query of the Proposal
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    50
      Model 'response' reference.
339
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
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    53
  #: a required many:1 relationship between Responses and a Quiz that
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    54
  #: defines what Questions for which each Response collects Answers
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    55
  #: (that is, there can be many Responses to the same Quiz)
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    56
  quiz = db.ReferenceProperty(reference_class=soc.models.quiz.Quiz,
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    57
                              required=True, collection_name="responses")
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    59
  #: a required many:1 relationship with a User that indicates which User
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
  #: submitted the Response (answered the Questions in the Quiz)
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
  respondent = db.ReferenceProperty(
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    62
      reference_class=soc.models.user.User, required=True,
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    63
      collection_name="responses")
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
  # TODO(tlarsen): should 'respondent' be a ReferenceProperty to some Role
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
  #   instead?