Example #1
0
def edit_task(request, id, id2):
    project = Project.objects.get(pk=id2)
    task = Task.objects.get(pk=id, project=project)
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data['project'] = project
            if datetime.strptime(data['start_date'], '%Y-%m-%d').date(
            ) >= project.start_date and datetime.strptime(
                    data['end_date'], '%Y-%m-%d').date() <= project.end_date:
                Task.objects.filter(pk=id,
                                    project=data['project']).update(**data)
                return redirect('list_tasks', id2)
            else:
                messages.add_message(request, messages.WARNING,
                                     'Fechas no validas.')
                return redirect('edit_task', id, id2)
        else:
            messages.add_message(request, messages.WARNING,
                                 'Informacion no valida.')
            return redirect('edit_task', id, id2)
    else:
        form = TaskForm()
        return render(request, 'calendar/edit_task.html', {
            'task': task,
            'project': project,
            'form': form,
        })
Example #2
0
def edit_task(request, id):
    task = Task.objects.get(id=id)
    if not request.user.is_superuser and request.user != task.assigned_to:
        return HttpResponseForbidden('Access denied')

    if request.method == 'POST':
        form = ProjectTaskForm(request.POST,
                               project_id=task.project.id,
                               instance=task)
        project = Project.objects.get(id=task.project.id)
        if form.is_valid():
            task = form.save(commit=False)
            task.author = request.user
            task.project = project
            task.save()
            messages.add_message(
                request, messages.INFO,
                'Task "{}" was successfully updated in project "{}"'.format(
                    task.title, task.project))
            return redirect(reverse('tasks:tasks'))

    else:
        form = ProjectTaskForm(project_id=task.project.id, instance=task)

    context = {'task': task, 'form': form}
    return render(request, 'tasks/edit_task.html', context)
def add_task(request, project_id):
    """
        view to display the form to add a new task
    """
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            form.instance.user_id = request.user.id
            form.instance.project_id = project_id
            form.save()
            forhandler(request.FILES.getlist('file[]'), project_id,
                       form.instance.id, request)
            #redirect to home after successful save
            #return HttpResponseRedirect('/')
            return HttpResponseRedirect(
                reverse(
                    'projects.views.task_detail',
                    kwargs={
                        'task_id': form.instance.id,
                    },
                ))
        else:
            context = {'form': form}
            return render_to_response('add_task.html',
                                      context,
                                      context_instance=RequestContext(request))
    else:
        return render_to_response('add_task.html', {
            'form': TaskForm(),
            'project_id': project_id
        },
                                  context_instance=RequestContext(request))
Example #4
0
def add_task(request, id):

    project = Project.objects.get(pk=id)
    if request.method == 'POST':
        form = TaskForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            data['project'] = project
            if not Task.objects.filter(project=project,
                                       name=data['name']).__len__():
                if datetime.strptime(data['start_date'], '%Y-%m-%d').date(
                ) >= project.start_date and datetime.strptime(
                        data['end_date'],
                        '%Y-%m-%d').date() <= project.end_date:
                    Task.objects.create(**data)
                    return redirect('list_tasks', id)
                else:
                    messages.add_message(request, messages.WARNING,
                                         'Fechas no validas.')
                    return redirect('add_task', id)
            else:
                messages.add_message(request, messages.WARNING,
                                     'Ya existe este task.')
                return redirect('add_task', id)
        else:
            messages.add_message(request, messages.WARNING,
                                 'Informacion no valida.')
            return redirect('add_task', id)
    else:
        form = TaskForm()
        return render(request, 'calendar/add_task.html', {
            'id': id,
            'form': form,
        })
Example #5
0
def task_create(request, project_id):
	try:
		project = Project.objects.get(id=project_id)
	except Project.DoesNotExist:
		return HttpResponseNotFound('<h1>Project not found</h1>')

	if request.method == "POST" and request.is_ajax():
		print(request.POST)
		form = TaskForm(request.POST)
		if form.is_valid():
			p = Task(projectId=project,
				title=form.cleaned_data['title'],
				type=form.cleaned_data['type'],
				deadline=form.cleaned_data['deadline'],
				description=form.cleaned_data['description'],
				createdBy = request.user)
			p.save(True,False)
			__assign_person(p, request)
			return HttpResponse(json.dumps({"status":"OK","id":p.id}))
		else:
			errors_fields = dict()
			if form.errors:
				errors_fields["fields"] = list(form.errors.keys())
			return HttpResponseBadRequest(json.dumps(errors_fields), content_type="application/json")
	else:
		template = loader.get_template('task_write.html')
		context = RequestContext(request, get_context({
			'new_task': True,
			'taskTypes': Task.TASK_TYPES,
			'data_page_type': 'tasks',
			'project_id': project_id,
			'people_to_assign': getAssignablePeople(request,project.id)
		}, request))
		return HttpResponse(template.render(context))
Example #6
0
def save(request, project_id, task_id=False):
    """
    Shows latest activity and other usefull info
    """
    t = 'projects/task/form.html'
    response_vars = {}
    project = Project.objects.get(id=project_id)

    parent = None
    kwargs = {}
    kwargs['project'] = project

    if task_id:
        task = Task.objects.get(id=task_id)
        form = TaskForm(instance=task)
        parent = task.parent
    else:
        task = Task()
        form = TaskForm(**kwargs)

        if request.GET.has_key('parent') and request.GET['parent']:
            parent = Task.objects.get(id=request.GET['parent'])

    if request.method == 'POST':
        form = TaskForm(request.POST, **kwargs)
        if form.is_valid():
            if task_id:
                form = TaskForm(request.POST, instance=Task.objects.get(id=task_id))
                task = form.save(commit=False)
            else:
                task = form.save(commit=False)
                task.project = project
                task.parent  = parent

            task.assignor = request.user

            task.save()

            return HttpResponseRedirect(reverse('projects.views.task.index', args=[project.id]))


    response = { }
    response_vars['request']      = request
    response_vars['project']      = project
    response_vars['form']         = form
    response_vars['task']         = task
    response_vars['parent']       = parent

    return render_project(request, project_id, t, response_vars)
Example #7
0
 def post(self, request):
     form = TaskForm(request.POST)
     if form.is_valid():
         creator = form.cleaned_data['creator']
         assigned_to = form.cleaned_data['assigned_to']
         name = form.cleaned_data['name']
         description = form.cleaned_data['description']
         status = form.cleaned_data['status']
         story = form.cleaned_data['story']
         Task.objects.create(creator=creator,
                             assigned_to=assigned_to,
                             name=name,
                             description=description,
                             status=status,
                             story=story)
         return HttpResponseRedirect(reverse('task_list'))
Example #8
0
def __task_edit( task, request):
	print(request.POST)
	filesToRemove = request.POST["filesToRemove"]
	# personResponsibleID = request.POST["personResponsibleId"]
	form = TaskForm(request.POST)
	if form.is_valid():
		task.title = form.cleaned_data['title']
		task.type = form.cleaned_data['type']
		task.deadline = form.cleaned_data['deadline']
		task.description = form.cleaned_data['description']
		task.createdBy = request.user
		task.save(False,True)
		__assign_person(task,request)
		# remove composites TODO not tested
		# File.objects.filter(taskId=task).filter(id__in=filesToRemove).delete()
		return True, {}
	else:
		return False, list(form.errors.keys()) if form.errors else None
def add_task(request, project_id):
    """
        view to display the form to add a new task
    """
    if request.method == "POST":
        form = TaskForm(request.POST)
        if form.is_valid():
            form.instance.user_id = request.user.id
            form.instance.project_id = project_id
            form.save()
            forhandler(request.FILES.getlist('file[]'), project_id, form.instance.id, request)
            #redirect to home after successful save
            #return HttpResponseRedirect('/')
            return HttpResponseRedirect(
                reverse('projects.views.task_detail',
                        kwargs={'task_id': form.instance.id, },
                        ))
        else:
            context = {'form': form}
            return render_to_response('add_task.html', context, context_instance=RequestContext(request))
    else:
        return render_to_response('add_task.html', {'form': TaskForm(), 'project_id': project_id}, context_instance=RequestContext(request))