def add_task(): """! Обработчик маршрута страницы добавления активности/задачи пользователя (edit_profile). @return Страницу add_task.html. """ form = AddTaskForm() if form.validate_on_submit(): task = form.task.data description = form.description.data start = datetime.utcnow() user_id = current_user.id t = Task.query.filter_by(task=task).first() if t is not None: flash('Такая задача уже существует') return redirect(url_for('add_task')) db.session.add( Task(task=task, description=description, start=start, user_id=user_id)) db.session.commit() return redirect(url_for('user', username=current_user.username)) return render_template('add_task.html', title='Добавить задачу', form=form)
def user_task(user_name): form = AddTaskForm() if form.validate_on_submit(): task = Task(content=form.content.data, owner=current_user) db.session.add(task) db.session.commit() flash('Your task was added') return redirect(url_for('user_task', user_name=current_user.username)) tasks = Task.query.filter_by(user_id=current_user.id).order_by(Task.timestamp).all() return render_template('user_task.html', title='{}s task'.format(current_user.username), form=form, tasks=tasks)
def index(): form = AddTaskForm() if form.validate_on_submit(): task = Task(description=form.description.data, goal=form.goal.data, owner=current_user, progress=0) db.session.add(task) db.session.commit() return redirect(url_for('index')) tasks = current_user.tasks.all() return render_template("index.html", title='Home Page', tasks=tasks, form=form)
def index(): add_task = AddTaskCase() add_task.repo = repo form = AddTaskForm() all_tasks = repo.get_all_tasks() if form.validate_on_submit(): result = add_task.create( header=form.header.data, body=form.body.data, done=form.done.data, ) flash(f"Task created : {result}") return redirect("/") return render_template("home.html", form=form, tasks=all_tasks)
def task_add(project_id): if not current_user.is_anonymous: form = AddTaskForm() if form.validate_on_submit(): order_value = Task.query.filter_by(project_id=project_id).count() task = Task(title=form.title.data, project_id=project_id, due_date=form.due_date.data, completed=False, order=order_value + 1) db.session.add(task) db.session.commit() flash('Project added successfully!') return redirect(url_for('project', project_id=project_id)) project_list = Project.query.filter_by(user_id=current_user.id).all() return render_template('task_add.html', form=form, projects=project_list) return redirect(url_for('login'))