49 """ |
49 """ |
50 |
50 |
51 return True |
51 return True |
52 |
52 |
53 def _keyName(self, **kwargs): |
53 def _keyName(self, **kwargs): |
54 """ |
54 """Returns the KeyName constructed from kwargs for this type of entity |
55 Returns the KeyName constructed from kwargs for this type of entity |
55 |
56 |
56 The KeyName is in the following format: |
57 The Keyname is in the following format: |
|
58 entity.name:<key_value1>:<key_value2>:...:<key_valueN> |
57 entity.name:<key_value1>:<key_value2>:...:<key_valueN> |
59 """ |
58 """ |
60 |
59 |
61 #Get the KeyFieldNames for this entity |
60 # get the KeyFieldNames for this entity |
62 key_field_names = self.getKeyFieldNames() |
61 key_field_names = self.getKeyFieldNames() |
63 |
62 |
64 #Check if all given KeyFieldNames are valid for this entity |
63 # check if all given KeyFieldNames are valid for this entity |
65 if not all(key in key_field_names for key in kwargs.keys()): |
64 if not all(key in key_field_names for key in kwargs.keys()): |
66 raise Error("Some of the provided arguments are not key fields") |
65 raise Error("Some of the provided arguments are not key fields") |
67 |
66 |
68 #Check if all key_field_names for this entity are present in kwargs |
67 # check if all key_field_names for this entity are present in kwargs |
69 if not all(field in kwargs.keys() for field in key_field_names): |
68 if not all(field in kwargs.keys() for field in key_field_names): |
70 raise Error("Not all the required key fields are present") |
69 raise Error("Not all the required key fields are present") |
71 |
70 |
72 #Check if all kwargs.values() are non-false |
71 # check if all kwargs.values() are non-false |
73 if not all(kwargs.values()): |
72 if not all(kwargs.values()): |
74 raise Error("Not all KeyValues are non-false") |
73 raise Error("Not all KeyValues are non-false") |
75 |
74 |
76 #Construct the KeyValues in the order given by getKeyFieldNames() |
75 # construct the KeyValues in the order given by getKeyFieldNames() |
77 keyvalues = [] |
76 keyvalues = [] |
78 for key_field_name in key_field_names: |
77 for key_field_name in key_field_names: |
79 keyvalues.append(kwargs[key_field_name]) |
78 keyvalues.append(kwargs[key_field_name]) |
80 |
79 |
81 #Construct the KeyName in the appropriate format |
80 # construct the KeyName in the appropriate format |
82 return ":".join([self._name] + keyvalues) |
81 return ":".join([self._name] + keyvalues) |
83 |
82 |
84 def getKeyValues(self, entity): |
83 def getKeyValues(self, entity): |
85 """Exctracts the key values from entity and returns them |
84 """Exctracts the key values from entity and returns them |
86 |
85 |