Exemple #1
0
def set_featured_post(ctx: rest.Context,
                      _params: Dict[str, str] = {}) -> rest.Response:
    auth.verify_privilege(ctx.user, 'posts:feature')
    post_id = ctx.get_param_as_int('id')
    post = posts.get_post_by_id(post_id)
    featured_post = posts.try_get_featured_post()
    if featured_post and featured_post.post_id == post.post_id:
        raise posts.PostAlreadyFeaturedError('짤 %r 는 이미 대문짤임.' % post_id)
    posts.feature_post(post, ctx.user)
    snapshots.modify(post, ctx.user)
    ctx.session.commit()
    return _serialize_post(ctx, post)
Exemple #2
0
 def post(self, ctx):
     auth.verify_privilege(ctx.user, 'posts:feature')
     post_id = ctx.get_param_as_int('id', required=True)
     post = posts.get_post_by_id(post_id)
     featured_post = posts.try_get_featured_post()
     if featured_post and featured_post.post_id == post.post_id:
         raise posts.PostAlreadyFeaturedError(
             'Post %r is already featured.' % post_id)
     posts.feature_post(post, ctx.user)
     if featured_post:
         snapshots.save_entity_modification(featured_post, ctx.user)
     snapshots.save_entity_modification(post, ctx.user)
     ctx.session.commit()
     return posts.serialize_post_with_details(post, ctx.user)