Exemplo n.º 1
0
def run_email_done(
    request: HttpRequest,
    action_info: Optional[EmailPayload] = None,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Create the log object, queue the operation request and render done.

    :param request: HTTP request (GET)
    :param action_info: Dictionary containing all the required parameters. If
    empty, the dictionary is taken from the session.
    :return: HTTP response
    """
    # Get the payload from the session if not given
    action_info = get_or_set_action_info(request.session,
                                         EmailPayload,
                                         action_info=action_info)
    if action_info is None:
        # Something is wrong with this execution. Return to action table.
        messages.error(request, _('Incorrect email action invocation.'))
        return redirect('action:index')

    # Get the information from the payload
    action = workflow.actions.filter(pk=action_info['action_id']).first()
    if not action:
        return redirect('home')

    # Log the event
    log_item = Log.objects.register(
        request.user, Log.SCHEDULE_EMAIL_EXECUTE, action.workflow, {
            'action': action.name,
            'action_id': action.id,
            'from_email': request.user.email,
            'subject': action_info['subject'],
            'cc_email': action_info['cc_email'],
            'bcc_email': action_info['bcc_email'],
            'send_confirmation': action_info['send_confirmation'],
            'track_read': action_info['track_read'],
            'exported_workflow': action_info['export_wf'],
            'exclude_values': action_info['exclude_values'],
            'item_column': action_info['item_column'],
            'status': 'Preparing to execute',
        })

    # Update the last_execution_log
    action.last_executed_log = log_item
    action.save()

    # Send the emails!
    run_task.delay(request.user.id, log_item.id, action_info.get_store())

    # Reset object to carry action info throughout dialogs
    set_action_payload(request.session)
    request.session.save()

    # Successful processing.
    return render(request, 'action/action_done.html', {
        'log_id': log_item.id,
        'download': action_info['export_wf']
    })
Exemplo n.º 2
0
def zip_action(
    req: HttpRequest,
    pk: int,
    workflow: Optional[Workflow] = None,
    action: Optional[Action] = None,
) -> HttpResponse:
    """Request data to create a zip file.

    Form asking for participant column, user file name column, file suffix,
    if it is a ZIP for Moodle and confirm users step.

    :param req: HTTP request (GET)
    :param pk: Action key
    :return: HTTP response
    """
    # Get the payload from the session, and if not, use the given one
    action_info = get_or_set_action_info(req.session,
                                         ZipPayload,
                                         initial_values={
                                             'action_id':
                                             action.id,
                                             'prev_url':
                                             reverse('action:zip_action',
                                                     kwargs={'pk': action.id}),
                                             'post_url':
                                             reverse('action:zip_done'),
                                         })

    # Create the form to ask for the email subject and other information
    form = ZipActionForm(
        req.POST or None,
        column_names=[col.name for col in workflow.columns.all()],
        action=action,
        form_info=action_info,
    )

    if req.method == 'POST' and form.is_valid():
        if action_info['confirm_items']:
            # Add information to the session object to execute the next pages
            action_info['button_label'] = ugettext('Create ZIP')
            action_info['valuerange'] = 2
            action_info['step'] = 2
            set_action_payload(req.session, action_info.get_store())

            return redirect('action:item_filter')

        # Go straight to the final step.
        return run_zip_done(req, action_info=action_info, workflow=workflow)

    # Render the form
    return render(
        req, 'action/action_zip_step1.html', {
            'action': action,
            'num_msgs': action.get_rows_selected(),
            'form': form,
            'valuerange': range(2)
        })
Exemplo n.º 3
0
def run_email_action(
    req: HttpRequest,
    workflow: Workflow,
    action: Action,
) -> HttpResponse:
    """Request data to send emails.

    Form asking for subject line, email column, etc.
    :param req: HTTP request (GET)
    :param workflow: workflow being processed
    :param action: Action being run
    :return: HTTP response
    """
    # Get the payload from the session, and if not, use the given one
    action_info = get_or_set_action_info(req.session,
                                         EmailPayload,
                                         initial_values={
                                             'action_id':
                                             action.id,
                                             'prev_url':
                                             reverse('action:run',
                                                     kwargs={'pk': action.id}),
                                             'post_url':
                                             reverse('action:email_done')
                                         })

    # Create the form to ask for the email subject and other information
    form = EmailActionForm(req.POST or None,
                           column_names=[
                               col.name
                               for col in workflow.columns.filter(is_key=True)
                           ],
                           action=action,
                           form_info=action_info)

    # Request is a POST and is valid
    if req.method == 'POST' and form.is_valid():
        if action_info['confirm_items']:
            # Add information to the session object to execute the next pages
            action_info['button_label'] = ugettext('Send')
            action_info['valuerange'] = 2
            action_info['step'] = 2
            set_action_payload(req.session, action_info.get_store())

            return redirect('action:item_filter')

        # Go straight to the final step.
        return run_email_done(req, action_info=action_info, workflow=workflow)

    # Render the form
    return render(
        req, 'action/request_email_data.html', {
            'action': action,
            'num_msgs': action.get_rows_selected(),
            'form': form,
            'valuerange': range(2)
        })
Exemplo n.º 4
0
def action_zip_export(
    request: HttpRequest,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Create a zip with the personalised text and return it as response.

    :param request: Request object with a Dictionary with all the required
    information
    :return: Response (download)
    """
    # Get the payload from the session if not given
    action_info = get_or_set_action_info(request.session, ZipPayload)
    if not action_info:
        # Something is wrong with this execution. Return to action table.
        messages.error(request, _('Incorrect ZIP action invocation.'))
        return redirect('action:index')

    # Get the information from the payload
    action = workflow.actions.filter(pk=action_info['action_id']).first()
    if not action:
        return redirect('home')

    # Create the file name template
    if action_info['zip_for_moodle']:
        file_name_template = ('{user_fname}_{part_id}_assignsubmission_file_')
    else:
        if action_info['user_fname_column']:
            file_name_template = '{part_id}_{user_fname}_'
        else:
            file_name_template = '{part_id}'
    if action_info['file_suffix']:
        file_name_template += action_info['file_suffix']
    else:
        file_name_template += 'feedback.html'

    # Create the ZIP with the eval data tuples and return it for download
    sbuf = create_zip(
        create_eval_data_tuple(
            action,
            action_info['item_column'],
            action_info['exclude_values'],
            action_info['user_fname_column'],
        ), action_info['zip_for_moodle'], file_name_template)

    # Reset object to carry action info throughout dialogs
    set_action_payload(request.session)
    request.session.save()

    return create_response(sbuf)
Exemplo n.º 5
0
def run_json_done(
    request: HttpRequest,
    action_info: Optional[JSONPayload] = None,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Create the log object, queue the operation request, render DONE page.

    :param request: HTTP request (GET)

    :param action_info: Dictionary containing all the required parameters. If
    empty, the dictionary is taken from the session.

    :return: HTTP response
    """
    # Get the payload from the session if not given
    action_info = get_or_set_action_info(request.session,
                                         JSONPayload,
                                         action_info=action_info)
    if action_info is None:
        # Something is wrong with this execution. Return to action table.
        messages.error(request, _('Incorrect JSON action invocation.'))
        return redirect('action:index')

    # Get the information from the payload
    action = workflow.actions.filter(pk=action_info['action_id']).first()
    if not action:
        return redirect('home')

    # Log the event
    log_item = action.log(request.user,
                          Log.ACTION_RUN_JSON,
                          exclude_values=action_info['exclude_values'],
                          item_column=action_info['item_column'],
                          exported_workflow=action_info['export_wf'])

    # Send the objects
    run_task.delay(request.user.id, log_item.id, action_info.get_store())

    # Reset object to carry action info throughout dialogs
    set_action_payload(request.session)
    request.session.save()

    # Successful processing.
    return render(request, 'action/action_done.html', {
        'log_id': log_item.id,
        'download': action_info['export_wf']
    })
Exemplo n.º 6
0
def run_zip_done(
    request: HttpRequest,
    action_info: Optional[ZipPayload] = None,
    workflow: Optional[Workflow] = None,
) -> HttpResponse:
    """Create the zip object, send it for download and render the DONE page.

    :param request: HTTP request (GET)
    :param action_info: Dictionary containing all the required parameters. If
    empty, the dictionary is taken from the session.
    :return: HTTP response
    """
    # Get the payload from the session if not given
    action_info = get_or_set_action_info(request.session,
                                         ZipPayload,
                                         action_info=action_info)
    if action_info is None:
        # Something is wrong with this execution. Return to action table.
        messages.error(request, _('Incorrect ZIP action invocation.'))
        return redirect('action:index')

    # Get the information from the payload
    action = workflow.actions.filter(pk=action_info['action_id']).first()
    if not action:
        return redirect('home')

    # Log the event
    log_item = Log.objects.register(
        request.user, Log.DOWNLOAD_ZIP_ACTION, action.workflow, {
            'action': action.name,
            'action_id': action.id,
            'user_fname_column': action_info['user_fname_column'],
            'item_column': action_info['item_column'],
            'file_suffix': action_info['file_suffix'],
            'zip_for_moodle': action_info['zip_for_moodle'],
            'exclude_values': action_info['exclude_values'],
        })

    # Store the payload in the session for the download part
    set_action_payload(request.session, action_info.get_store())

    # Successful processing.
    return render(request, 'action/action_zip_done.html', {})
Exemplo n.º 7
0
def run_canvas_email_action(
    req: WSGIRequest,
    workflow: Workflow,
    action: Action,
) -> HttpResponse:
    """Request data to send JSON objects.

    Form asking for subject, item column (contains ids to select unique users),
    confirm items (add extra step to drop items), export workflow and
    target_rul (if needed).

    :param req: HTTP request (GET)
    :param workflow: workflow being processed
    :param action: Action begin run
    :return: HTTP response
    """
    # Get the payload from the session, and if not, use the given one
    action_info = get_or_set_action_info(
        req.session,
        CanvasEmailPayload,
        initial_values={
            'action_id': action.id,
            'prev_url': reverse('action:run', kwargs={'pk': action.id}),
            'post_url': reverse('action:canvas_email_done'),
        },
    )

    # Create the form to ask for the email subject and other information
    form = CanvasEmailActionForm(
        req.POST or None,
        column_names=[
            col.name for col in workflow.columns.filter(is_key=True)
        ],
        action=action,
        form_info=action_info)

    if req.method == 'POST' and form.is_valid():
        # Request is a POST and is valid

        if action_info['confirm_items']:
            # Create a dictionary in the session to carry over all the
            # information to execute the next pages
            action_info['button_label'] = ugettext('Send')
            action_info['valuerange'] = 2
            action_info['step'] = 2
            set_action_payload(req.session, action_info.get_store())
            continue_url = 'action:item_filter'
        else:
            continue_url = 'action:canvas_email_done'

        # Check for the CANVAS token and proceed to the continue_url
        return canvas_get_or_set_oauth_token(req, action_info['target_url'],
                                             continue_url)

    # Render the form
    return render(
        req, 'action/request_canvas_email_data.html', {
            'action': action,
            'num_msgs': action.get_rows_selected(),
            'form': form,
            'valuerange': range(2),
            'rows_all_false': action.get_row_all_false_count()
        })