app/soc/logic/models/organization.py
author Sverre Rabbelier <srabbelier@gmail.com>
Sun, 01 Feb 2009 22:48:48 +0000
changeset 1166 558bd62ee9d4
parent 1154 77276e2c46f7
child 1171 26998a171c49
permissions -rw-r--r--
Fix get args construction when there are multiple lists on the page It is now possible to go back and forward through the liast, and specify the limit (both offset and limit can be done per list). The JS driving the list boxes is buggy, if visiting an url like: http://localhost:8080/notification/list?limit_0=10 And then change the limit in the second checkbox, it directs to: http://localhost:8080/notification/list?limit_1=25 Whereas it should redirect to: http://localhost:8080/notification/list?limit_0=10&limit_1=25 The logic _does_ work properly when the limit of the changed list is already present in the url. 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
#
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',
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    72
          'role_verbose' : 'Organization Admin',
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]:
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    77
        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
    78
        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
    79
        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
    80
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    81
      # set the application to completed  
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    82
      fields = {'status' : 'completed'}
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    83
      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
    84
77276e2c46f7 Implement the last step in the org application process.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1124
diff changeset
    85
    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
    86
682
187f4d95fedb Added organizations
Sverre Rabbelier <srabbelier@gmail.com>
parents:
diff changeset
    87
logic = Logic()