Example #1
0
 def put(self, ctx, comment_id):
     auth.verify_privilege(ctx.user, 'comments:score')
     score = ctx.get_param_as_int('score', required=True)
     comment = comments.get_comment_by_id(comment_id)
     scores.set_score(comment, ctx.user, score)
     ctx.session.commit()
     return comments.serialize_comment_with_details(comment, ctx.user)
Example #2
0
def set_post_score(ctx, params):
    auth.verify_privilege(ctx.user, 'posts:score')
    post = posts.get_post_by_id(params['post_id'])
    score = ctx.get_param_as_int('score', required=True)
    scores.set_score(post, ctx.user, score)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Example #3
0
def set_post_score(ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:score')
    post = _get_post(params)
    score = ctx.get_param_as_int('score')
    scores.set_score(post, ctx.user, score)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Example #4
0
def set_comment_score(ctx, params):
    auth.verify_privilege(ctx.user, 'comments:score')
    score = ctx.get_param_as_int('score', required=True)
    comment = comments.get_comment_by_id(params['comment_id'])
    scores.set_score(comment, ctx.user, score)
    ctx.session.commit()
    return _serialize(ctx, comment)
Example #5
0
 def put(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:score')
     post = posts.get_post_by_id(post_id)
     score = ctx.get_param_as_int('score', required=True)
     scores.set_score(post, ctx.user, score)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Example #6
0
def set_favorite(entity, user):
    try:
        scores.set_score(entity, user, 1)
    except scores.InvalidScoreTargetError:
        pass
    fav_entity = _get_fav_entity(entity, user)
    if not fav_entity:
        table, get_column = _get_table_info(entity)
        fav_entity = table()
        setattr(fav_entity, get_column(table).name, get_column(entity))
        fav_entity.user = user
        fav_entity.time = datetime.datetime.now()
        db.session.add(fav_entity)
Example #7
0
def set_favorite(entity: model.Base, user: Optional[model.User]) -> None:
    from szurubooru.func import scores
    assert entity
    assert user
    try:
        scores.set_score(entity, user, 1)
    except scores.InvalidScoreTargetError:
        pass
    fav_entity = _get_fav_entity(entity, user)
    if not fav_entity:
        table, get_column = _get_table_info(entity)
        fav_entity = table()
        setattr(fav_entity, get_column(table).name, get_column(entity))
        fav_entity.user = user
        fav_entity.time = datetime.utcnow()
        db.session.add(fav_entity)