def delete_post(): post_data = json.loads(request.data) post_id = post_data["postId"] post = Post.objects(id=post_id).first() author = User.objects(username=current_user.username).first() if post.author != author: return json.dumps({"status": "not-allowed"}) Relation.objects(post1=post).delete() Relation.objects(post2=post).delete() Post.objects(id=post_id).delete() return json.dumps({"status": "success"})
def single_post(seq, slug): seq = int(seq) user = get_user() post = Post.objects(seq=seq).first() related_posts = Relation.objects(post1=post).order_by("-similarity")[:3] return render_template( 'single.html', user=user, post=post, related_posts=related_posts )
def after_tagging_calculation(post1): """ Arguments: - `post1`: tag added to this post """ relation = Relation.objects(post1=post1) if post1.post_type == "pdf": return None for r in relation: category_point = get_category_point(r.post1, r.post2) r.similarity += category_point r.save() relation = Relation.objects(post2=post1) for r in relation: category_point = get_category_point(r.post1, r.post2) r.similarity += category_point r.save()
def get_related_posts(post1): related_posts = Relation.objects(post1=post1).order_by("-similarity")[:4] return related_posts