app/soc/models/response.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 22 Nov 2008 22:44:02 +0000
changeset 568 6713617751b4
parent 533 ba3309b2fd30
child 1307 091a21cf3627
permissions -rw-r--r--
Remove inheritance from PolyModel in Answer and Linkable model. Replace PolyModel inheritance with base.ModelWithFieldAttributes. A little explanation why we are trying to get rid of PolyModel. We decided to use PolyModel in order to get support for model inheritance in App Engine, however as we know this was a hacky workaround which added inheritance_line property to each model. Recent commits which added Linkable model caused our data viewer in admin console to show only one model "Linkable" since all of the classes inherited from it. Basically datastore viewer was useless plus we had a really big mess in datastore since everything was of one kind (Linkable). It's almost like creating one huge table in SQL database. Upcoming commits will eliminate all usage of PolyModel and finally remove PolyModel from our repository. We are still using inheritance however this doesn't modify how models are saved in data store so basically it's like copy and paste of properties from parent models. Patch by: Pawel Solyga, Sverre Rabbelier
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
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
    25
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 385
diff changeset
    26
import soc.models.linkable
339
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    27
import soc.models.quiz
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    28
import soc.models.user
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    29
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    30
533
ba3309b2fd30 Move LINK_ID and SCOPE_PATH regular expressions to soc/models/linkable.py.
Todd Larsen <tlarsen@google.com>
parents: 385
diff changeset
    31
class Response(soc.models.linkable.Linkable):
339
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    32
  """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
    33
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    34
  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
    35
  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
    36
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    37
  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
    38
  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
    39
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    40
    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
    41
      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
    42
      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
    43
      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
    44
      reference.
342
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    45
72482d8e5b34 Remove the proposed WorksAuthors many:many relation and promote the "founder"
Todd Larsen <tlarsen@google.com>
parents: 339
diff changeset
    46
    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
    47
      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
    48
      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
    49
      Model 'response' reference.
339
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    50
  """
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
  #: 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
    53
  #: 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
    54
  #: (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
    55
  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
    56
                              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
    57
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    58
  #: 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
    59
  #: 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
    60
  respondent = db.ReferenceProperty(
b9be44e09530 Define the Models for implementing Quizzes (collections of Questions) and their
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
      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
    62
      collection_name="responses")
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
  # 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
    65
  #   instead?