def update(request, pk): task = Task.objects.get(pk=pk) form = TaskForm(request.POST, instance=task) if form.is_valid(): form.save() return redirect(index) return render(request, 'app/app_display.html', {'task': task})
def task_display(request, pk): if request.method == 'POST': form = TaskForm(request.POST) user = request.user if request.user.is_authenticated else None if form.is_valid(): task = Task( tasklist_id = pk, description=request.POST['description'], created=timezone.now(), creator=user, ) task.save() return redirect('task:task_display', pk) task_list = get_object_or_404(TaskList, pk=pk) user = request.user if request.user.is_authenticated else None tasks = task_list.tasks.filter(creator=user) length = task_list.count() complete_length = task_list.count_complete() incomplete_length = task_list.count_incomplete() if length != 0: progress = round((complete_length/length)*100, 0) else: progress = 0 context = { 'task_list':task_list, 'tasks':tasks, 'len':length, 'complete':complete_length, 'incomplete':incomplete_length, 'progress':progress, 'form':TaskForm(), } return render(request, 'task/tasks.html', context)
def post(self, request, task_id): task = TaskModel.objects.get(pk=int(task_id)) form = TaskForm(request.POST, instance=task) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: return render(request, 'edit_task.html', {'form': form})
def post(self, request): form = TaskForm(request.POST) if form.is_valid(): task = form.save(commit=False) task.author = request.user task.save() return HttpResponseRedirect('/') else: return render(request, 'create_task.html', {'form': form})
def post(self, request): form = TaskForm(request.POST) if form.is_valid(): new_task = form.save() return JsonResponse({'task': model_to_dict(new_task)}, status=200) # model_to_dict is used to serialize python objects to json else: return redirect('task_list_url')
def post(self, request): form = TaskForm(request.POST) if form.is_valid(): # new_task is python object therefore we will have to first convert it into json serializable object new_task = form.save() return JsonResponse({'new_task': model_to_dict(new_task)}, status=200) else: return redirect('task_list')
def get(self, request): form = TaskForm() tasks = Task.objects.all() return render(request, 'task/task_list.html', { 'form': form, 'tasks': tasks })
def add_task(request, slug, milestone_slug): project_obj = Project.objects.get(slug=slug, organization=request.user.organization) if request.method == 'POST': add_task_dict = request.POST.copy() add_task_dict['project'] = project_obj.id json_data = {} add_task_form = TaskForm(add_task_dict, project=project_obj, user=request.user) if add_task_form.is_valid(): json_data['error'] = False task = add_task_form.save() task.order = project_obj.project_tickets.count() + 1 task.save() msg = "created " + task.name + " of milestone " + task.milestone.name create_timeline.send(sender=request.user, content_object=task, namespace=msg, event_type="task created", project=project_obj) try: msg = "task " + task.name + " is assigned to " + task.assigned_to.username create_timeline.send(sender=request.user, content_object=task.assigned_to, namespace=msg, event_type="task assigned", project=project_obj) except: pass return HttpResponse(json.dumps(json_data), content_type='application/json') else: json_data['error'] = True json_data['form_errors'] = add_task_form.errors return HttpResponse(json.dumps(json_data), content_type='application/json') else: milestone_list = project_obj.milestones.all() ticket_status_list = TicketStatus.objects.filter(project=project_obj).order_by('order') if not ticket_status_list: return HttpResponseRedirect(reverse("project:ticket_status",kwargs={'slug':slug})) assigned_to_list = [] for member in project_obj.members.all(): try: Role.objects.get(users__email=member.email, project=project_obj) assigned_to_list.append(member) except: pass milestone = project_obj.milestones.get(slug=milestone_slug) return render(request, 'task/add_task.html', {'ticket_status_list': ticket_status_list, 'assigned_to_list': assigned_to_list, 'slug': slug, 'milestone_list': milestone_list, 'milestone': milestone, 'notification_list': get_notification_list(request.user)})
def create(request): if request.method == 'POST': formTask = TaskForm(request.POST) if formTask.is_valid(): formTask.save() return redirect('home') else: formTask = TaskForm() return render(request, 'create.html', {'formTask': formTask})
def post(self, request, *args, **kwargs): form = TaskForm(request.POST) context = {"form": form} if not form.is_valid(): return redirect('index') else: form.is_valid() form.save() return redirect('index')
def index(request): if request.method == "GET": tasks_todo = Task.objects.filter(is_done=False) tasks_done = Task.objects.filter(is_done=True) context = { 'tasks_todo': tasks_todo, 'tasks_done': tasks_done, 'form': TaskForm, } return render(request, "index.html", context) if request.method == "POST": form = TaskForm(request.POST) if form.is_valid(): form.save() return redirect('/')
def edit(request, id): task = get_object_or_404(Task, pk=id) if request.method == 'POST': formTask = TaskForm(request.POST, instance=task) if formTask.is_valid(): formTask.save() return redirect('home') else: formTask = TaskForm(instance=task) return render(request, 'edit.html', {'formTask': formTask})
def submit(request): if request.method == "POST": form = TaskForm(request.POST) if form.is_valid(): try: form.save() redirect('/index') except: pass else: form = TaskForm() return render(request, 'app/app_index.html', {'form': form})
def taskview(request): task = Task.objects.all() if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): form.instance.user = request.user form.save() else: form = TaskForm() context = { 'task': task, 'form': form, } return render(request, 'task/list_task1.html', context)
def new_task(request): """Определяет новую задачу.""" if request.method != 'POST': # Данные не отправлялись; создается пустая форма. form = TaskForm() else: # Отправлены данные POST; обработать данные. form = TaskForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('mainMenu:tasks')) context = {'form': form} return render(request, 'mainMenu/new_task.html', context)
def edit_task(request, task_id): """Редактирует существующую запись.""" task = Task.objects.get(id=task_id) if request.method != 'POST': # Исходный запрос; форма заполняется данными текущей записи. form = TaskForm(instance=task) else: # Отправка данных POST; обработать данные. form = TaskForm(instance=task, data=request.POST) if form.is_valid(): form.save() return HttpResponseRedirect( reverse('mainMenu:task', args=[task.id])) context = {'task': task, 'form': form} return render(request, 'mainMenu/edit_task.html', context)
def info_edit(request, task_id): profile = request.user.profile workspace = profile.workspace task = apps.get_model('task', 'Task').objects.get(id=task_id, workspace=workspace) if request.method == 'POST': form = TaskForm(workspace, profile, request.POST, instance=task) if form.is_valid(): form.save() else: form = TaskForm(workspace, profile, instance=task) context = { 'form': form, 'form_action': reverse_lazy('task_info_edit', kwargs={'task_id': task_id}) } return render(request, 'dashboard/ajax_form.html', context)
def new(request): (context, some_data) = data_existence(request) profile = request.user.profile workspace = profile.workspace if request.method == 'POST': form = TaskForm(workspace, profile, request.POST) if form.is_valid(): new_task = form.save(commit=False) new_task.workspace = workspace new_task.save() return redirect(reverse_lazy('task_new')) else: form = TaskForm(workspace, profile, initial={'owner': profile.user.id}) context.update({'form': form, 'form_action': reverse_lazy('task_new')}) return render(request, 'dashboard/task_new.html', context)
def project_tasks(self): """Get tasks and task form for the project.""" tasks = self.object.task_set.all() identified = self.object.task_set.filter(status="Identified") inprogress = self.object.task_set.filter(status="In Progress") complete = self.object.task_set.filter(status="Complete") identified_ct = identified.count() inprogress_ct = inprogress.count() complete_ct = complete.count() form = TaskForm(organization=self.request.user.organization) return { 'tasks': tasks, 'identified': identified, 'inprogress': inprogress, 'complete': complete, 'identified_ct': identified_ct, 'inprogress_ct': inprogress_ct, 'complete_ct': complete_ct, 'form': form, }
def get_context_data(self, **kwargs): context = super(TaskListView, self).get_context_data(**kwargs) # appended the objects to the context dictionary (force) context['form'] = TaskForm() """ pass tasks in the ff form { 'story': [task1, task4, task6], 'to do': [task2, task3, task5], } """ task_data = None if self.request.user.is_authenticated: task_data = [] # iterate all status choices # for each choice, retrieve status_id and status_name # then append the choice to task_data to preserve order for choice in Task.STATUS_CHOICES: task_data.append( # choice[0] status_id, choice[1] status_name (choice[1], Task.objects.filter(status=choice[0])[:3])) context['task_data'] = task_data context['user'] = User return context
def taskedit(request, task_id): # Recuperamos la instancia de la persona instancia = InveraTask.objects.get(idTask=task_id) # Creamos el formulario con los datos de la instancia form = TaskForm(instance=instancia) # Comprobamos si se ha enviado el formulario if request.method == "POST": # Actualizamos el formulario con los datos recibidos form = TaskForm(request.POST, instance=instancia) # Si el formulario es válido... if form.is_valid(): # Guardamos el formulario pero sin confirmarlo, # así conseguiremos una instancia para manejarla instanciatask = form.save(commit=False) # Podemos guardarla cuando queramos instanciatask.save() # Redireccionamos si el formulario es valido return HttpResponseRedirect(reverse('task')) # return HttpResponseRedirect(reverse('detailobj', kwargs={'objdetail_id':id_datos_ed})) # Si llegamos al final renderizamos el formulario return render(request, "taskedit.html", {'form': form})