app/soc/models/survey_record.py
author Daniel Diniz <ajaksu@gmail.com>
Sun, 28 Jun 2009 23:58:03 +0200
changeset 2442 dd1f94c3594c
parent 2429 a0a1dd1cc69e
child 2444 6276c3340c30
permissions -rw-r--r--
Start on adding ProjectSurvey and GradingProjectSurvey. New classes still need to be made for logic and views so the appropriate methods can be overwritten. Reviewed by: Lennard de Rijk
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
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    19
ProjectSurveyRecord allows linking two result sets by StudentProject.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    20
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    21
GradingProjectSurveyRecord stores the grade in an evaluation survey.
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    22
"""
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    23
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    24
__authors__ = [
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    25
  '"Daniel Diniz" <ajaksu@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    26
  '"James Levy" <jamesalexanderlevy@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    27
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    28
]
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    29
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 google.appengine.ext import db
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    32
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    33
from django.utils.translation import ugettext
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    34
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    35
from soc.models.survey import Survey
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    36
from soc.models.survey import GradingProjectSurvey
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    37
from soc.models.survey import ProjectSurvey
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    38
import soc.models.student_project
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    39
import soc.models.user
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    40
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    41
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    42
class BaseSurveyRecord(db.Expando):
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    43
  """Record produced each time Survey is taken.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    44
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    45
  Like SurveyContent, this model includes dynamic properties
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    46
  corresponding to the fields of the survey.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    47
  """
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    48
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    49
  #: Reference to the User entity which took this survey.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    50
  user = db.ReferenceProperty(reference_class=soc.models.user.User,
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    51
                              required=True, collection_name="surveys_taken",
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    52
                              verbose_name=ugettext('Created by'))
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    53
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    54
  #: Date when this record was created.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    55
  created = db.DateTimeProperty(auto_now_add=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    56
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    57
  #: Date when this record was last modified.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    58
  modified = db.DateTimeProperty(auto_now=True)
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    59
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    60
  def getValues(self):
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    61
    """Method to get dynamic property values for a survey record.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    62
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    63
    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
    64
    the SurveyContent entity linked to the survey entity.
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    65
    """
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    66
    survey_order = self.getSurvey().survey_content.getSurveyOrder()
2429
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    67
    values = []
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    68
    for position, property in survey_order.items():
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    69
        values.insert(position, getattr(self, property, None))
a0a1dd1cc69e Added SurveyRecordModel.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    70
    return values
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    71
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    72
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    73
# TODO(ajaksu) think of a better way to handle the survey reference
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    74
class SurveyRecord(BaseSurveyRecord):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    75
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    76
  #: The survey for which this entity is a record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    77
  survey = db.ReferenceProperty(Survey, collection_name="survey_records")
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    78
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    79
  def getSurvey(self):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    80
    """Returns the Survey belonging to this record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    81
    """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    82
    return self.survey
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    83
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    84
class ProjectSurveyRecord(SurveyRecord):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    85
  """Record linked to a Project, enabling to store which Projects had their
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    86
  Survey done.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    87
  """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    88
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    89
  #: The survey for which this entity is a record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    90
  project_survey = db.ReferenceProperty(ProjectSurvey,
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    91
                                collection_name="project_survey_records")
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    92
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    93
  #: Reference to the Project that this record belongs to.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    94
  project = db.ReferenceProperty(soc.models.student_project.StudentProject,
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    95
                                 collection_name="survey_records")
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    96
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    97
  def getSurvey(self):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    98
    """Returns the ProjectSurvey that belongs to this record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
    99
    """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   100
    return self.project_survey
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   101
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   102
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   103
class GradingProjectSurveyRecord(ProjectSurveyRecord):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   104
  """Grading record for evaluation surveys.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   105
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   106
  Represents the grading part of a evaluation survey group (usually a pair)
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   107
  where the grading (e.g. Mentor's) survey is linked to a non-grading (e.g
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   108
  Student's) one by a project.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   109
  """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   110
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   111
  #: The survey for which this entity is a record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   112
  grading_survey = db.ReferenceProperty(GradingProjectSurvey,
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   113
                                collection_name="grading_survey_records")
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   114
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   115
  #: Required grade given to the project that this survey is about.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   116
  grade = db.BooleanProperty(required=True)
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   117
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   118
  def getSurvey(self):
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   119
    """Returns the GradingProjectSurvey that belongs to this record.
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   120
    """
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2429
diff changeset
   121
    return self.grading_survey