예제 #1
0
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"})
예제 #2
0
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
    )
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
def get_related_posts(post1):
    related_posts = Relation.objects(post1=post1).order_by("-similarity")[:4]
    return related_posts
예제 #6
0
def get_related_posts(post1):
    related_posts = Relation.objects(post1=post1).order_by("-similarity")[:4]
    return related_posts