app/soc/logic/helper/request.py
author Lennard de Rijk <ljvderijk@gmail.com>
Sat, 24 Oct 2009 15:14:11 -0700
changeset 3036 c703f3802841
parent 2677 7df4d0fcbb80
permissions -rw-r--r--
Use skipFields method in the expando base logic.
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
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
    26
  """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
    27
  
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    28
  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
    29
    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
    30
      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
    31
    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
    32
      type of the role_entity
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    33
   
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
2677
7df4d0fcbb80 Use proper in-line import in Request helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1308
diff changeset
    36
  from soc.logic.models.request import logic as request_logic
916
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
  # create the query properties for the specific role
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    39
  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
    40
      '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
    41
      'role': role_name}
916
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    42
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    43
  # get the request that complies with properties
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    44
  request_entity = request_logic.getForFields(properties, unique=True)
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    45
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    46
  # mark the request completed, if there is any
f18c0a56da8b Redid removeRequestForRole to completeRequestForRole.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 715
diff changeset
    47
  if request_entity:
2677
7df4d0fcbb80 Use proper in-line import in Request helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1308
diff changeset
    48
    request_logic.updateEntityProperties(
7df4d0fcbb80 Use proper in-line import in Request helper.
Lennard de Rijk <ljvderijk@gmail.com>
parents: 1308
diff changeset
    49
        request_entity, {'status': 'completed'})