Exemplo n.º 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')
Exemplo n.º 2
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')
Exemplo n.º 3
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')
Exemplo n.º 4
0
def create_comment(request):
	form = CommentForm(request.POST)
	if not form.is_valid():
		return HttpResponseBadRequest(nice_errors(form).as_ul())
	comment = form.save(commit=False)
	comment.content = comment.content.strip()
	comment.author = request.user
	comment.expiration_date = None if form.cleaned_data['expiration'] == 0 else timezone.now() + timedelta(days=form.cleaned_data['expiration'])
	comment.save()
	return redirect('tool_control')