app/soc/models/survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Wed, 01 Jul 2009 16:28:27 +0200
changeset 2474 b8e25769880d
parent 2454 849956450d69
child 2493 0aabd2d76606
permissions -rw-r--r--
Move getMenusForScope to the end of the View class. Adhering to our principle that we the methods we use for generating our menus can be usually found at the bottom of the View class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2428
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     2
#
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     4
#
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     8
#
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    10
#
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    16
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    17
"""This module contains the Survey models.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    18
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    19
Survey describes meta-information and permissions.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    20
SurveyContent contains the fields (questions) and their metadata.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    21
"""
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    22
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    23
__authors__ = [
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    24
  '"Daniel Diniz" <ajaksu@gmail.com>',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    25
  '"James Levy" <jamesalexanderlevy@gmail.com>',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    26
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    27
]
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    28
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    29
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    30
from google.appengine.ext import db
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    31
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    32
from django.utils.translation import ugettext
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    33
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    34
import soc.models.work
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    35
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    36
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    37
class SurveyContent(db.Expando):
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    38
  """Fields (questions) and schema representation of a Survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    39
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    40
  Each survey content entity consists of properties where names and default
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    41
  values are set by the survey creator as survey fields.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    42
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    43
    schema: A dictionary (as text) storing, for each field:
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    44
      - type
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    45
      - index
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    46
      - order (for choice questions)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    47
      - render (for choice questions)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    48
      - question (free form text question, used as label)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    49
  """
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    50
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    51
  #:Field storing the content of the survey in the form of a dictionary.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    52
  schema = db.TextProperty()
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    53
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    54
  #: Fields storing the created on and last modified on dates.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    55
  created = db.DateTimeProperty(auto_now_add=True)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    56
  modified = db.DateTimeProperty(auto_now=True)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    57
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    58
  def getSurveyOrder(self):
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    59
    """Make survey questions always appear in the same (creation) order.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    60
    """
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    61
    survey_order = {}
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    62
    schema = eval(self.schema)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    63
    for property in self.dynamic_properties():
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    64
      # map out the order of the survey fields
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    65
      index = schema[property]["index"]
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    66
      if index not in survey_order:
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    67
        survey_order[index] = property
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    68
      else:
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    69
        # Handle duplicated indexes
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    70
        survey_order[max(survey_order) + 1] = property
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    71
    return survey_order
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    72
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    73
  def orderedProperties(self):
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    74
    """Helper for View.get_fields(), keep field order.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    75
    """
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    76
    properties = []
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    77
    survey_order = self.getSurveyOrder().items()
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    78
    for position,key in survey_order:
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    79
      properties.insert(position, key)
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    80
    return properties
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    81
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    82
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    83
class Survey(soc.models.work.Work):
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    84
  """Model of a Survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    85
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    86
  This model describes meta-information and permissions.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    87
  The actual questions of the survey are contained
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    88
  in the SurveyContent entity.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    89
  """
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    90
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    91
  URL_NAME = 'survey'
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    92
  # euphemisms like "student" and "mentor" should be used if possible
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    93
  SURVEY_ACCESS = ['admin', 'restricted', 'member', 'user']
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    94
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    95
  # these are GSoC specific, so eventually we can subclass this
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    96
  SURVEY_TAKING_ACCESS = ['student', 
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    97
                          'mentor',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    98
                          'org_admin',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    99
                          'user',
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   100
                          'public']
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   101
  GRADE_OPTIONS = {'midterm':['mid_term_passed', 'mid_term_failed'],
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   102
                   'final':['final_passed', 'final_failed'],
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   103
                   'N/A':[] }
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   104
2428
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   105
  prefix = db.StringProperty(default='program', required=True,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   106
      choices=['site', 'club', 'sponsor', 'program', 'org', 'user'],
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   107
      verbose_name=ugettext('Prefix'))
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   108
  prefix.help_text = ugettext(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   109
      'Indicates the prefix of the survey,'
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   110
      ' determines which access scheme is used.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   111
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   112
  #: Field storing the required access to read this survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   113
  read_access = db.StringProperty(default='restricted', required=True,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   114
      choices=SURVEY_ACCESS,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   115
      verbose_name=ugettext('Survey Read Access'))
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   116
  read_access.help_text = ugettext(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   117
      'Indicates who can read the results of this survey.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   118
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   119
  #: Field storing the required access to write to this survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   120
  write_access = db.StringProperty(default='admin', required=True,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   121
      choices=SURVEY_ACCESS,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   122
      verbose_name=ugettext('Survey Write Access'))
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   123
  write_access.help_text = ugettext(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   124
      'Indicates who can edit this survey.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   125
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   126
  #: Field storing the required access to write to this survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   127
  taking_access = db.StringProperty(default='student', required=True,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   128
      choices=SURVEY_TAKING_ACCESS,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   129
      verbose_name=ugettext('Survey Taking Access'))
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   130
  taking_access.help_text = ugettext(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   131
      'Indicates who can take this survey. '
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   132
      'Student/Mentor options are for Midterms and Finals.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   133
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   134
  #: Field storing whether a link to the survey should be featured in
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   135
  #: the sidebar menu (and possibly elsewhere); FAQs, Terms of Service,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   136
  #: and the like are examples of "featured" survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   137
  is_featured = db.BooleanProperty(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   138
      verbose_name=ugettext('Is Featured'))
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   139
  is_featured.help_text = ugettext(
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   140
      'Field used to indicate if a Survey should be featured, for example,'
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   141
      ' in the sidebar menu.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   142
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   143
  #: Date at which the survey becomes available for taking.
2440
05c430d1c147 Renamed opening to survey_start and deadline to survey_end.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2428
diff changeset
   144
  survey_start = db.DateTimeProperty(required=False)
05c430d1c147 Renamed opening to survey_start and deadline to survey_end.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2428
diff changeset
   145
  survey_start.help_text = ugettext(
2428
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   146
      'Indicates a date before which this survey'
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   147
      ' cannot be taken or displayed.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   148
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   149
  #: Deadline for taking survey.
2440
05c430d1c147 Renamed opening to survey_start and deadline to survey_end.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2428
diff changeset
   150
  survey_end = db.DateTimeProperty(required=False)
05c430d1c147 Renamed opening to survey_start and deadline to survey_end.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2428
diff changeset
   151
  survey_end.help_text = ugettext(
2428
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   152
      'Indicates a date after which this survey'
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   153
      ' cannot be taken.')
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   154
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   155
  #: Referenceproperty that specifies the content of this survey.
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   156
  survey_content = db.ReferenceProperty(SurveyContent,
8ca9f32d3fc4 Added Survey and SurveyContent model.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   157
                                     collection_name="survey_parent")
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   158
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   159
  def getRecords(self):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   160
    """Returns all SurveyRecords belonging to this survey.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   161
    """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2440
diff changeset
   162
    return self.survey_records