app/soc/logic/models/base.py
changeset 432 1851d67a1004
parent 429 e50e18936f06
child 433 001b981be45e
equal deleted inserted replaced
431:96b6ee5efdc3 432:1851d67a1004
    18 """
    18 """
    19 
    19 
    20 __authors__ = [
    20 __authors__ = [
    21   '"Todd Larsen" <tlarsen@google.com>',
    21   '"Todd Larsen" <tlarsen@google.com>',
    22   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    22   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
       
    23   '"Lennard de Rijk" <rijk0214@gmail.com>',
    23   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    24   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    24   ]
    25   ]
    25 
    26 
    26 
    27 
    27 from google.appengine.ext import db
    28 from google.appengine.ext import db
    45     taken when a field is updated. The field is not updated if the
    46     taken when a field is updated. The field is not updated if the
    46     method does not return a True value.
    47     method does not return a True value.
    47     """
    48     """
    48 
    49 
    49     return True
    50     return True
       
    51 
       
    52   def _keyName(self, **kwargs):
       
    53     """
       
    54     Returns the KeyName constructed from kwargs for this type of entity
       
    55 
       
    56     The Keyname is in the following format:
       
    57     entity.name:<key_value1>:<key_value2>:...:<key_valueN>
       
    58     """
       
    59 
       
    60     #Get the KeyFieldNames for this entity
       
    61     key_field_names = self.getKeyFieldNames()
       
    62 
       
    63     #Check if all given KeyFieldNames are valid for this entity
       
    64     if not all(key in key_field_names for key in kwargs.keys()):
       
    65       raise Error("Some of the provided arguments are not key fields")
       
    66 
       
    67     #Check if all key_field_names for this entity are present in kwargs
       
    68     if not all(field in kwargs.keys() for field in key_field_names):
       
    69         raise Error("Not all the required key fields are present")
       
    70 
       
    71     #Check if all kwargs.values() are non-false
       
    72     if not all(kwargs.values()):
       
    73         raise Error("Not all KeyValues are non-false")
       
    74 
       
    75     #Construct the KeyValues in the order given by getKeyFieldNames()
       
    76     keyvalues = []
       
    77     for key_field_name in key_field_names:
       
    78         keyvalues.append(kwargs[key_field_name])
       
    79 
       
    80     #Construct the KeyName in the appropriate format
       
    81     return ":".join([self._name] + keyvalues)
    50 
    82 
    51   def getKeyValues(self, entity):
    83   def getKeyValues(self, entity):
    52     """Exctracts the key values from entity and returns them
    84     """Exctracts the key values from entity and returns them
    53 
    85 
    54     Args:
    86     Args: