app/soc/logic/key_name.py
author Sverre Rabbelier <srabbelier@gmail.com>
Mon, 03 Nov 2008 19:47:02 +0000
changeset 439 0658c3c9a9dc
parent 404 44223e50e1fc
child 445 31927f21970d
permissions -rw-r--r--
Minor fixes needed for generic key name We no longer try to retreive an entity when there are unset fields. This sort of makes 'getIfFields' obsolete, since we check if fields now anyway. This is needed because getKeyFieldsFromDict expects the fields to be set. Also a minor fix in a Django template so that the generic 'edit' page has a working delete button again.
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
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    61
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
    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
  """
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
  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
    68
    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
    69
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 334
diff changeset
    70
  return nameHomeSettings(path, entity_type='SiteSettings')
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    71
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    72
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 334
diff changeset
    73
def nameHomeSettings(path, entity_type='HomeSettings'):
334
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    74
  """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
    75
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    76
  Raises:
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    77
    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
    78
  """
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    79
  if not path:
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    80
    raise Error('"path" must be non-False: "%s"' % path)
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    81
377
d94ec6f104cc Refactor various site views into more generic locations, in preparation for
Todd Larsen <tlarsen@google.com>
parents: 334
diff changeset
    82
  return '%s:%s' % (entity_type, path)
334
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    83
0d0e96b12551 Add nameHomeSettings function to key_name module. Add HomeSettings logic.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 299
diff changeset
    84
202
b8b4a83788d4 A key_name controller module to collect all of the name...() functions that
Todd Larsen <tlarsen@google.com>
parents:
diff changeset
    85
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
    86
  """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
    87
  
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
    88
  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
    89
    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
    90
  """
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
  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
    92
    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
    93
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
  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
    95
213
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
    96
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
    97
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
    98
  """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
    99
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
  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
   101
    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
   102
  """
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
  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
   104
    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
   105
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
  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
   107
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   108
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   109
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
   110
  """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
   111
     
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
  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
   113
    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
   114
    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
   115
    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
   116
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
  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
   118
    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
   119
    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
   120
  """
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
   121
  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
   122
  
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
  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
   124
    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
   125
  
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
  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
   127
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   128
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   129
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
   130
  """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
   131
     
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
  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
   133
    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
   134
    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
   135
    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
   136
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
  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
   138
    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
   139
    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
   140
  """
298
c76a366c7ab4 Replace almost all occurences of linkname with link_name
Sverre Rabbelier <srabbelier@gmail.com>
parents: 263
diff changeset
   141
  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
   142
  
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
  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
   144
    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
   145
  
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
  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
   147
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   148
75a8cc0200ad Add key naming function for Sponsor, School, Organization, Club key_names.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 206
diff changeset
   149
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
   150
  """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
   151
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
  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
   153
    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
   154
  """
63e5f42e2e83 Add lots of new functions to key_name.py, including path/link_name processing.
Todd Larsen <tlarsen@google.com>
parents: 213
diff changeset
   155
  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
   156
    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
   157
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
  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
   159
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   160
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   161
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
   162
  """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
   163
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   164
  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
   165
    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
   166
a1cc853a56e5 Refactor nearly all the soc.logic code to use the Base class
Sverre Rabbelier <srabbelier@gmail.com>
parents: 298
diff changeset
   167
  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
   168
404
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   169
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   170
def nameHost(sponsor_ln, user_ln):
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   171
  """Placeholder for host namer"""
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   172
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   173
  if not sponsor_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   174
    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
   175
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   176
  if not user_ln:
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   177
    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
   178
44223e50e1fc Added a Host profile and generalized some views
Sverre Rabbelier <srabbelier@gmail.com>
parents: 377
diff changeset
   179
  return 'Host:%s:%s' % (sponsor_ln, user_ln)