def posts_edit(post_id): """POST route for user post edit. Doesn't change post.created_at or post.user""" tags = Tag.query.all() post = Post.query.get(post_id) if request.method == "GET": return render_template('posts/edit.html.j2', post=post, tags=tags, back=f'/posts/{post_id}') elif request.method == "POST": title = request.form["title"] content = request.form["content"] tags = request.form.getlist('tags') post.title = title post.content = content Tag.change_tags(post, tags) return redirect(f'/posts/{post_id}') else: return redirect(f'/users')
def posts_new(user_id): tags = Tag.query.all() user = User.query.get_or_404(user_id) if request.method == "GET": return render_template('posts/new.html.j2', user=user, tags=tags, back=f'/users/{user_id}') elif request.method == "POST": title = request.form["title"] content = request.form["content"] tags = request.form.getlist('tags') created_at = datetime.now().strftime('%A, %B %d, %Y') post = Post(title=title, content=content, created_at=created_at, user_id=user_id) Tag.change_tags(post, tags) return redirect(f'/posts/{post.id}') else: return redirect(f'/posts')