# Path: mistraldashboard/api.py
# SERVICE_TYPE = 'workflowv2'
# def mistralclient(request):
# def pagination_list(entity, request, marker='', sort_keys='', sort_dirs='asc',
#                     paginate=False, reversed_order=False, selector=None):
# def execution_create(request, **data):
# def execution_get(request, execution_id):
# def execution_update(request, execution_id, field, value):
# def execution_delete(request, execution_name):
# def task_list(request, execution_id=None):
# def task_get(request, task_id=None):
# def workflow_list(request):
# def workflow_get(request, workflow_name):
# def workflow_create(request, workflows_definition):
# def workflow_validate(request, workflow_definition):
# def workflow_delete(request, workflow_name):
# def workflow_update(request, workflows_definition):
# def workbook_list(request):
# def workbook_get(request, workbook_name):
# def workbook_create(request, workbook_definition):
# def workbook_validate(request, workbook_definition):
# def workbook_delete(request, workbook_name):
# def workbook_update(request, workbook_definition):
# def action_list(request):
# def action_get(request, action_name):
# def action_create(request, action_definition):
# def action_update(request, action_definition):
# def action_run(request, action_name, input, params):
# def action_delete(request, action_name):
# def action_executions_list(request, task_execution_id=None):
# def action_execution_get(request, action_execution_id):
# def action_execution_delete(request, action_execution_id):
# def action_execution_update(request, id, state=None, output=None):
# def cron_trigger_list(request):
# def cron_trigger_get(request, cron_trigger_name):
# def cron_trigger_delete(request, cron_trigger_name):
# def cron_trigger_create(
#     request,
#     cron_trigger_name,
#     workflow_ID,
#     workflow_input,
#     workflow_params,
#     pattern,
#     first_time,
#     count
# ):
# 
# Path: mistraldashboard/default/utils.py
# def convert_empty_string_to_none(str):
#     """Returns None if given string is empty.
# 
#     Empty string is default for Django form empty HTML input.
#     python-mistral-client does not handle empty strings, only "None" type.
# 
#     :param str: string variable
#     """
# 
#     return str if len(str) != 0 else None
# 
# 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 json
from django.utils.translation import ugettext_lazy as _
from horizon import forms
from horizon import messages
from mistraldashboard import api
from mistraldashboard.default.utils import convert_empty_string_to_none
from mistraldashboard.handle_errors import handle_errors
            except Exception as e:
                msg = _('Input is invalid JSON: %s') % str(e)
                raise forms.ValidationError(msg)

        if cleaned_data.get('params_upload'):
            files = self.request.FILES
            cleaned_data['params'] = files['params_upload'].read()
        elif cleaned_data.get('params_data'):
            cleaned_data['params'] = cleaned_data['params_data']

        del(cleaned_data['params_upload'])
        del(cleaned_data['params_data'])

        if len(cleaned_data['params']) > 0:
            try:
                cleaned_data['params'] = json.loads(cleaned_data['params'])
            except Exception as e:
                msg = _('Params is invalid JSON: %s') % str(e)
                raise forms.ValidationError(msg)

        return cleaned_data

    @handle_errors(_("Unable to create Cron Trigger"), [])
    def handle(self, request, data):
        data['input'] = convert_empty_string_to_none(data['input'])
        data['params'] = convert_empty_string_to_none(data['params'])
        data['schedule_pattern'] = convert_empty_string_to_none(
            data['schedule_pattern']
        )
        data['first_time'] = convert_empty_string_to_none(data['first_time'])

# Path: mistraldashboard/api.py
# SERVICE_TYPE = 'workflowv2'
# def mistralclient(request):
# def pagination_list(entity, request, marker='', sort_keys='', sort_dirs='asc',
#                     paginate=False, reversed_order=False, selector=None):
# def execution_create(request, **data):
# def execution_get(request, execution_id):
# def execution_update(request, execution_id, field, value):
# def execution_delete(request, execution_name):
# def task_list(request, execution_id=None):
# def task_get(request, task_id=None):
# def workflow_list(request):
# def workflow_get(request, workflow_name):
# def workflow_create(request, workflows_definition):
# def workflow_validate(request, workflow_definition):
# def workflow_delete(request, workflow_name):
# def workflow_update(request, workflows_definition):
# def workbook_list(request):
# def workbook_get(request, workbook_name):
# def workbook_create(request, workbook_definition):
# def workbook_validate(request, workbook_definition):
# def workbook_delete(request, workbook_name):
# def workbook_update(request, workbook_definition):
# def action_list(request):
# def action_get(request, action_name):
# def action_create(request, action_definition):
# def action_update(request, action_definition):
# def action_run(request, action_name, input, params):
# def action_delete(request, action_name):
# def action_executions_list(request, task_execution_id=None):
# def action_execution_get(request, action_execution_id):
# def action_execution_delete(request, action_execution_id):
# def action_execution_update(request, id, state=None, output=None):
# def cron_trigger_list(request):
# def cron_trigger_get(request, cron_trigger_name):
# def cron_trigger_delete(request, cron_trigger_name):
# def cron_trigger_create(
#     request,
#     cron_trigger_name,
#     workflow_ID,
#     workflow_input,
#     workflow_params,
#     pattern,
#     first_time,
#     count
# ):
# 
# Path: mistraldashboard/default/utils.py
# def convert_empty_string_to_none(str):
#     """Returns None if given string is empty.
# 
#     Empty string is default for Django form empty HTML input.
#     python-mistral-client does not handle empty strings, only "None" type.
# 
#     :param str: string variable
#     """
# 
#     return str if len(str) != 0 else None
# 
# 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/cron_triggers/forms.py
import json
from django.utils.translation import ugettext_lazy as _
from horizon import forms
from horizon import messages
from mistraldashboard import api
from mistraldashboard.default.utils import convert_empty_string_to_none
from mistraldashboard.handle_errors import handle_errors

            except Exception as e:
                msg = _('Input is invalid JSON: %s') % str(e)
                raise forms.ValidationError(msg)

        if cleaned_data.get('params_upload'):
            files = self.request.FILES
            cleaned_data['params'] = files['params_upload'].read()
        elif cleaned_data.get('params_data'):
            cleaned_data['params'] = cleaned_data['params_data']

        del(cleaned_data['params_upload'])
        del(cleaned_data['params_data'])

        if len(cleaned_data['params']) > 0:
            try:
                cleaned_data['params'] = json.loads(cleaned_data['params'])
            except Exception as e:
                msg = _('Params is invalid JSON: %s') % str(e)
                raise forms.ValidationError(msg)

        return cleaned_data

    @handle_errors(_("Unable to create Cron Trigger"), [])
    def handle(self, request, data):
        data['input'] = convert_empty_string_to_none(data['input'])
        data['params'] = convert_empty_string_to_none(data['params'])
        data['schedule_pattern'] = convert_empty_string_to_none(
            data['schedule_pattern']
        )
        data['first_time'] = convert_empty_string_to_none(data['first_time'])

        data['schedule_count'] = convert_empty_string_to_none(