app/soc/logic/key_name.py
author Todd Larsen <tlarsen@google.com>
Thu, 20 Nov 2008 18:50:30 +0000
changeset 512 aae25d2b4464
parent 499 d22e4fe8e64b
child 522 c06a009005fc
permissions -rw-r--r--
Rename link_name to link_id everywhere, regardless of case (so LINK_NAME becomes LINK_ID, "link name" becomes "link id", etc.). Also, rename LINKNAME to LINK_ID. Patch by: Todd Larsen
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
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
    26
from soc.logic import path_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
    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
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    34
def nameDocument(partial_path, link_id=None):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    35
  """Returns a Document key name constructed from a path and link ID.
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
    36
    
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
  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
    38
    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
    39
      identifies it
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    40
    link_id: optional link ID to append to path (when omitted,
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    41
      partial_path is actually the entire path, with the link_id already
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
    42
      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
    43
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
  Raises:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    45
    Error if partial_path and link_id produce a "False" path (None,
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
    46
    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
    47
  """
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
  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
    49
  
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    50
  if link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    51
    path.append(link_id)
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
    52
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
    53
  path = path_link_name.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
    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 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
    56
    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
    57
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    58
  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
    59
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    60
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    61
def nameSiteSettings(partial_path, link_id):
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
    62
  """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
    63
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    64
  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
    65
    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
    66
  """
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    67
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    68
  if not partial_path:
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    69
    raise Error('"partial_path" must be non-False: "%s"' % partial_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
    70
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    71
  if not link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    72
    raise Error('"link_id" must be non-False: "%s"' % link_id)
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    73
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    74
  return 'SiteSettings:%s:%s' % (partial_path, link_id)
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    75
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    76
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    77
def nameHomeSettings(partial_path, link_id):
334
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    78
  """Returns a HomeSettings key name constructed from a supplied path.
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    79
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    80
  Raises:
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    81
    Error if path is "False" (None, empty string, etc.)
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    82
  """
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    83
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    84
  if not partial_path:
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    85
    raise Error('"partial_path" must be non-False: "%s"' % partial_path)
334
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    86
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    87
  if not link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    88
    raise Error('"link_id" must be non-False: "%s"' % link_id)
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    89
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
    90
  return 'HomeSettings:%s:%s' % (partial_path, link_id)
334
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    91
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    92
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    93
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
    94
  """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
    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
  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
    97
    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
    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
  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
   100
    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
   101
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   102
  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
   103
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   104
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   105
def nameSponsor(link_id):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   106
  """Returns a Sponsor key name constructed from a supplied link ID.
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
   107
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
  Raises:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   109
    Error if link_id is "False" (None, empty string, etc.)
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
   110
  """
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   111
  if not link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   112
    raise Error('"link_id" must be non-False: "%s"' % link_id)
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
   113
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   114
  return 'Group/Sponsor:%s' % link_id
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   115
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   116
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   117
def nameSchool(sponsor_ln, program_ln, link_id):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   118
  """Returns a School key name constructed from link IDs.
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
   119
     
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   120
  Args:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   121
    sponsor_ln: Sponsor link ID
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   122
    program_ln: Program link ID
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   123
    link_id: School link ID
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
   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
  Raises:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   126
    Error if sponsor_ln, program_ln, and link_id combine to produce
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
   127
    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
   128
  """
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   129
  path = path_link_name.combinePath([[sponsor_ln, program_ln], link_id])
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
   130
  
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
  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
   132
    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
   133
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   134
  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
   135
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   136
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   137
def nameOrganization(sponsor_ln, program_ln, link_id):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   138
  """Returns a Organization key name constructed from link IDs.
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
   139
     
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   140
  Args:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   141
    sponsor_ln: Sponsor link ID
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   142
    program_ln: Program link ID
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   143
    link_id: Organization link ID
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
   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:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   146
    Error if sponsor_ln, program_ln, and link_id combine to produce
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
   147
    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
   148
  """
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   149
  path = path_link_name.combinePath([[sponsor_ln, program_ln], link_id])
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
   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
  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
   152
    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
   153
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   154
  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
   155
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   156
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   157
def nameClub(link_id):
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   158
  """Returns a Club key name constructed from a supplied link ID.
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
   159
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   160
  Raises:
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   161
    Error if link_id is "False" (None, empty string, etc.)
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
   162
  """
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   163
  if not link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   164
    raise Error('"link_id" must be non-False: "%s"' % link_id)
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
   165
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   166
  return 'Group/Club:%s' % link_id
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   167
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   168
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   169
def nameWork(link_id):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 445
diff changeset
   170
  """Placeholder for work namer.
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 445
diff changeset
   171
  """
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   172
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   173
  if not link_id:
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   174
    raise Error('"link_id" must be non-False: "%s"' % link_id)
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   175
512
aae25d2b4464 Rename link_name to link_id everywhere, regardless of case (so LINK_NAME
Todd Larsen <tlarsen@google.com>
parents: 499
diff changeset
   176
  return 'Work:%s' % link_id
299
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   177
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   178
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   179
def nameHost(sponsor_ln, user_ln):
499
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 445
diff changeset
   180
  """Placeholder for host namer.
d22e4fe8e64b Fix missing dots in doc strings and some other doc string corrections.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 445
diff changeset
   181
  """
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   182
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   183
  if not sponsor_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   184
    raise Error('"sponsor_ln" must be non-False: "%s"' % sponsor_ln)
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   185
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   186
  if not user_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   187
    raise Error('"user_ln" must be non-False: "%s"' % user_ln)
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   188
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   189
  return 'Host:%s:%s' % (sponsor_ln, user_ln)