def index(request): #the index view todos = Task.objects.all() # quering all todos with the object manager categories = Category.objects.all( ) # getting all categories with object manager if request.method == "GET": return render(request, "todolist/index.html", { "todos": todos, "categories": categories }) if request.method == "POST": # checking if the request method is a POST if "taskAdd" in request.POST: # checking if there is a request to add a todo title = request.POST["description"] # title date = str(request.POST["date"]) # date category = request.POST["category_select"] # category content = title + " -- " + date + " " + category # content Todo = Task(title=title, content=content, due_date=date, category=Category.objects.get(name=category)) Todo.save() return redirect("/") # reloading the page if "taskDelete" in request.POST: #checking if there is a request to delete a todo checkedlist = request.POST[ "checkedbox"] # checked todos to be deleted for todo_id in checkedlist: todo = Task.objects.get(id=int(todo_id)) # getting todo id todo.delete() # deleting todo return render(request, "todolist/index.html", { "todos": todos, "categories": categories })
def add(request): if request.method == "POST": task_name = request.POST['task'] new_task = Task() new_task.name = task_name new_task.completed = False new_task.save() return redirect('/todolist')
def todolist(request): context = {'success': False} if request.method == "POST": title = request.POST['title'] desc = request.POST['desc'] ins = Task(taskTitle=title, taskDesc=desc) ins.save() context = {'success': True} return render(request, 'index.html', context)
def add_task(request, pk): if request.method == 'POST': if 'task' in str(request.POST): task_form = NewTask(request.POST, prefix='task') if task_form.is_valid(): board_obj = get_object_or_404(Board, pk=pk) task = Task(name=task_form.cleaned_data['task_name'], status=False, board=board_obj) task.save() return HttpResponseRedirect( request.META.get('HTTP_REFERER', '/')) return HttpResponseNotFound
def add_task(request): new_task = json.loads(request.body.decode('utf-8')) error_msg = Task.validate(new_task) if error_msg: return HttpResponseBadRequest(error_msg) t = Task(project_id=new_task['project_id'], name=new_task['name'], priority=new_task['priority'], finished=False) year, month, day = map(int, new_task['finish_date'].split('-')) t.finish_date = datetime.date(year, month, day) t.save() return HttpResponse(t.to_json())
def task(request, id): # Add task if request.method == 'POST': try: new_task = Task(owner=request.user, text=request.POST["text"], priority=request.POST["priority"], completed=0) new_task.save() task = {"text": request.POST["text"], "priority": request.POST["priority"], "completed": 0, "id": new_task.id} return JsonResponse({'error': 'false', 'task': task}) except Exception as e: return JsonResponse({'error': 'true', 'errorMessage': e}) # Update task elif request.method == 'PATCH': try: task = get_object_or_404(Task, id=id) if task.owner == request.user: body_unicode = request.body.decode('utf-8') body = json.loads(body_unicode) task.text = body["text"] task.save() return JsonResponse({'error': 'false'}) else: return JsonResponse({'error': 'true', 'errorMessage': 'Permission Denied'}) except Exception as e: return JsonResponse({'error': 'true', 'errorMessage': e}) # Delete task elif request.method == 'DELETE': try: task = get_object_or_404(Task, id=id) if task.owner == request.user: task.delete() return JsonResponse({'error': 'false'}) else: return JsonResponse({'error': 'true', 'errorMessage': 'Permission Denied'}) except Exception as e: return JsonResponse({'error': 'true', 'errorMessage': e})
def add_task(request): if request.method == 'POST': form = NewTaskForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass parentID = form.cleaned_data['parentID'] taskName = form.cleaned_data['taskName'] p = Project.objects.get(id=parentID) t = Task(name=taskName, project=p, ddl="1970-01-01") t.save() resp = {} resp['parentID'] = parentID resp['id'] = t.id resp['name'] = t.name return HttpResponse(json.dumps(resp), mimetype="application/json")
def index(request): if request.method == 'POST': task = Task() form = AddTask(request.POST) if form.is_valid(): task.content = request.POST['new_task'] task.user = request.user task.save() all_task = Task.objects.filter(user__exact=request.user) form = AddTask() context = { 'all_task': all_task, 'form': form, } return render(request, 'index.html', context=context)