Implement @get_workbench decorator
This passes in a Workbench() via the 'workbench' keyword argument, and conveniently cleans it up after the function has finished. 2 out of our 5 backends forgot to clean up their workbench, so this is clearly needed :-). Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
c11c1994e6
commit
f91dcc9d96
@ -20,6 +20,7 @@ from urlparse import urljoin
|
||||
from werkzeug.exceptions import Forbidden, NotFound
|
||||
from werkzeug.urls import url_quote
|
||||
|
||||
from mediagoblin import mg_globals as mgg
|
||||
from mediagoblin.db.models import MediaEntry, User
|
||||
from mediagoblin.tools.response import redirect, render_404
|
||||
|
||||
@ -222,3 +223,14 @@ def get_media_entry_by_id(controller):
|
||||
return controller(request, media=media, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def get_workbench(func):
|
||||
"""Decorator, passing in a workbench as kwarg which is cleaned up afterwards"""
|
||||
|
||||
@wraps(func)
|
||||
def new_func(*args, **kwargs):
|
||||
with mgg.workbench_manager.create_workbench() as workbench:
|
||||
return func(*args, workbench=workbench, **kwargs)
|
||||
|
||||
return new_func
|
||||
|
Loading…
x
Reference in New Issue
Block a user