def add_task(request): if request.POST: form = TaskForm(request.POST) args = {} args['name'] = request.POST.get('name') args['project'] = request.POST.get('project') if form.is_valid(): task = form.save(commit=False) task.status = False task.save() args['id'] = task.id return render_to_response('task.html', args)
def post(self, request, project_id, manager_id): response = {'project_id': project_id, 'manager_id': manager_id} form = TaskForm(request.POST) if form.is_valid(): task = form.save(commit=False) task.project_id = project_id task.employee_id = request.POST.get('employee_id') task.save() return render(request, 'project/createtask.html') else: response['form'] = form return render(request, 'project/createtask.html', response)
def task_handler(request, pk): """ Task handler for creating, deleting and updating the task . """ task_form = TaskForm(pk) if request.method == 'POST': task_form = TaskForm(pk, request.POST or None) if task_form.is_valid(): task = task_form.save(commit=False) task.id_project = Project.objects.get(id_project=pk) task_form.save() messages.success(request, 'The task was added to the unfinished section.', extra_tags='alert') return redirect('/projects/{}/tasks'.format(pk)) finished_tasks = Task.objects.filter(id_project=pk, finish=True).order_by('-important') unfinished_tasks = Task.objects.filter(id_project=pk, finish=False).order_by('-important') context = { 'task_form': task_form, 'finished_tasks': finished_tasks, 'unfinished_tasks': unfinished_tasks, 'project_pk': pk, 'update': False, } return render(request, 'project/task_form.html', context)
def get(self, request, project_id, manager_id): response = {'project_id': project_id, 'manager_id': manager_id} response['employees'] = User.objects.filter(role="employee", createdby=manager_id) response['form'] = TaskForm() response['form'].fields['project'].widget = forms.HiddenInput() response['tasks'] = Task.objects.filter(project_id=project_id) return render(request, 'project/task.html', response)
def task_update(request, id): date_error = "" myproject = Project.objects.all().filter(user=request.user) data = {} task = Task.objects.get(id=id) if request.method == 'POST': form = TaskForm(request.POST, instance=task) if form.is_valid(): project = form.cleaned_data['project'] due_date = form.cleaned_data['due_date'] start_date = form.cleaned_data['start_date'] pro = Project.objects.get(id=str(project)) if Task.objects.all().filter( Q( Q(project__endDate__lt=due_date) | Q(project__endDate__lt=start_date)) & Q(user=request.user)): date_error = "Check your start date and your due date! " \ + "the project start on the " + str( pro.startDate) + " and end on the " + str(pro.endDate) else: ta = form.save(commit=False) ta.save() form.save_m2m() task = Task.objects.all().filter(user=request.user) project_task = Project.objects.all().filter(user=request.user) context = { 'tasks': 'active', 'task': task, 'id': 0, 'project': project_task } data['form_is_valid'] = True data['sms'] = 'Your Task was successfully updated!' data['project_task'] = render_to_string('tasks/taskList.html', context, request=request) return JsonResponse(data) else: form = TaskForm(instance=task) context = { 'myproject': myproject, 'task': task, 'mydate': date_error, 'user': User.objects.all(), 'form': form } data['html_form'] = render_to_string('tasks/task_edit.html', context, request=request) return JsonResponse(data)
def task_edit(request, id): temp_name = "headers/testcase-header.html" obj = get_object(task, id=id) if request.method == 'POST': form = TaskForm(request.POST, instance=obj) print form.is_valid() if form.is_valid(): try: form.save() status = 1 except: status = 2 else: status = 2 print status else: form = TaskForm(instance=obj) return render(request, "task/task_edit.html", locals())
def update_task(request, pk): """ Update a specific task. """ instance = Task.objects.get(id_task=pk) project = instance.id_project task_form = TaskForm(project.id_project, request.POST or None, instance=instance) if task_form.is_valid(): task_form.save() messages.success(request, 'The task was updated.', extra_tags='alert') return redirect('/projects/{}/tasks'.format(project.id_project)) finished_tasks = Task.objects.filter(id_project=project.id_project, finish=True) unfinished_tasks = Task.objects.filter(id_project=project.id_project, finish=False) context = { 'task_form': task_form, 'finished_tasks': finished_tasks, 'unfinished_tasks': unfinished_tasks, 'project_pk': project.id_project, 'update': True, } return render(request, 'project/task_form.html', context)
def task_add(request): temp_name = "headers/project-header.html" if request.method == "POST": print "post" task_form = TaskForm(request.POST) if task_form.is_valid(): task_form.save() tips = u"增加成功!" display_control = "" else: tips = u"增加失败!" display_control = "" return render(request, "task/task_add.html", locals()) else: print "get" display_control = "none" task_form = TaskForm() return render(request, "task/task_add.html", locals())
def task_create(request): name_error = "" date_error = "" context = {} data = {} data['form_is_valid'] = False myproject = Project.objects.all().filter(user=request.user) user = User.objects.all() if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] project = form.cleaned_data['project'] due_date = form.cleaned_data['due_date'] start_date = form.cleaned_data['start_date'] pro = Project.objects.get(id=str(project)) if Task.objects.all().filter( Q(user=request.user) & Q() & Q(name=name) & Q(project=project)): name_error = "This Task exist already in that project" elif Task.objects.all().filter( Q( Q(project__endDate__lt=due_date) | Q(project__endDate__lt=start_date)) & Q(user=request.user)): date_error = "Check your start date and your due date! " \ + "the project start on the " + str( pro.startDate) + " and end on the " + str(pro.endDate) else: ta = form.save(commit=False) ta.user = request.user ta.save() form.save_m2m() task = Task.objects.all().filter(user=request.user) project_task = Project.objects.all().filter(user=request.user) context = { 'tasks': 'active', 'task': task, 'id': 0, 'project': project_task } data['form_is_valid'] = True data['sms'] = 'Your Task was successfully added!' data['project_task'] = render_to_string('tasks/taskList.html', context, request=request) return JsonResponse(data) else: form = TaskForm() context = { 'myproject': myproject, 'myname': name_error, 'mydate': date_error, 'user': user, 'form': form } data['html_form'] = render_to_string('tasks/task_create.html', context, request=request) return JsonResponse(data)