def show(id): if not g.db.doc_exist(id): abort(404) errors = [] task = Task.get(id) form = CommentForm(request.form) comments = list(Comment.view('comments/by_task_id', key=id)) comments = sorted(comments, key=lambda x: x.date) if request.method == 'POST' and form.validate(): new_comment = Comment() new_comment.author = session['username'] new_comment.text = form.text.data new_comment.date = datetime.datetime.utcnow() new_comment.task_id = id new_comment.save() flash('Comment was successfully added') return redirect(url_for('tasks.show', id=id)) fpath = os.path.join(UPLOADED_FILES, id) files = None if os.path.exists(fpath): files = os.listdir(fpath) errors.extend(format_form_errors(form.errors.items())) return render_template('task_show.html', \ task = task, comments = comments, form = form, errors = errors, \ files = files)
def show(id): if not g.db.doc_exist(id): abort(404) errors = [] task = Task.get(id) form = CommentForm(request.form) comments = list(Comment.view('comments/by_task_id', key = id)) comments = sorted(comments, key = lambda x: x.date) if request.method == 'POST' and form.validate(): new_comment = Comment() new_comment.author = session['username'] new_comment.text = form.text.data new_comment.date = datetime.datetime.utcnow() new_comment.task_id = id new_comment.save() flash('Comment was successfully added') return redirect(url_for('tasks.show', id = id)) fpath = os.path.join(UPLOADED_FILES, id) files = None if os.path.exists(fpath): files = os.listdir(fpath) errors.extend(format_form_errors(form.errors.items())) return render_template('task_show.html', \ task = task, comments = comments, form = form, errors = errors, \ files = files)