app/soc/models/answer.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 13 Sep 2008 22:00:51 +0000
changeset 141 e120c24b89e2
parent 54 03e267d67478
child 181 fdd29818a954
permissions -rw-r--r--
Added Melange front page edit view where you can change title, content, feed url. Created SiteSettings and Document models and some logic for them. Added isFeedURLValid function in soc/logic/feed.py. Created some functions for handling datastore updates of different kinds of Models (soc/logic/model.py). Fixed some typos and too long lines of code. Patch by: Pawel Solyga Review by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
# 
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
# 
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""This module contains the Answer Model."""
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
__authors__ = [
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
  '"Todd Larsen" <tlarsen@google.com>',
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    22
]
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
from google.appengine.ext import db
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    26
from soc import models
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
import soc.models.question
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    28
import soc.models.review
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    30
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
class Answer(db.Model):
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
  """Model of a specific Answer to a Question in a specific Review."""
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
  #: A required many:1 relationship, where each of many Answers is
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
  #: a specific answer to a single Question.  An Answer must always
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
  #: be associated with a Question in order to be interpreted.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
  #: It is currently unclear how useful this back-reference will be,
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
  #: since the same question could be used in multiple different
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
  #: Review "templates". Given this, 'answers' currently only exists
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  #: for completeness. 
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
  question = db.ReferenceProperty(reference_class=models.question.Question,
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
                                  required=True, collection_name="answers")
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
  #: A required many:1 relationship, where each of many Answers to
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
  #: different Questions represents the answer set of a specific
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
  #: Review. The back-reference in the Review model is a Query named
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
  #: 'answers' which represents all of the specific answers to
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    48
  #: questions in that Review.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    49
  review = db.ReferenceProperty(reference_class=models.review.Review,
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    50
                                required=True, collection_name="answers")
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    51
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    52
  #: db.StringProperty storing the "short" answer to the question;
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
  #: the interpretation of this value depends on the Question entity
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    54
  #: referred to by 'question'. Answers can be indexed, filtered, and
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    55
  #: sorted by their "short" answer. Depending on the Question type,
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    56
  #: some Answers will use only 'short', some only 'long', some both.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    57
  short = db.StringProperty()
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    58
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    59
  #: db.TextProperty storing the "long" answer to the question;
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    60
  #: the interpretation of this value depends on the Question entity
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    61
  #: referred to by 'question'.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    62
  long = db.TextProperty()
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    63
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    64
  #: db.ListProperty of short strings from the list of possible
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    65
  #: picks in the question.pick_choices list.
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    66
  picks = db.ListProperty(item_type=str)
7a901a99b349 Initial definition of the Answer Model.
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    67