app/soc/logic/models/organization.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sat, 18 Apr 2009 18:59:53 +0000
changeset 2221 1177ab97c2f0
parent 2160 3f9dd37d98a8
permissions -rw-r--r--
Add a silent option to updateOrCreateFromFields Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     2
#
1308
35b75ffcbb37 Partially reverted "Update the copyright notice for 2009."
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1307
diff changeset
     3
# Copyright 2008 the Melange authors.
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     4
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     8
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    10
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    16
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    17
"""Organization (Model) query functions.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    18
"""
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    19
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    20
__authors__ = [
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    21
  '"Sverre Rabbelier" <sverre@rabbelier.nl>',
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    22
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    23
  ]
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    24
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    25
1124
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    26
from soc.logic.models import base
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    27
from soc.logic.models import group
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    28
from soc.logic.models import org_app as org_app_logic
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    29
from soc.logic.models import program as program_logic
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    30
from soc.logic.models import request as request_logic
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
    31
from soc.logic.models.ranker_root import logic as ranker_root_logic
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
import soc.models.group
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
import soc.models.organization
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    35
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    36
class Logic(group.Logic):
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    37
  """Logic methods for the Organization model.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    38
  """
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    39
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    40
  def __init__(self, model=soc.models.organization.Organization,
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    41
               base_model=soc.models.group.Group, scope_logic=program_logic):
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    42
    """Defines the name, key_name and model for this entity.
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    43
    """
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    44
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    45
    super(Logic, self).__init__(model=model, base_model=base_model,
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    46
                                scope_logic=scope_logic)
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    47
1124
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    48
  # Restore base.Logic key field related methods
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    49
  getKeyValuesFromEntity = base.Logic.getKeyValuesFromEntity
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    50
  getKeyValuesFromFields = base.Logic.getKeyValuesFromFields
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    51
  getKeyFieldNames = base.Logic.getKeyFieldNames
d456f50af0d2 Reverting a change from r1732 for reasons stated in soc/logic/models/group.py.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1122
diff changeset
    52
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    53
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    54
  def _onCreate(self, entity):
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
    55
    """Invites the group admin and backup admin and creates a RankerRoot entity.
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    56
    """
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    57
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
    58
    from soc.models import student_proposal
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
    59
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
    60
    # create a new ranker
1623
8b70d6bb3f8f Renamed rankerroot to ranker_root and made some changes due to comments.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1609
diff changeset
    61
    ranker_root_logic.create(student_proposal.DEF_RANKER_NAME, entity,
1609
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
    62
        student_proposal.DEF_SCORE, 100)
cd285bc524f1 Create a new Ranker for each organization that is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1512
diff changeset
    63
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    64
    fields = {
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    65
        'link_id': entity.link_id,
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    66
        'scope_path': entity.scope_path
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    67
        }
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    68
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    69
    # Find their application
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    70
    application = org_app_logic.logic.getFromKeyFields(fields)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    71
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    72
    if application:
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    73
      # only if there is an application send out the invites
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    74
      properties = {
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    75
          'scope': entity,
2160
3f9dd37d98a8 Use key().id_or_name() instead of key().name()
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1623
diff changeset
    76
          'scope_path': entity.key().id_or_name(),
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    77
          'role': 'org_admin',
1171
26998a171c49 Style fixes in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1154
diff changeset
    78
          'role_verbose': 'Organization Admin',
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    79
          'status': 'group_accepted',
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    80
          }
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    81
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    82
      for admin in [application.applicant, application.backup_admin]:
1292
cf8b099bd787 Fixed a bug in club and org logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1171
diff changeset
    83
        if not admin:
cf8b099bd787 Fixed a bug in club and org logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1171
diff changeset
    84
          continue
cf8b099bd787 Fixed a bug in club and org logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1171
diff changeset
    85
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    86
        properties['link_id'] = admin.link_id
1512
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
    87
        key_name = request_logic.logic.getKeyNameFromFields(properties)
97c4a718d6f4 Remove updateOrCreateFromFields and it's uses
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1511
diff changeset
    88
        request_logic.logic.updateOrCreateFromKeyName(properties, key_name)
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    89
1511
3342ce7a495c Fix some whitespace damadge and a style fix
Sverre Rabbelier <srabbelier@gmail.com>
parents: 1308
diff changeset
    90
      # set the application to completed
1171
26998a171c49 Style fixes in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1154
diff changeset
    91
      fields = {'status': 'completed'}
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    92
      org_app_logic.logic.updateEntityProperties(application, fields)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    93
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    94
    super(Logic, self)._onCreate(entity)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    95
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    96
logic = Logic()