app/soc/logic/models/organization.py
author Lennard de Rijk <ljvderijk@gmail.com>
Thu, 12 Feb 2009 23:35:44 +0000
changeset 1292 cf8b099bd787
parent 1171 26998a171c49
child 1307 091a21cf3627
permissions -rw-r--r--
Fixed a bug in club and org logic. This bug would give an error when no backup was set. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
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
#
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
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
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    31
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    32
import soc.models.group
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    33
import soc.models.organization
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    34
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):
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    55
    """Invites the group admin and backup admin.
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
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    58
    fields = {
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    59
        '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
    60
        '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
    61
        }
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    62
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    63
    # Find their application
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    64
    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
    65
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    66
    if application:
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    67
      # 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
    68
      properties = {
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    69
          'scope': entity,
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    70
          'scope_path': entity.key().name(),
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    71
          'role': 'org_admin',
1171
26998a171c49 Style fixes in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1154
diff changeset
    72
          '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
    73
          'status': 'group_accepted',
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    74
          }
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    75
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    76
      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
    77
        if not admin:
cf8b099bd787 Fixed a bug in club and org logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1171
diff changeset
    78
          continue
cf8b099bd787 Fixed a bug in club and org logic.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1171
diff changeset
    79
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    80
        properties['link_id'] = admin.link_id
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    81
        key_fields = request_logic.logic.getKeyFieldsFromFields(properties)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    82
        request_logic.logic.updateOrCreateFromFields(properties, key_fields)
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    83
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    84
      # set the application to completed  
1171
26998a171c49 Style fixes in soc.logic.models modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1154
diff changeset
    85
      fields = {'status': 'completed'}
1154
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    86
      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
    87
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    88
    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
    89
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    90
logic = Logic()