app/soc/logic/helper/request.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 22 Jan 2009 16:03:17 +0000
changeset 900 0b416bb14970
parent 715 51703b18ef2e
child 916 f18c0a56da8b
permissions -rw-r--r--
Extend dicts.merge to be (optionally) recursive This is very useful when dealing for views that expect to be inhereted from but wish to provide default values. Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
715
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     2
#
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     4
#
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     8
#
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    10
#
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    15
# limitations under the License.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    16
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    17
"""Functions that are useful when dealing with requests.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    18
"""
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    19
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    20
__authors__ = [
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    22
  ]
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    23
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    24
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    25
import soc.logic.models as model_logic
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    26
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    27
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    28
def removeRequestForRole(role_entity):
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    29
  """Removes the request that leads to the creation of the given entity.
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    30
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    31
  Args:
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    32
    role_entity : A datastore entity that is either a role or a subclass of the role model
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    33
   
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    34
  """
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    35
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    36
  # get the type of the role entity using the classname
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    37
  role_type = role_entity.__class__.__name__
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    38
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    39
  # get the request logic so we can query the datastore
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    40
  request_logic = model_logic.request.logic
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    41
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    42
  # create the query properties for the specific role
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    43
  properties = {'scope' : role_entity.scope,
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    44
      'link_id' : role_entity.link_id,
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    45
      'role' : role_type.lower() }
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    46
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    47
  # get the request that complies with properties
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    48
  request_entity = request_logic.getForFields(properties, unique=True)
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    49
  
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    50
  # delete the request from the datastore, if there is any
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    51
  if request_entity:
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    52
    request_logic.delete(request_entity)
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    53
    
51703b18ef2e Adds the removal of requests from the datastore when a new role entity is created.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff changeset
    54