app/soc/logic/key_name.py
author Pawel Solyga <Pawel.Solyga@gmail.com>
Fri, 07 Nov 2008 22:24:01 +0000
changeset 448 075360be6743
parent 445 31927f21970d
child 499 d22e4fe8e64b
permissions -rw-r--r--
Fix not working former_ids. Add support for "Invalid accounts". Now when id from former_ids tries to create a profile "This account is invalid." error message is displayed. Compare emails in lower cases to prevent changing User email to the same email with different character casing (needs some more testing). Patch by: Pawel Solyga
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
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 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
    35
  """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
    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
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
    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
    41
      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
    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:
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
    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
    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
  
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
  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
    51
    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
    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
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    61
def nameSiteSettings(partial_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
    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
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    71
  if not link_name:
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    72
    raise Error('"link_name" must be non-False: "%s"' % link_name)
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    73
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    74
  return 'SiteSettings:%s:%s' % (partial_path, link_name)
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
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    77
def nameHomeSettings(partial_path, link_name):
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
445
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    87
  if not link_name:
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    88
    raise Error('"link_name" must be non-False: "%s"' % link_name)
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    89
31927f21970d Major site restructuring, also deleting of many unused or obsolete documents
Sverre Rabbelier <srabbelier@gmail.com>
parents: 404
diff changeset
    90
  return 'HomeSettings:%s:%s' % (partial_path, link_name)
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
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   105
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
   106
  """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
   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:
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
    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
   110
  """
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
  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
   112
    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
   113
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   114
  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
   115
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   116
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   117
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
   118
  """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
   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:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   121
    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
   122
    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
   123
    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
   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:
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
    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
   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
  """
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
   129
  path = path_link_name.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
   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
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   137
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
   138
  """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
   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:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   141
    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
   142
    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
   143
    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
   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 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
   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
  """
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
   149
  path = path_link_name.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
   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
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   157
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
   158
  """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
   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:
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   161
    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
   162
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   163
  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
   164
    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
   165
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   166
  return 'Group/Club:%s' % link_name
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
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   169
def nameWork(link_name):
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   170
  """Placeholder for work namer"""
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   171
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   172
  if not link_name:
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   173
    raise Error('"link_name" must be non-False: "%s"' % link_name)
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   174
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   175
  return 'Work:%s' % link_name
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   176
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   177
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   178
def nameHost(sponsor_ln, user_ln):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   179
  """Placeholder for host namer"""
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   180
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   181
  if not sponsor_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   182
    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
   183
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   184
  if not user_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   185
    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
   186
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   187
  return 'Host:%s:%s' % (sponsor_ln, user_ln)