示例#1
0
def index(request: HttpRequest) -> HttpResponse:
    """Render the page with the list of workflows."""
    remove_workflow_from_session(request)

    workflows = (request.user.workflows_owner.all()
                 | request.user.workflows_shared.all())
    workflows = workflows.distinct()

    # Get the queryset for those with start and those without
    workflows_star = workflows.filter(star__in=[request.user])
    workflows_no_star = workflows.exclude(star__in=[request.user])

    # We include the table only if it is not empty.
    context = {
        'workflows_star': workflows_star.order_by('name'),
        'workflows': workflows_no_star.order_by('name'),
        'nwflows': len(workflows),
    }

    # Report if Celery is not running properly
    if request.user.is_superuser:
        # Verify that celery is running!
        if not celery_is_up():
            messages.error(
                request,
                _(
                    'WARNING: Celery is not currently running. ' +
                    'Please configure it correctly.', ),
            )

    return render(request, 'workflow/index.html', context)
示例#2
0
def run_action(
    request: http.HttpRequest,
    pk: int,
    workflow: Optional[models.Workflow] = None,
    action: Optional[models.Action] = None,
) -> http.HttpResponse:
    """Run specific run action view depending on action type.

    If it is a Survey or todo, renders a table with all rows that
    satisfy the filter condition and includes a link to enter data for each
    of them.

    :param request: HttpRequest
    :param pk: Action id. It is assumed to be an action In
    :param workflow: Workflow object to be assigned by the decorators
    :param action: Action object to be assigned by the decorators
    :return: HttpResponse
    """
    del pk, workflow
    if not celery_is_up():
        messages.error(
            request,
            _('Unable to execute actions due to a misconfiguration. ' +
              'Ask your system administrator to enable message queueing.'))
        return redirect(reverse('action:index'))

    return services.ACTION_PROCESS_FACTORY.process_run_request(
        action.action_type,
        request=request,
        action=action,
        prev_url=reverse('action:run', kwargs={'pk': action.id}))
示例#3
0
def edit(
    request: HttpRequest,
    pk: int,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Edit an existing scheduled email action.

    :param request: HTTP request

    :param pk: primary key of the action

    :return: HTTP response
    """
    # Distinguish between creating a new element or editing an existing one
    new_item = request.path.endswith(
        reverse('scheduler:create', kwargs={'pk': pk}))

    if new_item:
        action = workflow.actions.filter(pk=pk, ).filter(
            Q(workflow__user=request.user)
            | Q(workflow__shared=request.user), ).first()
        if not action:
            return redirect('home')
        s_item = None
    else:
        # Get the scheduled action from the parameter in the URL
        s_item = ScheduledAction.objects.filter(pk=pk).first()
        if not s_item:
            return redirect('home')
        action = s_item.action

    # Get the payload from the session, and if not, use the given one
    op_payload = request.session.get(action_session_dictionary)
    if not op_payload:
        op_payload = {
            'action_id': action.id,
            'prev_url': reverse('scheduler:create', kwargs={'pk': action.id}),
            'post_url': reverse('scheduler:finish_scheduling'),
        }
        set_action_payload(request.session, op_payload)
        request.session.save()

    # Verify that celery is running!
    if not celery_is_up():
        messages.error(
            request,
            _('Unable to schedule actions due to a misconfiguration. ' +
              'Ask your system administrator to enable queueing.'))
        return redirect(reverse('action:index'))

    if action.action_type == Action.personalized_text:
        return save_email_schedule(request, action, s_item, op_payload)
    elif action.action_type == Action.personalized_canvas_email:
        return save_canvas_email_schedule(request, action, s_item, op_payload)
    elif action.action_type == Action.personalized_json:
        return save_json_schedule(request, action, s_item, op_payload)

    # Action type not found, so return to the main table view
    messages.error(request, _('This action does not support scheduling'))
    return redirect('scheduler:index')
示例#4
0
def run_action(
    request: HttpRequest,
    pk: int,
    workflow: Optional[Workflow] = None,
    action: Optional[Action] = None,
) -> HttpResponse:
    """Run specific run action view depending on action type.

    If it is a Survey or todo, renders a table with all rows that
    satisfy the filter condition and includes a link to enter data for each
    of them.

    :param request: HttpRequest
    :param pk: Action id. It is assumed to be an action In
    :return: HttpResponse
    """

    if not celery_is_up():
        messages.error(
            request,
            _('Unable to execute actions due to a misconfiguration. ' +
              'Ask your system administrator to enable message queueing.'))
        return redirect(reverse('action:index'))

    if action.action_type not in fn_distributor:
        # Incorrect type of action.
        return redirect(reverse('action:index'))

    return fn_distributor[action.action_type](request, workflow, action)
示例#5
0
def index(request: http.HttpRequest) -> http.HttpResponse:
    """Render the page with the list of workflows.

    :param request: HttpRequest received
    :return: Response with the index page rendered
    """
    remove_workflow_from_session(request)

    # Report if Celery is not running properly
    if request.user.is_superuser:
        # Verify that celery is running!
        if not celery_is_up():
            messages.error(
                request,
                _(
                    'WARNING: Celery is not currently running. ' +
                    'Please configure it correctly.', ),
            )

    return render(request, 'workflow/index.html',
                  services.get_index_context(request.user))
示例#6
0
def plugin_invoke(
    request: HttpRequest,
    pk: int,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Render the view for the first step of plugin execution.

    :param request: HTTP request received
    :param pk: primary key of the plugin
    :return: Page offering to select the columns to invoke
    """
    # Verify that celery is running!
    if not celery_is_up():
        messages.error(
            request,
            _('Unable to run plugins due to a misconfiguration. ' +
              'Ask your system administrator to enable queueing.'))
        return redirect(reverse('table:display'))

    plugin_info = Plugin.objects.filter(pk=pk).first()
    if not plugin_info:
        return redirect('home')

    if workflow.nrows == 0:
        return render(request, 'dataops/plugin_info_for_run.html', {
            'empty_wflow': True,
            'is_model': plugin_info.get_is_model()
        })

    plugin_instance, __ = load_plugin(plugin_info.filename)
    if plugin_instance is None:
        messages.error(
            request,
            _('Unable to instantiate plugin "{0}"').format(plugin_info.name),
        )
        return redirect('dataops:transform')

    # create the form to select the columns and the corresponding dictionary
    form = PluginInfoForm(request.POST or None,
                          workflow=workflow,
                          plugin_instance=plugin_instance)

    if request.method == 'POST' and form.is_valid():
        in_cols, out_cols = _prepare_plugin_input_output(
            plugin_instance, workflow, form)

        exec_params = _prepare_plugin_parameters(plugin_instance, form)

        # Log the event with the status "preparing invocation"
        log_item = Log.objects.register(
            request.user, Log.PLUGIN_EXECUTE, workflow, {
                'id': plugin_info.id,
                'name': plugin_info.name,
                'input_column_names': in_cols,
                'output_column_names': out_cols,
                'parameters': json.dumps(exec_params, default=str),
                'status': 'preparing execution'
            })

        run_plugin_task.apply_async(
            (request.user.id, workflow.id, pk, in_cols, out_cols,
             form.cleaned_data['out_column_suffix'],
             form.cleaned_data['merge_key'], exec_params, log_item.id),
            serializer='pickle')

        # Successful processing.
        return render(request, 'dataops/plugin_execution_report.html',
                      {'log_id': log_item.id})

    return render(request,
                  'dataops/plugin_info_for_run.html',
                  context={
                      'form':
                      form,
                      'input_column_fields': [
                          fld for fld in list(form)
                          if fld.name.startswith(FIELD_PREFIX + 'input')
                      ],
                      'output_column_fields': [
                          fld for fld in list(form)
                          if fld.name.startswith(FIELD_PREFIX + 'output')
                      ],
                      'parameters': [
                          fld for fld in list(form)
                          if fld.name.startswith(FIELD_PREFIX + 'parameter')
                      ],
                      'pinstance':
                      plugin_instance,
                      'id':
                      workflow.id,
                  })
示例#7
0
def plugin_invoke(
    request: HttpRequest,
    pk: int,
    workflow: Optional[models.Workflow] = None,
) -> HttpResponse:
    """Render the view for the first step of plugin execution.

    :param request: HTTP request received
    :param pk: primary key of the plugin
    :param workflow: Workflow being manipulated
    :return: Page offering to select the columns to invoke
    """
    # Verify that celery is running!
    if not celery_is_up():
        messages.error(
            request,
            _(
                'Unable to run plugins due to a misconfiguration. '
                + 'Ask your system administrator to enable queueing.'))
        return redirect(reverse('table:display'))

    plugin_info = models.Plugin.objects.filter(pk=pk).first()
    if not plugin_info:
        return redirect('home')

    if workflow.nrows == 0:
        return render(
            request,
            'dataops/plugin_info_for_run.html',
            {'empty_wflow': True,
             'is_model': plugin_info.get_is_model()})

    plugin_instance, __ = services.load_plugin(plugin_info.filename)
    if plugin_instance is None:
        messages.error(
            request,
            _('Unable to instantiate plugin "{0}"').format(plugin_info.name),
        )
        return redirect('dataops:transform')

    # create the form to select the columns and the corresponding dictionary
    form = forms.PluginInfoForm(
        request.POST or None,
        workflow=workflow,
        plugin_instance=plugin_instance)

    if request.method == 'POST' and form.is_valid():
        log_item = services.plugin_queue_execution(
            request,
            workflow,
            plugin_info,
            plugin_instance,
            {
                'columns': form.cleaned_data.get('columns'),
                'input_column_names': form.get_input_column_names(),
                'output_column_names': form.get_output_column_names(),
                'params': form.get_parameters(),
                'out_column_suffix': form.cleaned_data['out_column_suffix'],
                'merge_key': form.cleaned_data['merge_key']})

        # Successful processing.
        return render(
            request,
            'dataops/plugin_execution_report.html',
            {'log_id': log_item.id})

    return render(
        request,
        'dataops/plugin_info_for_run.html',
        context={
            'form': form,
            'input_column_fields': [
                fld for fld in list(form)
                if fld.name.startswith(ONTASK_UPLOAD_FIELD_PREFIX + 'input')],
            'output_column_fields': [
                fld for fld in list(form)
                if fld.name.startswith(ONTASK_UPLOAD_FIELD_PREFIX + 'output')],
            'parameters': [
                fld for fld in list(form)
                if fld.name.startswith(
                    ONTASK_UPLOAD_FIELD_PREFIX + 'parameter')],
            'pinstance': plugin_instance,
            'id': workflow.id,
        })