def new_task(): tasks = Task.query.filter_by(author=current_user).all() if len(tasks) >= 50: flash('You can not add more than 50 tasks', 'danger') return redirect(url_for('home')) else: form = TaskForm() if form.validate_on_submit(): file = None if form.file.data: file = save_picture(form.file.data) task = Task(title=form.title.data, content=form.content.data, author=current_user, due_date=form.due_date.data, completion=form.completion.data, completion_date=form.completion_date.data, attachment=file) print('lol : ', file) db.session.add(task) db.session.commit() flash('Your task has been created!', 'success') return redirect(url_for('home')) return render_template('create_task.html', title='New Task', form=form, legend='New Task')
def update_task(task_id): task = Task.query.get_or_404(task_id) if task.author != current_user: abort(403) form = TaskForm() if form.validate_on_submit(): task.title = form.title.data task.content = form.content.data db.session.commit() flash('Your task has been updated!', 'success') return redirect(url_for('task', task_id=task.id)) elif request.method == 'GET': form.title.data = task.title form.content.data = task.content return render_template('create_task.html', title='Update Task', form=form, legend='Update Task')