Beispiel #1
0
def approve_post(update: Update, context: CallbackContext) -> None:
    _, post_id = update.callback_query.data.split(":", 1)

    post = Post.objects.get(id=post_id)
    if post.is_approved_by_moderator:
        update.callback_query.answer()
        update.message.reply_text(f"Пост «{post.title}» уже одобрен")
        return

    post.is_approved_by_moderator = True
    post.last_activity_at = datetime.utcnow()
    if not post.published_at:
        post.published_at = datetime.utcnow()
    post.save()

    notify_post_author_approved(post)
    announce_in_club_chats(post)

    post_url = settings.APP_HOST + reverse("show_post", kwargs={
        "post_type": post.type,
        "post_slug": post.slug,
    })

    update.effective_chat.send_message(
        f"👍 Пост «{post.title}» одобрен ({update.effective_user.full_name}): {post_url}"
    )

    # hide buttons
    update.callback_query.edit_message_reply_markup(reply_markup=None)

    return None
Beispiel #2
0
def approve_post(post_id: str, update: Update) -> (str, bool):
    post = Post.objects.get(id=post_id)
    if post.is_approved_by_moderator:
        return f"Пост «{post.title}» уже одобрен", True

    post.is_approved_by_moderator = True
    post.last_activity_at = datetime.utcnow()
    post.published_at = datetime.utcnow()
    post.save()

    notify_post_author_approved(post)
    announce_in_club_chats(post)

    announce_post_url = settings.APP_HOST + reverse("announce_post", kwargs={
        "post_slug": post.slug,
    })

    return f"👍 Пост «{post.title}» одобрен ({update.effective_user.full_name}). " \
           f"Можно запостить его на канал вот здесь: {announce_post_url}", True