app/soc/models/survey_record.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 18 Sep 2009 20:06:28 +0200
changeset 2957 f6515daaf000
parent 2763 80d625f78176
child 2975 e73c0eb59022
permissions -rw-r--r--
Enable document system for GHOP As can be seen from the changes outside app/soc/modules, there is still some work to be done to make the modules fully restricted to configuration changes and code in app/soc/modules. Reviewed-by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     2
#
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     4
#
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     8
#
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    10
#
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    16
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    17
"""SurveyRecord represents a single Survey result.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    18
"""
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    19
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    20
__authors__ = [
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    21
  '"Daniel Diniz" <ajaksu@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    22
  '"James Levy" <jamesalexanderlevy@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    23
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    24
]
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    25
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    26
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    27
from google.appengine.ext import db
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    28
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    29
from django.utils.translation import ugettext
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    30
2763
80d625f78176 Added base Model for Expando models.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2588
diff changeset
    31
from soc.models.expando_base import ExpandoBase
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    32
from soc.models.survey import Survey
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    33
import soc.models.user
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    34
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    35
2763
80d625f78176 Added base Model for Expando models.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2588
diff changeset
    36
class BaseSurveyRecord(ExpandoBase):
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    37
  """Record produced each time Survey is taken.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    38
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    39
  Like SurveyContent, this model includes dynamic properties
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    40
  corresponding to the fields of the survey.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    41
  """
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    42
2493
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    43
  #: The survey for which this entity is a record.
2588
db306bbda381 Indention fixes and adding "reference_class=" in ReferenceProperty params.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2515
diff changeset
    44
  survey = db.ReferenceProperty(
db306bbda381 Indention fixes and adding "reference_class=" in ReferenceProperty params.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 2515
diff changeset
    45
      reference_class=Survey, collection_name="survey_records")
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    46
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    47
  #: Date when this record was created.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    48
  created = db.DateTimeProperty(auto_now_add=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    49
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    50
  #: Date when this record was last modified.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    51
  modified = db.DateTimeProperty(auto_now=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    52
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    53
  def getValues(self):
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    54
    """Method to get dynamic property values for a survey record.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    55
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    56
    Right now it gets all dynamic values, but it could also be confined to
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    57
    the SurveyContent entity linked to the survey entity.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    58
    """
2493
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    59
    survey_order = self.survey.survey_content.getSurveyOrder()
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    60
    values = []
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    61
    for position, property in survey_order.items():
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    62
        values.insert(position, getattr(self, property, None))
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    63
    return values
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    64
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    65
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    66
class SurveyRecord(BaseSurveyRecord):
2515
a3513142ae01 Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2493
diff changeset
    67
  """Record produced by taking a Survey.
a3513142ae01 Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2493
diff changeset
    68
  """
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    69
2493
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    70
  #: Reference to the User entity which took this survey.
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    71
  user = db.ReferenceProperty(reference_class=soc.models.user.User,
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    72
                              required=True, collection_name="surveys_taken",
0aabd2d76606 Edit SurveyRecord model to not make use of different Survey property for each subclass.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2446
diff changeset
    73
                              verbose_name=ugettext('Taken by'))