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