def get(self, id): post = Post.objects.get_or_404(id=id) Post.objects(id=id).update_one(inc__views=1) return render_template('posts/detail.html', post=post, Markdown=Markdown, gen_author=gen_author, gen_author_name=gen_author_name, short_timesince=short_timesince)
def post(self): ref_id = request.form.get('ref_id', 0) content = request.form.get('content') author = User.objects.get_or_404(id=current_user.id) c = Comment(ref_id=ref_id, content=content, author=author) c.save() context = Post.objects(id=int(ref_id)) if not context: context = Comment.objects(id=int(ref_id)) if not context: return jsonify(ok=1, msg='not exists') else: context = context[0] context.comments.append(c) context.save() return jsonify(ok=0)
def get(self, id): context = self.get_context(id) Post.objects(id=id).update_one(inc__views=1) return render_template('posts/detail.html', **context)
def get(self, id): post = Post.objects.get_or_404(id=id) Post.objects(id=id).update_one(inc__views=1) return render_template('posts/detail.html', post=post)