mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 08:16:19 -04:00
remove history-meta for templates, replace with hand-made history table
history-meta's dynamic magic is insufficient for templates, where we need to be able to refer to the specific history table to take advantage of sqlalchemy's relationship management (2/3rds of an ORM). So replace it with a custom made version table. Had to change the version decorator slightly for this
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import itertools
|
||||
from functools import wraps
|
||||
from app.history_meta import versioned_objects, create_history
|
||||
from functools import wraps, partial
|
||||
|
||||
from app.history_meta import create_history
|
||||
|
||||
|
||||
def transactional(func):
|
||||
@@ -19,14 +20,16 @@ def transactional(func):
|
||||
return commit_or_rollback
|
||||
|
||||
|
||||
def version_class(model_class):
|
||||
def version_class(model_class, history_cls=None):
|
||||
create_hist = partial(create_history, history_cls=history_cls)
|
||||
|
||||
def versioned(func):
|
||||
@wraps(func)
|
||||
def record_version(*args, **kwargs):
|
||||
from app import db
|
||||
func(*args, **kwargs)
|
||||
history_objects = [create_history(obj) for obj in
|
||||
versioned_objects(itertools.chain(db.session.new, db.session.dirty))
|
||||
history_objects = [create_hist(obj) for obj in
|
||||
itertools.chain(db.session.new, db.session.dirty)
|
||||
if isinstance(obj, model_class)]
|
||||
for h_obj in history_objects:
|
||||
db.session.add(h_obj)
|
||||
|
||||
Reference in New Issue
Block a user