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 def completeRequestForRole(role_entity, role_name): |
|
26 """Marks the request that leads to the given role_entity as completed. |
|
27 |
|
28 Args: |
|
29 role_entity: A datastore entity that is either a role or a subclass |
|
30 of the role model |
|
31 role_name: The name in the request that is used to describe the |
|
32 type of the role_entity |
|
33 |
|
34 """ |
|
35 |
|
36 from soc.logic.models.request import logic as request_logic |
|
37 |
|
38 # create the query properties for the specific role |
|
39 properties = {'scope_path' : role_entity.scope_path, |
|
40 'link_id': role_entity.link_id, |
|
41 'role': role_name} |
|
42 |
|
43 # get the request that complies with properties |
|
44 request_entity = request_logic.getForFields(properties, unique=True) |
|
45 |
|
46 # mark the request completed, if there is any |
|
47 if request_entity: |
|
48 request_logic.updateEntityProperties( |
|
49 request_entity, {'status': 'completed'}) |
|