Beispiel #1
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}» уже одобрен")
        return None

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

    user.moderation_status = User.MODERATION_STATUS_APPROVED
    user.save()

    # make intro visible
    Post.objects\
        .filter(author=user, type=Post.TYPE_INTRO)\
        .update(is_visible=True, published_at=datetime.utcnow(), is_approved_by_moderator=True)

    SearchIndex.update_user_index(user)

    notify_user_profile_approved(user)
    send_welcome_drink(user)

    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
Beispiel #2
0
def edit_profile(request, user_slug):
    if user_slug == "me":
        return redirect("edit_profile", request.me.slug, permanent=False)

    user = get_object_or_404(User, slug=user_slug)
    if user.id != request.me.id and not request.me.is_moderator:
        raise Http404()

    if request.method == "POST":
        form = UserEditForm(request.POST, request.FILES, instance=user)
        if form.is_valid():
            user = form.save(commit=False)
            user.save()

            SearchIndex.update_user_index(user)
            Geo.update_for_user(user)

            return redirect("profile", user.slug)
    else:
        form = UserEditForm(instance=user)

    return render(request, "users/edit/profile.html", {
        "form": form,
        "user": user
    })
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()
        indexed_comment_count = 0
        indexed_post_count = 0
        indexed_user_count = 0

        for chunk in chunked_queryset(
            Comment.visible_objects().filter(is_deleted=False, post__is_visible=True)
        ):
            for comment in chunk:
                self.stdout.write(f"Indexing comment: {comment.id}")
                SearchIndex.update_comment_index(comment)
                indexed_comment_count += 1

        for chunk in chunked_queryset(
            Post.visible_objects().filter(is_shadow_banned=False)
        ):
            for post in chunk:
                self.stdout.write(f"Indexing post: {post.slug}")
                SearchIndex.update_post_index(post)
                indexed_post_count += 1

        for chunk in chunked_queryset(
            User.objects.filter(moderation_status=User.MODERATION_STATUS_APPROVED)
        ):
            for user in chunk:
                self.stdout.write(f"Indexing user: {user.slug}")
                SearchIndex.update_user_index(user)
                SearchIndex.update_user_tags(user)
                indexed_user_count += 1

        self.stdout.write(
            f"Done 🥙 "
            f"Comments: {indexed_comment_count} Posts: {indexed_post_count} Users: {indexed_user_count}"
        )
Beispiel #4
0
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()

        for comment in Comment.visible_objects().filter(is_deleted=False,
                                                        post__is_visible=True):
            self.stdout.write(f"Indexing comment: {comment.id}")
            SearchIndex.update_comment_index(comment)

        for post in Post.visible_objects().filter(is_shadow_banned=False):
            self.stdout.write(f"Indexing post: {post.slug}")
            SearchIndex.update_post_index(post)

        for user in User.objects.filter(is_profile_complete=True,
                                        is_profile_reviewed=True,
                                        is_profile_rejected=False):
            self.stdout.write(f"Indexing user: {user.slug}")
            SearchIndex.update_user_index(user)

        self.stdout.write("Done 🥙")
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()

        for comment in Comment.visible_objects().filter(is_deleted=False,
                                                        post__is_visible=True):
            self.stdout.write(f"Indexing comment: {comment.id}")
            SearchIndex.update_comment_index(comment)

        for post in Post.visible_objects().filter(is_shadow_banned=False):
            self.stdout.write(f"Indexing post: {post.slug}")
            SearchIndex.update_post_index(post)

        for user in User.objects.filter(
                moderation_status=User.MODERATION_STATUS_APPROVED):
            self.stdout.write(f"Indexing user: {user.slug}")
            SearchIndex.update_user_index(user)
            SearchIndex.update_user_tags(user)

        self.stdout.write("Done 🥙")
Beispiel #6
0
def approve_user_profile(user_id: str, update: Update) -> (str, bool):
    user = User.objects.get(id=user_id)
    if user.is_profile_reviewed and user.is_profile_complete:
        return f"Пользователь «{user.full_name}» уже одобрен", True

    user.is_profile_complete = True
    user.is_profile_reviewed = True
    user.is_profile_rejected = False
    user.save()

    # make intro visible
    Post.objects\
        .filter(author=user, type=Post.TYPE_INTRO)\
        .update(is_visible=True, published_at=datetime.utcnow(), is_approved_by_moderator=True)

    SearchIndex.update_user_index(user)

    notify_user_profile_approved(user)
    send_welcome_drink(user)

    return f"✅ Пользователь «{user.full_name}» одобрен ({update.effective_user.full_name})", True
Beispiel #7
0
def approve_user_profile(user_id: str, update: Update) -> (str, bool):
    user = User.objects.get(id=user_id)
    if user.moderation_status == User.MODERATION_STATUS_APPROVED:
        return f"Пользователь «{user.full_name}» уже одобрен", True

    if user.moderation_status == User.MODERATION_STATUS_REJECTED:
        return f"Пользователь «{user.full_name}» уже отклонен", True

    user.moderation_status = User.MODERATION_STATUS_APPROVED
    user.save()

    # make intro visible
    Post.objects\
        .filter(author=user, type=Post.TYPE_INTRO)\
        .update(is_visible=True, published_at=datetime.utcnow(), is_approved_by_moderator=True)

    SearchIndex.update_user_index(user)

    notify_user_profile_approved(user)
    send_welcome_drink(user)

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