示例#1
0
def tasks_edit(request, pk):
    task = get_object_or_404(Task, pk=pk)
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save(commit=False)
            task.task_modified_by_user_id = request.user
            # adapt starting and finishing time corresponding to taskstatus
            if task.taskstatus == Taskstatus.objects.get(
                    taskstatus_name="Pending"):
                task.task_started_time = None
                task.task_finished_time = None
            elif task.taskstatus == Taskstatus.objects.get(
                    taskstatus_name="Working"):
                task.task_started_time = timezone.now()
                task.task_finished_time = None
            elif task.taskstatus == Taskstatus.objects.get(
                    taskstatus_name="Done"):
                task.task_finished_time = timezone.now()
                if task.task_started_time == None:
                    task.task_started_time = timezone.now()
            task.save()
            form.save_m2m()
            task.logger(str(request.user), " TASK_EDIT_EXECUTED")
            messages.success(request, 'Task edited')
            return redirect('/tasks/' + str(task.task_id))
    else:
        form = TaskForm(instance=task)
        task.logger(str(request.user), " TASK_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/task/tasks_edit.html',
                  {'form': form})
示例#2
0
def tasks_add(request):
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            task = form.save(commit=False)
            task.task_created_by_user_id = request.user
            task.task_modified_by_user_id = request.user
            # adapt starting and finishing time corresponding to taskstatus
            if task.taskstatus == Taskstatus.objects.get(
                    taskstatus_name="Working"):
                task.task_started_time = timezone.now()
            elif task.taskstatus == Taskstatus.objects.get(
                    taskstatus_name="Done"):
                task.task_started_time = timezone.now()
                task.task_finished_time = timezone.now()
            task.save()
            form.save_m2m()
            task.logger(str(request.user), " TASK_ADD_EXECUTED")
            messages.success(request, 'Task added')
        if 'system' in request.GET:
            system = request.GET['system']
            return redirect('/systems/' + str(system))
        else:
            return redirect('/tasks/' + str(task.task_id))
    else:
        if request.method == 'GET' and 'system' in request.GET:
            system = request.GET['system']
            form = TaskForm(
                initial={
                    'system': system,
                    'taskpriority': 2,
                    'taskstatus': 1,
                    'task_scheduled_time': timezone.now(),
                    'task_due_time': timezone.now(),
                })
        else:
            form = TaskForm(
                initial={
                    'taskpriority': 2,
                    'taskstatus': 1,
                    'task_scheduled_time': timezone.now(),
                    'task_due_time': timezone.now(),
                })
        debug_logger(str(request.user), " TASK_ADD_ENTERED")
    return render(request, 'dfirtrack_main/task/tasks_add.html',
                  {'form': form})
示例#3
0
def tasks_edit(request, pk):
    task = get_object_or_404(Task, pk=pk)
    if request.method == 'POST':
        form = TaskForm(request.POST, instance=task)
        if form.is_valid():
            task = form.save(commit=False)
            task.task_modified_by_user_id = request.user
            task.save()
            form.save_m2m()
            task.logger(str(request.user), " TASK_EDIT_EXECUTED")
            messages.success(request, 'Task edited')
            return redirect('/tasks/' + str(task.task_id))
    else:
        form = TaskForm(instance=task)
        task.logger(str(request.user), " TASK_EDIT_ENTERED")
    return render(request, 'dfirtrack_main/task/tasks_edit.html',
                  {'form': form})