app/soc/logic/helper/request.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Sat, 24 Jan 2009 10:57:53 +0000
changeset 946 db4134853d64
parent 945 54ee340ac14d
child 955 b00251a6b9f9
permissions -rw-r--r--
Add missing dots in soc.views.helper.redirects module function docstrings. Patch by: Pawel Solyga Review by: to-be-reviewed
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
#
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
     3
# Copyright 2008 the Melange authors.
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:
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    32
    role_entity : A datastore entity that is either a role or a subclass of the role model
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    33
    role_name : The name in the request that is used to describe the type of the role_entity
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    34
   
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    35
  """
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
  # 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
    38
  request_logic = model_logic.request.logic
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    39
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    40
  # create the query properties for the specific role
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    41
  properties = {'scope_path' : role_entity.scope_path,
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    42
      'link_id' : role_entity.link_id,
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    43
      'role' : role_name}
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    44
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    45
  # get the request that complies with properties
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    46
  request_entity = request_logic.getForFields(properties, unique=True)
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    47
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    48
  # mark the request completed, if there is any
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    49
  if request_entity:
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    50
    request_logic.updateModelProperties(request_entity,
928
df051fc9d7a1 Replaced the boolean properties in soc/models/request.py with a state property.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 916
diff changeset
    51
        {'state' : 'completed'})