app/soc/logic/helper/request.py
author Sverre Rabbelier <srabbelier@gmail.com>
Thu, 19 Feb 2009 22:51:24 +0000
changeset 1407 423425ac79f5
parent 1308 35b75ffcbb37
child 2677 7df4d0fcbb80
permissions -rw-r--r--
Fixed copy/paste fail Patch by: Sverre Rabbelier
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     1
#!/usr/bin/python2.5
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
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.
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     4
#
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     6
# you may not use this file except in compliance with the License.
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     7
# You may obtain a copy of the License at
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     8
#
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    10
#
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    14
# See the License for the specific language governing permissions and
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    15
# limitations under the License.
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    16
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    17
"""Functions that are useful when dealing with requests.
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    18
"""
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    19
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    20
__authors__ = [
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    21
  '"Lennard de Rijk" <ljvderijk@gmail.com>',
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    22
  ]
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    23
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    24
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    25
import soc.logic.models as model_logic
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    26
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    27
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    28
def completeRequestForRole(role_entity, role_name):
945
54ee340ac14d Little change in soc.logic.hlper.request module completeRequestForRole function docstring.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 928
diff changeset
    29
  """Marks the request that leads to the given role_entity as completed.
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    30
  
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    31
  Args:
955
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    32
    role_entity: A datastore entity that is either a role or a subclass 
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    33
      of the role model
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    34
    role_name: The name in the request that is used to describe the 
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    35
      type of the role_entity
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    36
   
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    37
  """
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    38
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    39
  # get the request logic so we can query the datastore
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    40
  request_logic = model_logic.request.logic
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    41
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    42
  # create the query properties for the specific role
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    43
  properties = {'scope_path' : role_entity.scope_path,
955
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    44
      'link_id': role_entity.link_id,
b00251a6b9f9 Remove extra whitespaces and fix too long lines in soc.logic.helper.request module.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 945
diff changeset
    45
      'role': role_name}
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    46
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    47
  # get the request that complies with properties
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    48
  request_entity = request_logic.getForFields(properties, unique=True)
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    49
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    50
  # mark the request completed, if there is any
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    51
  if request_entity:
986
e9611a2288ca Rename ModelProperties to EntityProperties
Sverre Rabbelier <srabbelier@gmail.com>
parents: 955
diff changeset
    52
    request_logic.updateEntityProperties(request_entity,
1085
0afbdd0905ef Renamed state to status where appropriate.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 986
diff changeset
    53
        {'status': 'completed'})