1
0
mirror of http://git.whoc.org.uk/git/password-manager.git synced 2024-11-15 00:09:02 +01:00

Fix flask model initialization

This fixes Records and RecordVersions to populate parent objects as part of
the initialization
This commit is contained in:
jokajak 2016-04-24 12:17:22 -04:00
parent 3574eacb25
commit e4e4de7c1d

View File

@ -87,8 +87,11 @@ class RecordVersion(db.Model):
order_by=id, order_by=id,
cascade='all,delete')) cascade='all,delete'))
def __init__(self): def __init__(self, record=None):
"""Initialize a record version.""" """Initialize a record version."""
if record:
self.record = record
self.record_id = record.id
self.creation_date = datetime.datetime.utcnow() self.creation_date = datetime.datetime.utcnow()
def update(self, someData): def update(self, someData):
@ -128,8 +131,11 @@ class Record(db.Model):
uselist=False, uselist=False,
cascade='save-update, merge, delete, delete-orphan') cascade='save-update, merge, delete, delete-orphan')
def __init__(self): def __init__(self, user=None):
"""Initialize a record.""" """Initialize a record."""
if user:
self.user_id = user.id
self.version = 1
self.creation_date = datetime.datetime.utcnow() self.creation_date = datetime.datetime.utcnow()
def update(self, data, record_version): def update(self, data, record_version):
@ -139,10 +145,7 @@ class Record(db.Model):
self.api_version = data['version'] self.api_version = data['version']
self.update_date = datetime.datetime.now() self.update_date = datetime.datetime.now()
self.current_record_version = record_version self.current_record_version = record_version
if self.version: self.version += 1
self.version += 1
else:
self.version = 1
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------