Beispiel #1
0
def update(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    images_form = TaskImagesForm(request.POST, request.FILES)
    form = TaskForm(request.user, data=request.POST, instance=task)
    next_page = request.POST.get('next_page', 'tool_control')
    if not form.is_valid() or not images_form.is_valid():
        errors = nice_errors(form)
        errors.update(nice_errors(images_form))
        dictionary = {
            'title': 'Task update failed',
            'heading': 'Invalid task form data',
            'content': errors.as_ul(),
        }
        return render(request, 'acknowledgement.html', dictionary)
    form.save()
    set_task_status(request, task, request.POST.get('status'), request.user)
    determine_tool_status(task.tool)
    task_images = save_task_images(request, task)
    try:
        send_task_updated_email(
            task, request.build_absolute_uri(task.tool.get_absolute_url()),
            task_images)
    except Exception as error:
        site_title = get_customization('site_title')
        error_message = f"{site_title} was unable to send the task updated email. The error message that was received is: " + str(
            error)
        tasks_logger.exception(error_message)
        pass
    if next_page == 'maintenance':
        return redirect('maintenance')
    else:
        return redirect('tool_control')
Beispiel #2
0
def update(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    form = TaskForm(request.user, data=request.POST, instance=task)
    next_page = request.POST.get('next_page', 'tool_control')
    if not form.is_valid():
        dictionary = {
            'title': 'Task update failed',
            'heading': 'Invalid task form data',
            'content': str(form.errors),
        }
        return render(request, 'acknowledgement.html', dictionary)
    form.save()
    set_task_status(request, task, request.POST.get('status'), request.user)
    determine_tool_status(task.tool)
    try:
        send_task_updated_email(
            task, request.build_absolute_uri(task.tool.get_absolute_url()))
    except Exception as error:
        error_message = 'NEMO was unable to send the task updated email. The error message that NEMO received is: ' + str(
            error)
        tasks_logger.exception(error_message)
        pass
    if next_page == 'maintenance':
        return redirect('maintenance')
    else:
        return redirect('tool_control')
Beispiel #3
0
def update(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    images_form = TaskImagesForm(request.POST, request.FILES)
    form = TaskForm(request.user, data=request.POST, instance=task)
    next_page = request.POST.get('next_page', 'tool_control')
    if not form.is_valid() or not images_form.is_valid():
        errors = nice_errors(form)
        errors.update(nice_errors(images_form))
        dictionary = {
            'title': 'Task update failed',
            'heading': 'Invalid task form data',
            'content': errors.as_ul(),
        }
        return render(request, 'acknowledgement.html', dictionary)
    form.save()
    set_task_status(request, task, request.POST.get('status'), request.user)
    determine_tool_status(task.tool)
    task_images = save_task_images(request, task)
    send_task_updated_email(
        task, request.build_absolute_uri(task.tool.get_absolute_url()),
        task_images)
    if next_page == 'maintenance':
        return redirect('maintenance')
    else:
        return redirect('tool_control')
Beispiel #4
0
def create(request):
    """
	This function handles feedback from users. This could be a problem report or shutdown notification.
	"""
    images_form = TaskImagesForm(request.POST, request.FILES)
    form = TaskForm(request.user, data=request.POST)
    if not form.is_valid() or not images_form.is_valid():
        errors = nice_errors(form)
        errors.update(nice_errors(images_form))
        dictionary = {
            'title': 'Task creation failed',
            'heading': 'Something went wrong while reporting the problem',
            'content': errors.as_ul(),
        }
        return render(request, 'acknowledgement.html', dictionary)
    task = form.save()
    task_images = save_task_images(request, task)

    if not settings.ALLOW_CONDITIONAL_URLS and task.force_shutdown:
        site_title = get_customization('site_title')
        dictionary = {
            'title':
            'Task creation failed',
            'heading':
            'Something went wrong while reporting the problem',
            'content':
            f"Tool control is only available on campus. When creating a task, you can't force a tool shutdown while using {site_title} off campus.",
        }
        return render(request, 'acknowledgement.html', dictionary)

    if task.force_shutdown:
        # Shut down the tool.
        task.tool.operational = False
        task.tool.save()
        # End any usage events in progress for the tool or the tool's children.
        UsageEvent.objects.filter(tool_id__in=task.tool.get_family_tool_ids(),
                                  end=None).update(end=timezone.now())
        # Lock the interlock for this tool.
        try:
            tool_interlock = Interlock.objects.get(tool__id=task.tool.id)
            tool_interlock.lock()
        except Interlock.DoesNotExist:
            pass

    if task.safety_hazard:
        concern = 'This safety issue was automatically created because a ' + str(
            task.tool).lower(
            ) + ' problem was identified as a safety hazard.\n\n'
        concern += task.problem_description
        issue = SafetyIssue.objects.create(reporter=request.user,
                                           location=task.tool.location,
                                           concern=concern)
        send_safety_email_notification(request, issue)

    send_new_task_emails(request, task, task_images)
    set_task_status(request, task, request.POST.get('status'), request.user)
    return redirect('tool_control')
Beispiel #5
0
def update(request, task_id):
    task = get_object_or_404(Task, id=task_id)
    form = TaskForm(request.user, data=request.POST, instance=task)
    next_page = request.POST.get('next_page', 'tool_control')
    if not form.is_valid():
        dictionary = {
            'title': 'Task update failed',
            'heading': 'Invalid task form data',
            'content': str(form.errors),
        }
        return render(request, 'acknowledgement.html', dictionary)
    form.save()
    determine_tool_status(task.tool)
    if next_page == 'maintenance':
        return redirect('maintenance')
    else:
        return redirect('tool_control')