app/soc/logic/key_name.py
changeset 512 aae25d2b4464
parent 499 d22e4fe8e64b
child 522 c06a009005fc
equal deleted inserted replaced
511:52557918ec8f 512:aae25d2b4464
    29 class Error(Exception):
    29 class Error(Exception):
    30   """Base class for all exceptions raised by this module."""
    30   """Base class for all exceptions raised by this module."""
    31   pass
    31   pass
    32 
    32 
    33 
    33 
    34 def nameDocument(partial_path, link_name=None):
    34 def nameDocument(partial_path, link_id=None):
    35   """Returns a Document key name constructed from a path and link name.
    35   """Returns a Document key name constructed from a path and link ID.
    36     
    36     
    37   Args:
    37   Args:
    38     partial_path: the first portion of the path to the Document that uniquely
    38     partial_path: the first portion of the path to the Document that uniquely
    39       identifies it
    39       identifies it
    40     link_name: optional link name to append to path (when omitted,
    40     link_id: optional link ID to append to path (when omitted,
    41       partial_path is actually the entire path, with the link_name already
    41       partial_path is actually the entire path, with the link_id already
    42       appended)
    42       appended)
    43 
    43 
    44   Raises:
    44   Raises:
    45     Error if partial_path and link_Name produce a "False" path (None,
    45     Error if partial_path and link_id produce a "False" path (None,
    46     empty string, etc.)
    46     empty string, etc.)
    47   """
    47   """
    48   path = [partial_path]
    48   path = [partial_path]
    49   
    49   
    50   if link_name:
    50   if link_id:
    51     path.append(link_name)
    51     path.append(link_id)
    52 
    52 
    53   path = path_link_name.combinePath(path)
    53   path = path_link_name.combinePath(path)
    54 
    54 
    55   if not path:
    55   if not path:
    56     raise Error('"path" must be non-False: "%s"' % path)
    56     raise Error('"path" must be non-False: "%s"' % path)
    57 
    57 
    58   return 'Document:%s' % path
    58   return 'Document:%s' % path
    59 
    59 
    60 
    60 
    61 def nameSiteSettings(partial_path, link_name):
    61 def nameSiteSettings(partial_path, link_id):
    62   """Returns a SiteSettings key name constructed from a supplied path.
    62   """Returns a SiteSettings key name constructed from a supplied path.
    63   
    63   
    64   Raises:
    64   Raises:
    65     Error if path is "False" (None, empty string, etc.)
    65     Error if path is "False" (None, empty string, etc.)
    66   """
    66   """
    67 
    67 
    68   if not partial_path:
    68   if not partial_path:
    69     raise Error('"partial_path" must be non-False: "%s"' % partial_path)
    69     raise Error('"partial_path" must be non-False: "%s"' % partial_path)
    70 
    70 
    71   if not link_name:
    71   if not link_id:
    72     raise Error('"link_name" must be non-False: "%s"' % link_name)
    72     raise Error('"link_id" must be non-False: "%s"' % link_id)
    73 
    73 
    74   return 'SiteSettings:%s:%s' % (partial_path, link_name)
    74   return 'SiteSettings:%s:%s' % (partial_path, link_id)
    75 
    75 
    76 
    76 
    77 def nameHomeSettings(partial_path, link_name):
    77 def nameHomeSettings(partial_path, link_id):
    78   """Returns a HomeSettings key name constructed from a supplied path.
    78   """Returns a HomeSettings key name constructed from a supplied path.
    79 
    79 
    80   Raises:
    80   Raises:
    81     Error if path is "False" (None, empty string, etc.)
    81     Error if path is "False" (None, empty string, etc.)
    82   """
    82   """
    83 
    83 
    84   if not partial_path:
    84   if not partial_path:
    85     raise Error('"partial_path" must be non-False: "%s"' % partial_path)
    85     raise Error('"partial_path" must be non-False: "%s"' % partial_path)
    86 
    86 
    87   if not link_name:
    87   if not link_id:
    88     raise Error('"link_name" must be non-False: "%s"' % link_name)
    88     raise Error('"link_id" must be non-False: "%s"' % link_id)
    89 
    89 
    90   return 'HomeSettings:%s:%s' % (partial_path, link_name)
    90   return 'HomeSettings:%s:%s' % (partial_path, link_id)
    91 
    91 
    92 
    92 
    93 def nameUser(email):
    93 def nameUser(email):
    94   """Returns a User key name constructed from a supplied email address.
    94   """Returns a User key name constructed from a supplied email address.
    95   
    95   
   100     raise Error('"email" must be non-False: "%s"' % email)
   100     raise Error('"email" must be non-False: "%s"' % email)
   101 
   101 
   102   return 'User:%s' % email
   102   return 'User:%s' % email
   103 
   103 
   104 
   104 
   105 def nameSponsor(link_name):
   105 def nameSponsor(link_id):
   106   """Returns a Sponsor key name constructed from a supplied link name.
   106   """Returns a Sponsor key name constructed from a supplied link ID.
   107 
   107 
   108   Raises:
   108   Raises:
   109     Error if link_name is "False" (None, empty string, etc.)
   109     Error if link_id is "False" (None, empty string, etc.)
   110   """
   110   """
   111   if not link_name:
   111   if not link_id:
   112     raise Error('"link_name" must be non-False: "%s"' % link_name)
   112     raise Error('"link_id" must be non-False: "%s"' % link_id)
   113 
   113 
   114   return 'Group/Sponsor:%s' % link_name
   114   return 'Group/Sponsor:%s' % link_id
   115 
   115 
   116 
   116 
   117 def nameSchool(sponsor_ln, program_ln, link_name):
   117 def nameSchool(sponsor_ln, program_ln, link_id):
   118   """Returns a School key name constructed from link names.
   118   """Returns a School key name constructed from link IDs.
   119      
   119      
   120   Args:
   120   Args:
   121     sponsor_ln: Sponsor link name
   121     sponsor_ln: Sponsor link ID
   122     program_ln: Program link name
   122     program_ln: Program link ID
   123     link_name: School link name
   123     link_id: School link ID
   124 
   124 
   125   Raises:
   125   Raises:
   126     Error if sponsor_ln, program_ln, and link_Name combine to produce
   126     Error if sponsor_ln, program_ln, and link_id combine to produce
   127     a "False" path (None, empty string, etc.)
   127     a "False" path (None, empty string, etc.)
   128   """
   128   """
   129   path = path_link_name.combinePath([[sponsor_ln, program_ln], link_name])
   129   path = path_link_name.combinePath([[sponsor_ln, program_ln], link_id])
   130   
   130   
   131   if not path:
   131   if not path:
   132     raise Error('"path" must be non-False: "%s"' % path)
   132     raise Error('"path" must be non-False: "%s"' % path)
   133   
   133   
   134   return 'Group/School:%s' % path
   134   return 'Group/School:%s' % path
   135 
   135 
   136 
   136 
   137 def nameOrganization(sponsor_ln, program_ln, link_name):
   137 def nameOrganization(sponsor_ln, program_ln, link_id):
   138   """Returns a Organization key name constructed from link names.
   138   """Returns a Organization key name constructed from link IDs.
   139      
   139      
   140   Args:
   140   Args:
   141     sponsor_ln: Sponsor link name
   141     sponsor_ln: Sponsor link ID
   142     program_ln: Program link name
   142     program_ln: Program link ID
   143     link_name: Organization link name
   143     link_id: Organization link ID
   144 
   144 
   145   Raises:
   145   Raises:
   146     Error if sponsor_ln, program_ln, and link_Name combine to produce
   146     Error if sponsor_ln, program_ln, and link_id combine to produce
   147     a "False" path (None, empty string, etc.)
   147     a "False" path (None, empty string, etc.)
   148   """
   148   """
   149   path = path_link_name.combinePath([[sponsor_ln, program_ln], link_name])
   149   path = path_link_name.combinePath([[sponsor_ln, program_ln], link_id])
   150   
   150   
   151   if not path:
   151   if not path:
   152     raise Error('"path" must be non-False: "%s"' % path)
   152     raise Error('"path" must be non-False: "%s"' % path)
   153   
   153   
   154   return 'Group/Organization:%s' % path 
   154   return 'Group/Organization:%s' % path 
   155 
   155 
   156 
   156 
   157 def nameClub(link_name):
   157 def nameClub(link_id):
   158   """Returns a Club key name constructed from a supplied link name.
   158   """Returns a Club key name constructed from a supplied link ID.
   159 
   159 
   160   Raises:
   160   Raises:
   161     Error if link_name is "False" (None, empty string, etc.)
   161     Error if link_id is "False" (None, empty string, etc.)
   162   """
   162   """
   163   if not link_name:
   163   if not link_id:
   164     raise Error('"link_name" must be non-False: "%s"' % link_name)
   164     raise Error('"link_id" must be non-False: "%s"' % link_id)
   165 
   165 
   166   return 'Group/Club:%s' % link_name
   166   return 'Group/Club:%s' % link_id
   167 
   167 
   168 
   168 
   169 def nameWork(link_name):
   169 def nameWork(link_id):
   170   """Placeholder for work namer.
   170   """Placeholder for work namer.
   171   """
   171   """
   172 
   172 
   173   if not link_name:
   173   if not link_id:
   174     raise Error('"link_name" must be non-False: "%s"' % link_name)
   174     raise Error('"link_id" must be non-False: "%s"' % link_id)
   175 
   175 
   176   return 'Work:%s' % link_name
   176   return 'Work:%s' % link_id
   177 
   177 
   178 
   178 
   179 def nameHost(sponsor_ln, user_ln):
   179 def nameHost(sponsor_ln, user_ln):
   180   """Placeholder for host namer.
   180   """Placeholder for host namer.
   181   """
   181   """