from flask import flash, redirect, request, url_for from mg import error import functools def webtask(fn): """ Wrapper for using mg tasks inside mgweb. Makes all exceptions raised to flash inside flask """ @functools.wraps(fn) def launcher(*args, **kwargs): try: return fn(*args, **kwargs) except error.generalError as e: flash(e.message, "danger") return redirect(request.referrer or url_for('index')) return launcher