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 post(self): args = post_reqparse.parse_args() new_todo = Task(task=args['task'], timeOver=args['timeOver'], uid=g.current_user.id) if 'description' in args: new_todo.description = args['description'] db.session.add(new_todo) db.session.commit() todo = Task.query.filter_by(uid=g.current_user.id).first() data = todo_schema(todo) return {'status': 0, 'message': 'succeed', 'data': data}
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 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 create_task(user): session = db_session.create_session() data = request.get_json() title, priority, date = data["title"], data["priority"], data[ "scheduled_date"] if not isinstance(priority, int) or priority not in range(1, 5): return make_response( jsonify({ "message": "Priority field must be an integer in range from 1 to 4!" }), 400) try: date = datetime.datetime.strptime(date, "%Y-%m-%d") except: return make_response( jsonify({"message": "time data do not match format: YYYY-MM-DD"}), 400) # Привести к единому формату даты task = Task(title=title, priority=priority, scheduled_date=date, user_id=user.id) session.add(task) session.commit() return jsonify({'message': 'New task created!'})
def save_new(self, body: str, user_id: int) -> Task: new_task = Task( msg_user_id=user_id, text=body, ) self.db.add(new_task) self.db.commit() return new_task
def new_task(): form = TaskForm() if form.validate_on_submit(): task = Task(item=form.item.data, category=form.category.data, start_date=form.start_date.data, end_date=form.end_date.data, owner=current_user) db.session.add(task) db.session.commit() flash("Your task has been created!", "success") return redirect(url_for("tasks.todo")) return render_template("create_task.html", title="New Task", form=form)
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 update_task(request): task = json.loads(request.body.decode('utf-8')) error_msg = Task.validate(task) if error_msg: return HttpResponseBadRequest(error_msg) try: t = Task.objects.get(id=task['id']) except ObjectDoesNotExist: return HttpResponse(json.dumps('object does not exists')) t.name = task['name'] t.priority = task['priority'] year, month, day = map(int, task['finish_date'].split('-')) t.finish_date = datetime.date(year, month, day) t.finished = task['finished'] t.save() return HttpResponse(json.dumps('task updated.'), content_type='application/json')
def add_task(form, user): db_sess = db_session.create_session() # Изменяем дату формы на выбранную в календаре date = request.form.get("calendar") form.scheduled_date.data = date tasks = Task() tasks.title = form.title.data.strip() tasks.priority = form.priority.data tasks.scheduled_date = datetime.strptime(form.scheduled_date.data, "%Y-%m-%d") tasks.user_id = user.id db_sess.add(tasks) db_sess.commit()
def add_task(project_id): """ Add task to project :param project_id: project's id :return: start page with new task """ name = request.form.get('task_title') status = False priority = Task.query.filter_by( project_id=project_id).count() - Task.query.filter_by( status=True, project_id=project_id).count() + 1 update_priority_done(project_id) new_task = Task(name=name, status=status, priority=priority, project_id=project_id) db.session.add(new_task) db.session.commit() return redirect(url_for('index'))
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)
def addNewTask(request): task_title = request.POST.get("task_title", " ") task_due_on = request.POST.get("task_due_on", " ") task = Task.create(task_title, task_due_on, request.session['username']) task.save() return todolist(request)