app/soc/logic/key_name.py
author Todd Larsen <tlarsen@google.com>
Wed, 01 Oct 2008 20:52:39 +0000
changeset 251 8f23804302d0
parent 222 63e5f42e2e83
child 263 9b39d93b677f
permissions -rw-r--r--
Move path and link_name related functions and regex patterns to a new soc/logic/path_linkname.py module, and fix all dependencies. path/link_name functionality is becoming the generic way to identify entities in the Datastore in a URL-compatible way.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     1
#!/usr/bin/python2.5
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     2
#
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     3
# Copyright 2008 the Melange authors.
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     4
#
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     5
# Licensed under the Apache License, Version 2.0 (the "License");
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     6
# you may not use this file except in compliance with the License.
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     7
# You may obtain a copy of the License at
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     8
#
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
     9
#   http://www.apache.org/licenses/LICENSE-2.0
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    10
#
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    11
# Unless required by applicable law or agreed to in writing, software
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    12
# distributed under the License is distributed on an "AS IS" BASIS,
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    14
# See the License for the specific language governing permissions and
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    15
# limitations under the License.
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    16
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    17
"""Functions for composing Model entity key names.
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    18
"""
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    19
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    20
__authors__ = [
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    21
  '"Todd Larsen" <tlarsen@google.com>',
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
    22
  '"Pawel Solyga" <pawel.solyga@gmail.com>',
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    23
  ]
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    24
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    25
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 222
diff changeset
    26
from soc.logic import path_linkname
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    27
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    28
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    29
class Error(Exception):
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    30
  """Base class for all exceptions raised by this module."""
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    31
  pass
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    32
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    33
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    34
def getFullClassName(cls):
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    35
  """Returns fully-qualified module.class name string.""" 
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    36
  return '%s.%s' % (cls.__module__, cls.__name__) 
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    37
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    38
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    39
def nameDocument(partial_path, link_name=None):
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    40
  """Returns a Document key name constructed from a path and link name.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    41
    
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    42
  Args:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    43
    partial_path: the first portion of the path to the Document that uniquely
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    44
      identifies it
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    45
    link_name: optional link name to append to path (when omitted,
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    46
      partial_path is actually the entire path, with the link_name already
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    47
      appended)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    48
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    49
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    50
    Error if partial_path and link_Name produce a "False" path (None,
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    51
    empty string, etc.)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    52
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    53
  path = [partial_path]
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    54
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    55
  if link_name:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    56
    path.append(link_name)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    57
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 222
diff changeset
    58
  path = path_linkname.combinePath(path)
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    59
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    60
  if not path:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    61
    raise Error('"path" must be non-False: "%s"' % path)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    62
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    63
  return 'Document:%s' % path
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    64
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    65
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    66
def nameSiteSettings(path):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    67
  """Returns a SiteSettings key name constructed from a supplied path.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    68
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    69
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    70
    Error if path is "False" (None, empty string, etc.)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    71
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    72
  if not path:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    73
    raise Error('"path" must be non-False: "%s"' % path)
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 202
diff changeset
    74
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    75
  return 'SiteSettings:%s' % path
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    77
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    78
def nameUser(email):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    79
  """Returns a User key name constructed from a supplied email address.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    80
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    81
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    82
    Error if email is "False" (None, empty string, etc.)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    83
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    84
  if not email:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    85
    raise Error('"email" must be non-False: "%s"' % email)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    86
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    87
  return 'User:%s' % email
206
832335761384 Make use of PolyModel for Works, Documents, etc. Add some (but not all) of
Todd Larsen <tlarsen@google.com>
parents: 202
diff changeset
    88
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
    89
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
    90
def nameSponsor(link_name):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    91
  """Returns a Sponsor key name constructed from a supplied link name.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    92
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    93
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    94
    Error if link_name is "False" (None, empty string, etc.)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    95
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    96
  if not link_name:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    97
    raise Error('"link_name" must be non-False: "%s"' % link_name)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    98
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    99
  return 'Group/Sponsor:%s' % link_name
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   100
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   101
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   102
def nameSchool(sponsor_ln, program_ln, link_name):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   103
  """Returns a School key name constructed from link names.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   104
     
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   105
  Args:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   106
    sponsor_ln: Sponsor link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   107
    program_ln: Program link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   108
    link_name: School link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   109
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   110
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   111
    Error if sponsor_ln, program_ln, and link_Name combine to produce
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   112
    a "False" path (None, empty string, etc.)
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   113
  """
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 222
diff changeset
   114
  path = path_linkname.combinePath([[sponsor_ln, program_ln], link_name])
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   115
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   116
  if not path:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   117
    raise Error('"path" must be non-False: "%s"' % path)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   118
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   119
  return 'Group/School:%s' % path
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   120
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   121
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   122
def nameOrganization(sponsor_ln, program_ln, link_name):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   123
  """Returns a Organization key name constructed from link names.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   124
     
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   125
  Args:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   126
    sponsor_ln: Sponsor link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   127
    program_ln: Program link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   128
    link_name: Organization link name
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   129
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   130
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   131
    Error if sponsor_ln, program_ln, and link_Name combine to produce
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   132
    a "False" path (None, empty string, etc.)
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   133
  """
251
8f23804302d0 Move path and link_name related functions and regex patterns to a new
Todd Larsen <tlarsen@google.com>
parents: 222
diff changeset
   134
  path = path_linkname.combinePath([[sponsor_ln, program_ln], link_name])
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   135
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   136
  if not path:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   137
    raise Error('"path" must be non-False: "%s"' % path)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   138
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   139
  return 'Group/Organization:%s' % path 
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   140
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   141
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   142
def nameClub(link_name):
222
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   143
  """Returns a Club key name constructed from a supplied link name.
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   144
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   145
  Raises:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   146
    Error if link_name is "False" (None, empty string, etc.)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   147
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   148
  if not link_name:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   149
    raise Error('"link_name" must be non-False: "%s"' % link_name)
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   150
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   151
  return 'Group/Club:%s' % link_name