Added option to overwrite existing stored credentials.

Added an option to django_orm.Storage locked_put method to allow for
overwriting an existing credential record rather than the creation of a
new one.
This commit is contained in:
lraccomando
2014-04-28 16:58:58 -04:00
parent 27f520d1b6
commit e2e988f8d6

View File

@@ -116,14 +116,19 @@ class Storage(BaseStorage):
credential.set_store(self) credential.set_store(self)
return credential return credential
def locked_put(self, credentials): def locked_put(self, credentials, overwrite=False):
"""Write a Credentials to the datastore. """Write a Credentials to the datastore.
Args: Args:
credentials: Credentials, the credentials to store. credentials: Credentials, the credentials to store.
""" """
args = {self.key_name: self.key_value} args = {self.key_name: self.key_value}
entity = self.model_class(**args)
if overwrite:
entity, is_new = self.model_class.objects.get_or_create(**args)
else:
entity = self.model_class(**args)
setattr(entity, self.property_name, credentials) setattr(entity, self.property_name, credentials)
entity.save() entity.save()