app/soc/logic/models/grading_record.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Mon, 24 Aug 2009 04:31:23 +0530
changeset 2787 8408741aee63
parent 2660 e2654d53a643
child 2794 dd841c3160d8
permissions -rw-r--r--
Reverting last 4 patches containing GHOP related views. As Lennard suggested all the model patches should come first followed by the logic and views patches, to make sure nothing committed breaks the existing code after thorough review.
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
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    70
      if record_entity:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    71
        # update existing GradingRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    72
        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
    73
          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
    74
      else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    75
        # 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
    76
        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
    77
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    78
      # 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
    79
      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
    80
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    81
    # 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
    82
    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
    83
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    84
  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
    85
                                record_entity=None):
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    86
    """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
    87
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    88
    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
    89
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    90
    Args:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    91
      project: Project entity
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    92
      survey_group: a GradingSurveyGroup entity
2660
e2654d53a643 Another batch of style fixes for Surveys.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2626
diff changeset
    93
      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
    94
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    95
    Returns:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    96
      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
    97
      GradingSurveyGroup and StudentProject
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    98
    """
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
    99
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   100
    # 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
   101
    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
   102
    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
   103
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   104
    # retrieve a GradingSurveyRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   105
    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
   106
                            'survey': grading_survey}
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   107
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   108
    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
   109
                                                       unique=True)
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
    if student_survey:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   112
      # retrieve ProjectSurveyRecord
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   113
      survey_record_fields['survey'] = student_survey
2622
f37d7d564f88 Style fixes in GradingRecord Logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2617
diff changeset
   114
      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
   115
                                                         unique=True)
2617
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   116
    else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   117
      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
   118
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   119
    # 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
   120
    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
   121
              'project': project,
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   122
              '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
   123
              '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
   124
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   125
    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
   126
      # 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
   127
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   128
      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
   129
        # 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
   130
        grade_decision = 'undecided'
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   131
      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
   132
        # 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
   133
        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
   134
      else:
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   135
        # 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
   136
        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
   137
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
   138
      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
   139
274efd5c769d Added methods to GradingRecord Logic to facilitate creating/updating them.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 2584
diff changeset
   140
    # 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
   141
    return fields
2577
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   142
8ff2f23922b9 Added logic for GradingRecord and GradingSurveyGroup.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
   143
logic = Logic()