# Path: mistraldashboard/handle_errors.py
# def handle_errors(error_message, error_default=None, request_arg=None):
#     """A decorator for adding default error handling to API calls.
# 
#     It wraps the original method in a try-except block, with horizon's
#     error handling added.
# 
#     Note: it should only be used on functions or methods that take request as
#     their argument (it has to be named "request", or ``request_arg`` has to be
#     provided, indicating which argument is the request).
# 
#     The decorated method accepts a number of additional parameters:
# 
#         :param _error_handle: whether to handle the errors in this call
#         :param _error_message: override the error message
#         :param _error_default: override the default value returned on error
#         :param _error_redirect: specify a redirect url for errors
#         :param _error_ignore: ignore known errors
#     """
#     def decorator(func):
#         if request_arg is None:
#             _request_arg = 'request'
#             if _request_arg not in inspect.getargspec(func).args:
#                 raise RuntimeError(
#                     "The handle_errors decorator requires 'request' as "
#                     "an argument of the function or method being decorated")
#         else:
#             _request_arg = request_arg
# 
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
#             _error_handle = kwargs.pop('_error_handle', True)
#             _error_message = kwargs.pop('_error_message', error_message)
#             _error_default = kwargs.pop('_error_default', error_default)
#             _error_redirect = kwargs.pop('_error_redirect', None)
#             _error_ignore = kwargs.pop('_error_ignore', False)
# 
#             if not _error_handle:
#                 return func(*args, **kwargs)
#             try:
#                 return func(*args, **kwargs)
#             except Exception as e:
#                 callargs = inspect.getcallargs(func, *args, **kwargs)
#                 request = callargs[_request_arg]
#                 _error_message += ': ' + str(e)
#                 horizon.exceptions.handle(request, _error_message,
#                                           ignore=_error_ignore,
#                                           redirect=_error_redirect)
#                 return _error_default
# 
#         wrapper.wrapped = func
# 
#         return wrapper
# 
#     return decorator


import itertools
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from horizon.utils import functions as utils
from horizon.utils import memoized
from mistralclient.api import client as mistral_client
from mistraldashboard.handle_errors import handle_errors
from openstack_dashboard.api import base

    return mistralclient(request).executions.get(execution_id)


def execution_update(request, execution_id, field, value):
    """update specific execution field, either state or description.

    :param request: Request data
    :param execution_id: Execution ID
    :param field: flag - either Execution state or description
    :param value: new update value
    """

    if field == "state":
        return mistralclient(request).\
            executions.update(execution_id, value)
    elif field == "description":
        return mistralclient(request).\
            executions.update(execution_id, None, value)


def execution_delete(request, execution_name):
    """Delete execution.

    :param execution_name: Execution name
    """

    return mistralclient(request).executions.delete(execution_name)



# Path: mistraldashboard/handle_errors.py
# def handle_errors(error_message, error_default=None, request_arg=None):
#     """A decorator for adding default error handling to API calls.
# 
#     It wraps the original method in a try-except block, with horizon's
#     error handling added.
# 
#     Note: it should only be used on functions or methods that take request as
#     their argument (it has to be named "request", or ``request_arg`` has to be
#     provided, indicating which argument is the request).
# 
#     The decorated method accepts a number of additional parameters:
# 
#         :param _error_handle: whether to handle the errors in this call
#         :param _error_message: override the error message
#         :param _error_default: override the default value returned on error
#         :param _error_redirect: specify a redirect url for errors
#         :param _error_ignore: ignore known errors
#     """
#     def decorator(func):
#         if request_arg is None:
#             _request_arg = 'request'
#             if _request_arg not in inspect.getargspec(func).args:
#                 raise RuntimeError(
#                     "The handle_errors decorator requires 'request' as "
#                     "an argument of the function or method being decorated")
#         else:
#             _request_arg = request_arg
# 
#         @functools.wraps(func)
#         def wrapper(*args, **kwargs):
#             _error_handle = kwargs.pop('_error_handle', True)
#             _error_message = kwargs.pop('_error_message', error_message)
#             _error_default = kwargs.pop('_error_default', error_default)
#             _error_redirect = kwargs.pop('_error_redirect', None)
#             _error_ignore = kwargs.pop('_error_ignore', False)
# 
#             if not _error_handle:
#                 return func(*args, **kwargs)
#             try:
#                 return func(*args, **kwargs)
#             except Exception as e:
#                 callargs = inspect.getcallargs(func, *args, **kwargs)
#                 request = callargs[_request_arg]
#                 _error_message += ': ' + str(e)
#                 horizon.exceptions.handle(request, _error_message,
#                                           ignore=_error_ignore,
#                                           redirect=_error_redirect)
#                 return _error_default
# 
#         wrapper.wrapped = func
# 
#         return wrapper
# 
#     return decorator


# Path: mistraldashboard/api.py
import itertools
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from horizon.utils import functions as utils
from horizon.utils import memoized
from mistralclient.api import client as mistral_client
from mistraldashboard.handle_errors import handle_errors
from openstack_dashboard.api import base


    return mistralclient(request).executions.get(execution_id)


def execution_update(request, execution_id, field, value):
    """update specific execution field, either state or description.

    :param request: Request data
    :param execution_id: Execution ID
    :param field: flag - either Execution state or description
    :param value: new update value
    """

    if field == "state":
        return mistralclient(request).\
            executions.update(execution_id, value)
    elif field == "description":
        return mistralclient(request).\
            executions.update(execution_id, None, value)


def execution_delete(request, execution_name):
    """Delete execution.

    :param execution_name: Execution name
    """

    return mistralclient(request).executions.delete(execution_name)



@handle_errors(_("Unable to retrieve tasks."), [])