Пример #1
0
def delete_post_from_favorites(ctx: rest.Context,
                               params: Dict[str, str]) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:favorite')
    post = _get_post(params)
    favorites.unset_favorite(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Пример #2
0
def set_score(entity: model.Base, user: model.User, score: int) -> None:
    from szurubooru.func import favorites
    assert entity
    assert user
    if not score:
        delete_score(entity, user)
        try:
            favorites.unset_favorite(entity, user)
        except favorites.InvalidFavoriteTargetError:
            pass
        return
    if score not in (-1, 1):
        raise InvalidScoreValueError('Score %r is invalid. Valid scores: %r.' %
                                     (score, (-1, 1)))
    score_entity = _get_score_entity(entity, user)
    if score_entity:
        score_entity.score = score
        if score < 1:
            try:
                favorites.unset_favorite(entity, user)
            except favorites.InvalidFavoriteTargetError:
                pass
    else:
        table, get_column = _get_table_info(entity)
        score_entity = table()
        setattr(score_entity, get_column(table).name, get_column(entity))
        score_entity.score = score
        score_entity.user = user
        score_entity.time = datetime.datetime.utcnow()
        db.session.add(score_entity)
Пример #3
0
def delete_post_from_favorites(
        ctx: rest.Context, params: Dict[str, str]) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:favorite')
    post = _get_post(params)
    favorites.unset_favorite(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Пример #4
0
def set_score(entity, user, score):
    from szurubooru.func import favorites
    assert entity
    assert user
    if not score:
        delete_score(entity, user)
        try:
            favorites.unset_favorite(entity, user)
        except favorites.InvalidFavoriteTargetError:
            pass
        return
    if score not in (-1, 1):
        raise InvalidScoreValueError(
            'Score %r is invalid. Valid scores: %r.' % (score, (-1, 1)))
    score_entity = _get_score_entity(entity, user)
    if score_entity:
        score_entity.score = score
        if score < 1:
            try:
                favorites.unset_favorite(entity, user)
            except favorites.InvalidFavoriteTargetError:
                pass
    else:
        table, get_column = _get_table_info(entity)
        score_entity = table()
        setattr(score_entity, get_column(table).name, get_column(entity))
        score_entity.score = score
        score_entity.user = user
        score_entity.time = datetime.datetime.utcnow()
        db.session.add(score_entity)
Пример #5
0
def delete_post_from_favorites(ctx, params):
    auth.verify_privilege(ctx.user, 'posts:favorite')
    post = posts.get_post_by_id(params['post_id'])
    favorites.unset_favorite(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Пример #6
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:favorite')
     post = posts.get_post_by_id(post_id)
     favorites.unset_favorite(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)
Пример #7
0
 def delete(self, ctx, post_id):
     auth.verify_privilege(ctx.user, 'posts:favorite')
     post = posts.get_post_by_id(post_id)
     favorites.unset_favorite(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)