app/soc/logic/models/survey.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 30 Jun 2009 14:56:48 +0200
changeset 2464 64b241a237b2
parent 2462 2d5d2961f774
child 2466 70854ec7909d
permissions -rw-r--r--
Merge params from inheriting Survey views so functionality can be reused.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     2
#
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     4
#
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     8
#
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    10
#
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    16
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    17
"""Survey (Model) query functions.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    18
"""
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    19
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    20
__authors__ = [
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    21
  '"Daniel Diniz" <ajaksu@gmail.com>',
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    22
  '"James Levy" <jamesalexanderlevy@gmail.com>',
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    23
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    24
  ]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    25
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    26
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    27
import logging
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    28
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    29
from google.appengine.ext import db
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    30
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    31
from soc.cache import sidebar
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    32
from soc.logic.models import linkable as linkable_logic
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    33
from soc.logic.models import survey_record as survey_record_logic
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    34
from soc.logic.models.user import logic as user_logic
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    35
from soc.logic.models import work
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    36
from soc.models.program import Program
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    37
from soc.models import student_project
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    38
from soc.models.survey import Survey
2444
6276c3340c30 Separated two survey types out of the main survey model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2443
diff changeset
    39
from soc.models.grading_project_survey import GradingProjectSurvey
6276c3340c30 Separated two survey types out of the main survey model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2443
diff changeset
    40
from soc.models.project_survey import ProjectSurvey
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    41
from soc.models.survey import SurveyContent
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    42
from soc.models.survey_record import SurveyRecord
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    43
from soc.models.survey_record_group import SurveyRecordGroup
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    44
from soc.models.work import Work
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    45
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    46
#TODO(James): Ensure this facilitates variable # of surveys 
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    47
GRADES = {'pass': True, 'fail': False}
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    48
PROJECT_STATUSES = {
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    49
'accepted': {True: 'mid_term_passed', False: 'mid_term_failed'},
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    50
'mid_term_passed': {True: 'passed', False: 'final_failed'}
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    51
}
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    52
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    53
class Logic(work.Logic):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    54
  """Logic methods for the Survey model.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    55
  """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    56
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    57
  def __init__(self, model=Survey, base_model=Work,
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    58
               scope_logic=linkable_logic,
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    59
               record_logic=survey_record_logic.logic):
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    60
    """Defines the name, key_name and model for this entity.
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    61
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    62
    params:
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    63
      record_logic: SurveyRecordLogic (or subclass) instance for this Survey
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    64
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    65
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    66
    self.record_logic = record_logic
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
    67
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    68
    super(Logic, self).__init__(model=model, base_model=base_model,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    69
                                scope_logic=scope_logic)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    70
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    71
  def createSurvey(self, survey_fields, schema, survey_content=False):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    72
    """Create a new survey from prototype.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    73
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    74
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    75
      survey_fields = dict of survey field items (see SurveyContent model)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    76
      schema = metadata about survey fields (SurveyContent.schema)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    77
      survey_content = existing SurveyContent entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    78
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    79
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    80
    if not survey_content:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    81
      survey_content = SurveyContent()
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    82
    else:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    83
      # wipe clean existing dynamic properties if they exist
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    84
      for prop in survey_content.dynamic_properties():
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    85
        delattr(survey_content, prop)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    86
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    87
    for name, value in survey_fields.items():
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    88
      setattr(survey_content, name, value)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    89
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    90
    survey_content.schema = str(schema)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    91
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    92
    db.put(survey_content)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    93
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    94
    return survey_content
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    95
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    96
  def updateSurveyRecord(self, user, survey, survey_record, fields):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    97
    """ Create a new survey record, or get an existing one.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    98
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
    99
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   100
      user = user taking survey
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   101
      survey = survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   102
      survey_record = existing record, if one exists
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   103
      fields = submitted responses to survey fields
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   104
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   105
    if survey_record:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   106
      create = False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   107
      for prop in survey_record.dynamic_properties():
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   108
        delattr(survey_record, prop)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   109
    else:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   110
      create = True
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   111
      survey_record = SurveyRecord(user=user, survey=survey)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   112
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   113
    schema = eval(survey.survey_content.schema)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   114
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   115
    for name, value in fields.items():
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   116
      if name == 'project':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   117
        project = student_project.StudentProject.get(value)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   118
        survey_record.project = project
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   119
      elif name == 'grade':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   120
        survey_record.grade = GRADES[value]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   121
      else:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   122
        pick_multi = name in schema and schema[name]['type'] == 'pick_multi'
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   123
        if pick_multi and hasattr(fields, 'getlist'): # it's a multidict
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   124
          setattr(survey_record, name, ','.join(fields.getlist(name)))
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   125
        else:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   126
          setattr(survey_record, name, value)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   127
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   128
    # if creating evaluation record, set SurveyRecordGroup
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   129
    db.put(survey_record)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   130
    if 'evaluation' in survey.taking_access and create:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   131
      if not project: return False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   132
      role = self.getUserRole(user, survey, project)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   133
      survey_record_group = self.setSurveyRecordGroup(survey,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   134
      survey_record, project)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   135
      if survey_record_group:  db.put(survey_record_group)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   136
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   137
    return survey_record
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   138
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   139
  def setSurveyRecordGroup(self, survey, survey_record, project):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   140
    """First looks for an existing SurveyRecordGroup, using the
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   141
    project and its current status as a filter.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   142
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   143
    IOW SurveyRecordGroup cannot consist of surveys taken with
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   144
    two different statuses.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   145
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   146
    This means that a student cannot take a survey after the mentor
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   147
    has taken the accompanying survey and the project has since
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   148
    changed. (Assuming we want this strict behavior)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   149
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   150
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   151
      survey = survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   152
      survey_record = saved response to survey
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   153
      project = student project for survey taker
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   154
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   155
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   156
    group_query = SurveyRecordGroup.all(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   157
    ).filter("project = ", project
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   158
    ).filter("initial_status = ", project.status
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   159
    )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   160
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   161
    if survey.taking_access == 'mentor evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   162
      survey_record_group = group_query.filter(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   163
      "mentor = ", None ).get()
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   164
    elif survey.taking_access == 'student evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   165
      survey_record_group = group_query.filter(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   166
      "student = ", None ).get()
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   167
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   168
    if not survey_record_group:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   169
      #create Survey Record Group if it doesn't already exist
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   170
      survey_record_group = SurveyRecordGroup(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   171
      project=project,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   172
      initial_status = project.status
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   173
      )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   174
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   175
    if survey.taking_access == 'mentor evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   176
      survey_record_group.mentor_record = survey_record
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   177
    elif survey.taking_access == 'student evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   178
      survey_record_group.student_record = survey_record
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   179
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   180
    return survey_record_group
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   181
2460
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   182
  def getSurveyForContent(self, survey_content):
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   183
    """Returns the Survey belonging to the given SurveyContent.
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   184
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   185
    params:
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   186
      survey_content: the SurveyContent to retrieve the Survey for.
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   187
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   188
    returns:
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   189
      Survey or subclass if possible else None.
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   190
    """
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   191
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   192
    fields = {'survey_content': survey_content}
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   193
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   194
    return self.getForFields(fields, unique=True)
b8b0c631bcfe Added getSurveyForContent method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2459
diff changeset
   195
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   196
<<<<<<< local
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   197
=======
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   198
  def getRecordLogic(self):
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   199
    """Returns SurveyRecordLogic that belongs to this SurveyLogic.
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   200
    """
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   201
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   202
    return self.record_logic
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   203
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   204
>>>>>>> other
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   205
  def getUserRole(self, user, survey, project):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   206
    """Gets the role of a user for a project, used for SurveyRecordGroup.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   207
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   208
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   209
      user: user taking survey
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   210
      survey: survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   211
      project: student project for this user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   212
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   213
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   214
    if survey.taking_access == 'mentor evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   215
      mentors = self.getMentorforProject(user, project)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   216
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   217
      if len(mentors) < 1 or len(mentors) > 1:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   218
        logging.warning('Unable to determine mentor for \
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   219
        user %s. Results returned: %s ' % (
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   220
        user.key().name(), str(mentors)) )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   221
        return False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   222
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   223
      this_mentor = mentors[0]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   224
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   225
    if survey.taking_access == 'student evaluation':
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   226
      students = self.getStudentforProject(user, project)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   227
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   228
      if len(students) < 1 or len(students) > 1:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   229
        logging.warning('Unable to determine student for \
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   230
        user %s. Results returned: %s ' % (
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   231
        user.key().name(), str(students)) )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   232
        return False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   233
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   234
  def getStudentforProject(self, user, project):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   235
    """Get student projects for a given User.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   236
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   237
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   238
      user = survey taking user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   239
      project = survey taker's student project
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   240
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   241
    from soc.logic.models.student import logic as student_logic
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   242
    import soc.models.student
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   243
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   244
    # TODO this should be done per Student or Program
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   245
    # TODO filter for accepted, midterm_passed, etc?
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   246
    user_students = student_logic.getForFields({'user': user}) 
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   247
    if not user_students: return []
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   248
    return set([project.student for project in sum(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   249
    (list(s.student_projects.run())
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   250
    for s in user_students), []) if project.key() == project.key()])
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   251
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   252
  def getMentorforProject(self, user, project):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   253
    """Get Student Projects that are being mentored by the given User.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   254
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   255
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   256
      user = survey taking user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   257
      project = survey taker's student project
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   258
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   259
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   260
    from soc.logic.models.mentor import logic as mentor_logic
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   261
    import soc.models.mentor
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   262
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   263
    # TODO filter for accepted, midterm_passed, etc?
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   264
    # TODO this should be done a program basis not user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   265
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   266
    user_mentors = mentor_logic.getForFields({'user': user}) 
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   267
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   268
    if not user_mentors:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   269
      return []
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   270
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   271
    return set([project.mentor for project in sum(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   272
            (list(mentor.student_projects.run())
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   273
             for mentor in user_mentors), [])
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   274
        if project.key() == project.key()])
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   275
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   276
  def activateGrades(self, survey):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   277
    """Activates the grades on a Grading Survey.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   278
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   279
    TODO(James) Fix this Docstring
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   280
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   281
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   282
      survey = survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   283
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   284
    if survey.taking_access != "mentor evaluation":
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   285
      logging.error("Cannot grade survey %s with taking access %s"
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   286
      % (survey.key().name(), survey.taking_access))
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   287
      return False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   288
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   289
    program = survey.scope or Program.get_by_key_name(survey.scope_path)
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   290
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   291
    for project in program.student_projects.fetch(1000):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   292
      this_record_group = SurveyRecordGroup.all().filter(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   293
      "project = ", project).filter(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   294
      "initial_status = ", project.status).get()
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   295
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   296
      if not this_record_group:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   297
         logging.warning('neither mentor nor student has \
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   298
         taken the survey for project %s' % project.key().name() )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   299
         continue
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   300
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   301
      if not this_record_group.mentor_record:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   302
        # student has taken survey, but not mentor
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   303
        logging.warning('not continuing without mentor record...')
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   304
        continue
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   305
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   306
      status_options = PROJECT_STATUSES.get(project.status)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   307
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   308
      if not status_options:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   309
        logging.warning('unable to find status options for project \
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   310
        status %s' % project.status)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   311
        continue
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   312
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   313
      new_project_grade = this_record_group.mentor_record.grade
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   314
      new_project_status = status_options.get(new_project_grade)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   315
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   316
      if getattr(this_record_group, 'final_status'):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   317
         logging.warning('project %s record group should not \
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   318
         yet have a final status %s' % (
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   319
         project.key().name(), this_record_group.final_status ) )
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   320
         continue
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   321
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   322
      # assign the new status to the project and surveyrecordgroup
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   323
      project.status = new_project_status
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   324
      this_record_group.final_status = new_project_status
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   325
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   326
  def getKeyNameFromPath(self, path):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   327
    """Gets survey key name from a request path.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   328
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   329
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   330
      path = path of the current request
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   331
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   332
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   333
    # TODO determine if kwargs in the request contains this information
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   334
    return '/'.join(path.split('/')[-4:]).split('?')[0]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   335
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   336
  def getProjects(self, survey, user):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   337
    """Get projects linking user to a program.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   338
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   339
    Serves as access handler (since no projects == no access).
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   340
    And retrieves projects to choose from (if mentors have >1 projects).
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   341
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   342
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   343
      survey = survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   344
      user = survey taking user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   345
    """
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   346
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   347
    this_program = survey.scope or Program.get_by_key_name(survey.scope_path)
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   348
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   349
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   350
    if 'mentor' in survey.taking_access:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   351
      these_projects = self.getMentorProjects(user, this_program)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   352
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   353
    elif 'student' in survey.taking_access:
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   354
      these_projects = self.getStudentProjects(user, this_program)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   355
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   356
    logging.info(these_projects)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   357
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   358
    if len(these_projects) == 0:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   359
      return False
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   360
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   361
    return these_projects
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   362
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   363
  def getDebugUser(self, survey, this_program):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   364
    """Debugging method impersonates other roles.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   365
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   366
    Tests taking survey, saving response, and grading.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   367
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   368
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   369
      survey = survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   370
      this_program = program scope of survey
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   371
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   372
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   373
    if 'mentor' in survey.taking_access:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   374
      from soc.models.mentor import Mentor
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   375
      role = Mentor.get_by_key_name(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   376
      this_program.key().name() + "/org_1/test")
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   377
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   378
    if 'student' in survey.taking_access:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   379
      from soc.models.student import Student
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   380
      role = Student.get_by_key_name(
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   381
      this_program.key().name() + "/test")
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   382
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   383
    if role: return role.user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   384
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   385
  def getKeyValuesFromEntity(self, entity):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   386
    """See base.Logic.getKeyNameValues.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   387
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   388
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   389
    return [entity.prefix, entity.scope_path, entity.link_id]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   390
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   391
  def getKeyValuesFromFields(self, fields):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   392
    """See base.Logic.getKeyValuesFromFields.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   393
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   394
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   395
    return [fields['prefix'], fields['scope_path'], fields['link_id']]
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   396
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   397
  def getKeyFieldNames(self):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   398
    """See base.Logic.getKeyFieldNames.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   399
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   400
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   401
    return ['prefix', 'scope_path', 'link_id']
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   402
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   403
  def getScope(self, entity):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   404
    """Gets Scope for entity.
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   405
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   406
    params:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   407
      entity = Survey entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   408
    """
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   409
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   410
    if getattr(entity, 'scope', None):
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   411
      return entity.scope
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   412
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   413
    import soc.models.program
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   414
    import soc.models.organization
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   415
    import soc.models.user
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   416
    import soc.models.site
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   417
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   418
    # use prefix to generate dict key
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   419
    scope_types = {"program": soc.models.program.Program,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   420
    "org": soc.models.organization.Organization,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   421
    "user": soc.models.user.User,
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   422
    "site": soc.models.site.Site}
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   423
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   424
    # determine the type of the scope
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   425
    scope_type = scope_types.get(entity.prefix)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   426
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   427
    if not scope_type:
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   428
      # no matching scope type found
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   429
      raise AttributeError('No Matching Scope type found for %s' % entity.prefix)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   430
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   431
    # set the scope and update the entity
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   432
    entity.scope = scope_type.get_by_key_name(entity.scope_path)
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   433
    entity.put()
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   434
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   435
    # return the scope
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   436
    return entity.scope
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   437
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   438
class ProjectLogic(Logic):
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   439
  """Logic class for ProjectSurvey.
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   440
  """
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   441
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   442
  def __init__(self, model=ProjectSurvey,
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   443
               base_model=Survey, scope_logic=linkable_logic,
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   444
               record_logic=survey_record_logic.project_logic):
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   445
    """Defines the name, key_name and model for this entity.
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   446
    """
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   447
2459
accd8ba94b44 Calling the correct super in Project and Grading Survey Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2455
diff changeset
   448
    super(ProjectLogic, self).__init__(model=model, base_model=base_model,
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   449
                                       scope_logic=scope_logic,
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   450
                                       record_logic=record_logic)
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   451
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   452
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   453
class GradingProjectLogic(ProjectLogic):
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   454
  """Logic class for GradingProjectSurvey
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   455
  """
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   456
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   457
  def __init__(self, model=GradingProjectSurvey,
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   458
               base_model=ProjectSurvey, scope_logic=linkable_logic,
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   459
               record_logic=survey_record_logic.grading_logic):
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   460
    """Defines the name, key_name and model for this entity.
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   461
    """
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   462
2459
accd8ba94b44 Calling the correct super in Project and Grading Survey Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2455
diff changeset
   463
    super(GradingProjectLogic, self).__init__(model=model,
accd8ba94b44 Calling the correct super in Project and Grading Survey Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2455
diff changeset
   464
                                              base_model=base_model,
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   465
<<<<<<< local
2459
accd8ba94b44 Calling the correct super in Project and Grading Survey Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2455
diff changeset
   466
                                              scope_logic=scope_logic)
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   467
2455
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   468
class ResultsLogic(work.Logic):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   469
  """Logic methods for the Survey model
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   470
  """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   471
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   472
  def __init__(self, model=SurveyRecord,
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   473
               base_model=Work, scope_logic=linkable_logic):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   474
    """Defines the name, key_name and model for this entity.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   475
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   476
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   477
    super(ResultsLogic, self).__init__(model=model, base_model=base_model,
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   478
                                scope_logic=scope_logic)
2462
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   479
=======
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   480
                                              scope_logic=scope_logic,
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   481
                                              record_logic=record_logic)
2d5d2961f774 Added getRecordLogic method to SurveyLogic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2460
diff changeset
   482
>>>>>>> other
2455
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   483
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   484
  def getKeyValuesFromEntity(self, entity):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   485
    """See base.Logic.getKeyNameValues.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   486
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   487
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   488
    return [entity.prefix, entity.scope_path, entity.link_id]
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   489
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   490
  def getKeyValuesFromFields(self, fields):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   491
    """See base.Logic.getKeyValuesFromFields.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   492
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   493
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   494
    return [fields['prefix'], fields['scope_path'], fields['link_id']]
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   495
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   496
  def getKeyFieldNames(self):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   497
    """See base.Logic.getKeyFieldNames.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   498
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   499
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   500
    return ['prefix', 'scope_path', 'link_id']
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   501
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   502
  def isDeletable(self, entity):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   503
    """See base.Logic.isDeletable.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   504
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   505
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   506
    return not entity.home_for
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   507
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   508
  def _updateField(self, entity, entity_properties, name):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   509
    """Special logic for role. If state changes to active we flush the sidebar.
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   510
    """
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   511
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   512
    value = entity_properties[name]
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   513
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   514
    if (name == 'is_featured') and (entity.is_featured != value):
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   515
      sidebar.flush()
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   516
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   517
    home_for = entity.home_for
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   518
    if (name != 'home_for') and home_for:
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   519
      home.flush(home_for)
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   520
    return True
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   521
2442
dd1f94c3594c Start on adding ProjectSurvey and GradingProjectSurvey.
Daniel Diniz <ajaksu@gmail.com>
parents: 2439
diff changeset
   522
2431
800a020c9bcf Added logic for Survey and SurveyRecord.
James Levy <jamesalexanderlevy@gmail.com>
parents:
diff changeset
   523
logic = Logic()
2443
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   524
project_logic = ProjectLogic()
2e86dbd47907 Seperated Logic for ProjectSurvey and GradingProject surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2442
diff changeset
   525
grading_logic = GradingProjectLogic()
2455
a023b71ce125 fixed critical errors related to survey subclassing and renaming of deadline and opening properties, and surveys in sidebar are now marked as such and have a red color if untaken
james@jamess-macbook-air.local
parents: 2453
diff changeset
   526
results_logic = ResultsLogic()