Exemple #1
0
def edit_task(request):
    form = TaskForm(request.POST, project_id=request.POST['project'])
    if form.is_valid():

        t = Task.objects.get(pk=form.cleaned_data['pk'])
        t.name = form.cleaned_data['name']
        t.description = form.cleaned_data['description']
        t.start_date = form.cleaned_data['start_date']
        t.due_date = form.cleaned_data['due_date']
        t.date_complete = form.cleaned_data['date_complete']
        t.status_on_hold = form.cleaned_data['status_on_hold']
        t.status_waiting = form.cleaned_data['status_waiting']
        t.save()

        TaskWorker.objects.filter(task=t.pk).delete()
        for w in form.cleaned_data['worker']:
            tw = TaskWorker(
                task=Task.objects.get(pk=t.id),
                worker=Worker.objects.get(person=w, project=form.cleaned_data['project']),
            )
            tw.save()

        TaskDependency.objects.filter(blocked_task=t.pk).delete()
        if form.cleaned_data.get('blocked_by'):
            for d in form.cleaned_data['blocked_by']:
                td = TaskDependency(
                    blocking_task=d,
                    blocked_task=t,
                )
                td.save()

        return {'success': True}

    return {'failure': '%s' % form._errors}
Exemple #2
0
def create_task(request):
    pk = request.POST['project']
    form = TaskForm(request.POST, project_id=pk)
    if form.is_valid():

        # save task itself
        t = Task(
            project=form.cleaned_data['project'],
            name=form.cleaned_data['name'],
            description=form.cleaned_data['description'],
            start_date=form.cleaned_data['start_date'],
            due_date=form.cleaned_data['due_date'],
            status_on_hold=form.cleaned_data['status_on_hold'],
            status_waiting=form.cleaned_data['status_waiting'],)
        t.save()

        # save workers (note that "w" here is a Person, not a Worker)
        for w in form.cleaned_data['worker']:
            tw = TaskWorker(
                task=Task.objects.get(pk=t.id),
                worker=Worker.objects.get(person=w, project=form.cleaned_data['project']),
            )
            tw.save()

        # save dependencies
        for d in form.cleaned_data['blocked_by']:
            td = TaskDependency(
                blocking_task=d,
                blocked_task=Task.objects.get(pk=t.id)
            )
            td.save()

        return {'success': True}

    form_html = render_crispy_form(form, context=RequestContext(request))
    return {'success': False, 'form_html': form_html}