app/soc/logic/models/base.py
changeset 432 1851d67a1004
parent 429 e50e18936f06
child 433 001b981be45e
--- a/app/soc/logic/models/base.py	Sun Nov 02 18:25:07 2008 +0000
+++ b/app/soc/logic/models/base.py	Sun Nov 02 22:50:22 2008 +0000
@@ -20,6 +20,7 @@
 __authors__ = [
   '"Todd Larsen" <tlarsen@google.com>',
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
+  '"Lennard de Rijk" <rijk0214@gmail.com>',
   '"Pawel Solyga" <pawel.solyga@gmail.com>',
   ]
 
@@ -48,6 +49,37 @@
 
     return True
 
+  def _keyName(self, **kwargs):
+    """
+    Returns the KeyName constructed from kwargs for this type of entity
+
+    The Keyname is in the following format:
+    entity.name:<key_value1>:<key_value2>:...:<key_valueN>
+    """
+
+    #Get the KeyFieldNames for this entity
+    key_field_names = self.getKeyFieldNames()
+
+    #Check if all given KeyFieldNames are valid for this entity
+    if not all(key in key_field_names for key in kwargs.keys()):
+      raise Error("Some of the provided arguments are not key fields")
+
+    #Check if all key_field_names for this entity are present in kwargs
+    if not all(field in kwargs.keys() for field in key_field_names):
+        raise Error("Not all the required key fields are present")
+
+    #Check if all kwargs.values() are non-false
+    if not all(kwargs.values()):
+        raise Error("Not all KeyValues are non-false")
+
+    #Construct the KeyValues in the order given by getKeyFieldNames()
+    keyvalues = []
+    for key_field_name in key_field_names:
+        keyvalues.append(kwargs[key_field_name])
+
+    #Construct the KeyName in the appropriate format
+    return ":".join([self._name] + keyvalues)
+
   def getKeyValues(self, entity):
     """Exctracts the key values from entity and returns them