app/soc/logic/models/grading_record.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 00:36:49 +0200
changeset 2898 ac5f77cd6046
parent 2794 dd841c3160d8
permissions -rw-r--r--
Fix 500 when saving /site/edit without email When saving /site/edit with no no_reply_email set, a 500 error page would be returned due to an empty value being passed as value to the datastore (which is not allowed for email fields).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""GradingRecord (Model) query functions.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    25
from google.appengine.ext import db
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    26
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic.models import base
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    28
from soc.logic.models.survey_record import grading_logic
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    29
from soc.logic.models.survey_record import project_logic
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
import soc.models.grading_record
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
class Logic(base.Logic):
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
  """Logic methods for the GradingRecord model.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
  """
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
2584
10858e5d5712 Fixed GradingRecord and GradingSurveyRecord Logic to load the correct Model.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2577
diff changeset
    38
  def __init__(self, model=soc.models.grading_record.GradingRecord,
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
               base_model=None, scope_logic=None):
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
    """Defines the name, key_name and model for this entity.
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
    """
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
    super(Logic, self).__init__(model=model, base_model=base_model,
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
                                scope_logic=scope_logic, id_based=True)
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    46
  def updateOrCreateRecordsFor(self, survey_group, project_entities):
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    47
    """Updates or creates a GradingRecord in a batch.
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    48
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    49
    Args:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    50
      survey_group: GradingSurveyGroup entity
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    51
      project_entities: list of project_entities which to process
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    52
    """
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    53
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    54
    records_to_store = []
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    55
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    56
    query_fields = {'grading_survey_group': survey_group}
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    57
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    58
    for project_entity in project_entities:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    59
      # set a new project to query for
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    60
      query_fields['project'] = project_entity
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    61
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    62
      # try to retrieve an existing record
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    63
      record_entity = self.getForFields(query_fields, unique=True)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    64
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    65
      # retrieve the fields that should be set
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    66
      record_fields = self.getFieldsForGradingRecord(project_entity,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    67
                                                     survey_group,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    68
                                                     record_entity)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    69
2794
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    70
      if not record_entity and project_entity.status in ['failed', 'invalid'] \
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    71
          and not record_fields['mentor_record'] \
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    72
          and not record_fields['student_record']:
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    73
        # Don't create a new GradingRecord for an already failed project which
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    74
        # has no records attached. Because it does not matter.
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    75
        continue
dd841c3160d8 Only create GradingRecords for succeful projects or failed projects with Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2660
diff changeset
    76
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    77
      if record_entity:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    78
        # update existing GradingRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    79
        for key,value in record_fields.iteritems():
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    80
          setattr(record_entity, key, value)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    81
      else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    82
        # create a new GradingRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    83
        record_entity = self.getModel()(**record_fields)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    84
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    85
      # prepare the new/updated record for storage
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    86
      records_to_store.append(record_entity)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    87
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    88
    # batch put and return the entities
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    89
    return db.put(records_to_store)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    90
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    91
  def getFieldsForGradingRecord(self, project, survey_group,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    92
                                record_entity=None):
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    93
    """Returns the fields for a GradingRecord.
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    94
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    95
    See GradingRecord model for description of the grade_decision value.
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    96
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    97
    Args:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    98
      project: Project entity
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    99
      survey_group: a GradingSurveyGroup entity
2660
e2654d53a643 Another batch of style fixes for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2626
diff changeset
   100
      record_entity: an optional GradingRecord entity
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   101
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   102
    Returns:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   103
      Dict containing the fields that should be set on a GradingRecord for this
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   104
      GradingSurveyGroup and StudentProject
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   105
    """
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   106
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   107
    # retrieve the two Surveys, student_survey might be None
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   108
    grading_survey = survey_group.grading_survey
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   109
    student_survey = survey_group.student_survey
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   110
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   111
    # retrieve a GradingSurveyRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   112
    survey_record_fields = {'project': project,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   113
                            'survey': grading_survey}
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   114
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   115
    grading_survey_record = grading_logic.getForFields(survey_record_fields,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   116
                                                       unique=True)
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   117
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   118
    if student_survey:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   119
      # retrieve ProjectSurveyRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   120
      survey_record_fields['survey'] = student_survey
2622
f37d7d564f88 Style fixes in GradingRecord Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2617
diff changeset
   121
      project_survey_record = project_logic.getForFields(survey_record_fields,
f37d7d564f88 Style fixes in GradingRecord Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2617
diff changeset
   122
                                                         unique=True)
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   123
    else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   124
      project_survey_record = None
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   125
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   126
    # set the necessary fields
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   127
    fields = {'grading_survey_group': survey_group,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   128
              'project': project,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   129
              'mentor_record': grading_survey_record,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   130
              'student_record': project_survey_record}
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   131
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   132
    if not record_entity or not record_entity.locked:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   133
      # find grading decision for new or unlocked records
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   134
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   135
      if not grading_survey_record:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   136
        # no record found, return undecided
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   137
        grade_decision = 'undecided'
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   138
      elif not student_survey or project_survey_record:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   139
        # if the grade is True then pass else fail
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   140
        grade_decision = 'pass' if grading_survey_record.grade else 'fail'
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   141
      else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   142
        # no ProjectSurveyRecord on file while there is a survey to be taken
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   143
        grade_decision = 'fail'
2626
17dd9ada27cb Fixed bug where grade_decision would not be properly set in 2 out of 4 cases.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2622
diff changeset
   144
17dd9ada27cb Fixed bug where grade_decision would not be properly set in 2 out of 4 cases.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2622
diff changeset
   145
      fields['grade_decision'] = grade_decision
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   146
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   147
    # return the fields that should be set for a GradingRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   148
    return fields
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   149
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   150
logic = Logic()