app/soc/models/survey_record.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 09 Jul 2009 11:52:35 +0200
changeset 2580 cd3b42f52b21
parent 2515 a3513142ae01
child 2588 db306bbda381
permissions -rw-r--r--
Added skeleton view and templates for GradingSurveyGroup.
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
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    31
from soc.models.survey import Survey
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    32
import soc.models.user
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    33
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    34
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    35
class BaseSurveyRecord(db.Expando):
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    36
  """Record produced each time Survey is taken.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    37
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    38
  Like SurveyContent, this model includes dynamic properties
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    39
  corresponding to the fields of the survey.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    40
  """
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    41
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
    42
  #: The survey for which this entity is a record.
2515
a3513142ae01 Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2493
diff changeset
    43
  survey = db.ReferenceProperty(Survey, collection_name="survey_records")
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    44
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    45
  #: Date when this record was created.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    46
  created = db.DateTimeProperty(auto_now_add=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    47
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    48
  #: Date when this record was last modified.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    49
  modified = db.DateTimeProperty(auto_now=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    50
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    51
  def getValues(self):
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    52
    """Method to get dynamic property values for a survey record.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    53
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    54
    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
    55
    the SurveyContent entity linked to the survey entity.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    56
    """
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
    57
    survey_order = self.survey.survey_content.getSurveyOrder()
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    58
    values = []
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    59
    for position, property in survey_order.items():
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    60
        values.insert(position, getattr(self, property, None))
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    61
    return values
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    62
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    63
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    64
class SurveyRecord(BaseSurveyRecord):
2515
a3513142ae01 Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2493
diff changeset
    65
  """Record produced by taking a Survey.
a3513142ae01 Several stylefixes due to received reviews.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2493
diff changeset
    66
  """
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    67
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
    68
  #: 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
    69
  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
    70
                              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
    71
                              verbose_name=ugettext('Taken by'))