Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
def approve_user_profile(update: Update, context: CallbackContext) -> None:
    _, user_id = update.callback_query.data.split(":", 1)

    user = User.objects.get(id=user_id)
    if user.moderation_status == User.MODERATION_STATUS_APPROVED:
        update.effective_chat.send_message(
            f"Пользователь «{user.full_name}» уже одобрен")
        update.callback_query.edit_message_reply_markup(reply_markup=None)
        return None

    if user.moderation_status == User.MODERATION_STATUS_REJECTED:
        update.effective_chat.send_message(
            f"Пользователь «{user.full_name}» уже был отклонен")
        update.callback_query.edit_message_reply_markup(reply_markup=None)
        return None

    user.moderation_status = User.MODERATION_STATUS_APPROVED
    user.created_at = datetime.utcnow()
    user.save()

    # make intro visible
    intro = Post.objects.filter(author=user, type=Post.TYPE_INTRO).first()
    intro.is_approved_by_moderator = True
    intro.is_visible = True
    intro.last_activity_at = datetime.utcnow()
    if not intro.published_at:
        intro.published_at = datetime.utcnow()
    intro.save()

    SearchIndex.update_user_index(user)

    notify_user_profile_approved(user)
    send_welcome_drink(user)
    announce_in_club_chats(intro)

    update.effective_chat.send_message(
        f"✅ Пользователь «{user.full_name}» одобрен ({update.effective_user.full_name})"
    )

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

    return None