app/soc/logic/models/student_proposal.py
author Lennard de Rijk <ljvderijk@gmail.com>
Tue, 03 Mar 2009 22:48:57 +0000
changeset 1610 6f675b690f92
parent 1422 052218c51035
child 1611 83e7b09ce959
permissions -rw-r--r--
Update the ranker belonging to the org of a student_proposal when the score changes. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1422
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2009 the Melange authors.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Student Proposal (Model) query functions.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
from soc.logic.models import base
1610
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    26
from soc.logic.models import rankerroot as ranker_logic
1422
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
from soc.logic.models import student as student_logic
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
import soc.models.linkable
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
import soc.models.student_proposal
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
class Logic(base.Logic):
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
  """Logic methods for the Student Proposal model.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
  """
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
  def __init__(self, model=soc.models.student_proposal.StudentProposal,
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
               base_model=soc.models.linkable.Linkable, scope_logic=student_logic):
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
    """Defines the name, key_name and model for this entity.
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
    """
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
    super(Logic, self).__init__(model=model, base_model=base_model,
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
                                scope_logic=scope_logic)
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
1610
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    45
  def _onCreate(self, entity):
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    46
    """Adds this proposal to the organization ranker entity
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    47
    """
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    48
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    49
    fields = {'link_id': self_model.DEF_RANKER_NAME,
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    50
              'scope': entity.org}
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    51
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    52
    ranker_root = ranker_logic.logic.getForFields(fields, unique=True)
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    53
    ranker = ranker_logic.logic.getRootFromEntity(ranker_root) 
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    54
    ranker.SetScore(entity.key().name(), [entity.score])
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    55
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    56
    super(Logic, self)._onCreate(entity)
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    57
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    58
  def _updateField(self, entity, entity_properties, name):
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    59
    """Update the ranker if the score changes
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    60
    """
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    61
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    62
    value = entity_properties[name]
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    63
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    64
    if name == 'score':
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    65
      fields = {'link_id': self_model.DEF_RANKER_NAME,
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    66
                'scope': entity.org}
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    67
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    68
      ranker_root = ranker_logic.logic.getForFields(fields, unique=True)
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    69
      ranker = ranker_logic.logic.getRootFromEntity(ranker_root)
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    70
      ranker.SetScore(entity.key().name(), [value])
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    71
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    72
    return super(Logic, self)._updateField(entity, entity_properties, name)
6f675b690f92 Update the ranker belonging to the org of a student_proposal when the score changes.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1422
diff changeset
    73
1422
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    74
052218c51035 Added student_proposal logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    75
logic = Logic()