コード例 #1
0
def blocked_user_list_view(request):
    return render_paginated_queryset(
        request,
        get_member_queryset(request, exclude_blocking_users=False).filter(
            blockers=request.user).order_by("name", "username"),
        "users/list/blocked.html",
    )
コード例 #2
0
ファイル: views.py プロジェクト: danjac/localhub
def invite_list_view(request):
    invites = get_invite_queryset(request).order_by("-created")
    total_count = invites.count()

    status = request.GET.get("status")
    status_display = None

    if total_count == 0 or status not in Invite.Status.values:
        status = None
    if status:
        status_display = dict(Invite.Status.choices)[status]
        invites = invites.filter(status=status)

    if request.search:
        invites = invites.filter(email__icontains=request.search)

    return render_paginated_queryset(
        request,
        invites,
        "invites/invite_list.html",
        {
            "status": status,
            "status_display": status_display,
            "status_choices": list(Invite.Status.choices),
            "total_count": total_count,
        },
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #3
0
def join_request_list_view(request):

    join_reqs = get_join_request_queryset(request)
    total_count = join_reqs.count()

    status = request.GET.get("status")
    status_display = None

    if total_count == 0 or status not in JoinRequest.Status.values:
        status = None

    if status:
        status_display = dict(JoinRequest.Status.choices)[status]
        join_reqs = join_reqs.filter(status=status).order_by("-created")
    else:
        join_reqs = join_reqs.annotate(priority=Case(
            When(status=JoinRequest.Status.PENDING, then=Value(1)),
            default_value=0,
            output_field=IntegerField(),
        )).order_by("priority", "-created")

    if request.search:
        join_reqs = join_reqs.search(request.search)

    return render_paginated_queryset(
        request,
        join_reqs,
        "join_requests/joinrequest_list.html",
        {
            "status": status,
            "status_display": status_display,
            "status_choices": list(JoinRequest.Status.choices),
            "total_count": total_count,
        },
    )
コード例 #4
0
def following_user_list_view(request):
    return render_paginated_queryset(
        request,
        get_member_queryset(request).filter(followers=request.user).order_by(
            "name", "username"),
        "users/list/following.html",
    )
コード例 #5
0
ファイル: views.py プロジェクト: danjac/localhub
def received_invite_list_view(request):
    invites = get_recipient_invite_queryset(request).order_by("-created")
    return render_paginated_queryset(
        request,
        invites,
        "invites/received_invite_list.html",
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #6
0
ファイル: views.py プロジェクト: danjac/localhub
def render_tag_list(request, tags, template_name):
    return render_paginated_queryset(
        request,
        tags,
        template_name,
        {"content_warnings": request.community.get_content_warnings()},
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #7
0
def member_list_view(request):

    qs = get_member_queryset(request)
    if request.search:
        qs = qs.search(request.search).order_by("-rank")
    else:
        qs = qs.order_by("name", "username")

    return render_paginated_queryset(request, qs, "users/list/members.html")
コード例 #8
0
ファイル: views.py プロジェクト: danjac/localhub
def membership_list_view(request):
    members = get_membership_queryset(request).order_by(
        "member__name", "member__username")
    if request.search:
        members = members.search(request.search)
    return render_paginated_queryset(
        request,
        members,
        "communities/membership_list.html",
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #9
0
def sent_join_request_list_view(request):
    """
    List of pending join requests sent by this user
    """

    return render_paginated_queryset(
        request,
        JoinRequest.objects.for_sender(
            request.user).select_related("community").order_by("-created"),
        "join_requests/sent_joinrequest_list.html",
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #10
0
ファイル: views.py プロジェクト: danjac/localhub
def bookmarks_comment_list_view(request):
    comments = (Comment.objects.for_community(
        request.community).with_common_annotations(
            request.user,
            request.community).exclude_blocked_users(request.user).
                exclude_deleted().with_common_related().bookmarked(
                    request.user).with_bookmarked_timestamp(request.user))
    if request.search:
        comments = comments.search(request.search)
        ordering = ("-rank", "-bookmarked")
    else:
        ordering = ("-bookmarked", "-created")

    comments = comments.order_by(*ordering)

    return render_paginated_queryset(request, comments,
                                     "bookmarks/comments.html")
コード例 #11
0
ファイル: views.py プロジェクト: danjac/localhub
def notification_list_view(request):
    qs = (get_notification_queryset(request).exclude_blocked_actors(
        request.user).prefetch_related("content_object").select_related(
            "actor", "content_type", "community",
            "recipient").order_by("is_read", "-created"))

    return render_paginated_queryset(
        request,
        qs,
        "notifications/notification_list.html",
        {
            "is_unread_notifications": qs.filter(is_read=False).exists(),
            "webpush_settings": {
                "public_key": settings.VAPID_PUBLIC_KEY,
                "enabled": settings.WEBPUSH_ENABLED,
            },
        },
        page_size=settings.LONG_PAGE_SIZE,
    )
コード例 #12
0
ファイル: views.py プロジェクト: danjac/localhub
def bookmarks_message_list_view(request):
    messages = (Message.objects.for_community(
        request.community).for_sender_or_recipient(
            request.user).common_select_related().bookmarked(
                request.user).with_bookmarked_timestamp(
                    request.user).distinct())

    if request.search:
        messages = messages.search(request.search)
        ordering = ("-rank", "-bookmarked")
    else:
        ordering = ("-bookmarked", "-created")

    messages = messages.order_by(*ordering)

    return render_paginated_queryset(
        request,
        messages,
        "bookmarks/messages.html",
    )
コード例 #13
0
ファイル: views.py プロジェクト: danjac/localhub
def liked_comment_list_view(request):
    comments = (get_comment_queryset(request).liked(
        request.user).with_common_annotations(
            request.user, request.community).with_liked_timestamp(
                request.user).order_by("-liked", "-created"))
    return render_paginated_queryset(request, comments, "likes/comments.html")
コード例 #14
0
@login_required
@community_required
def inbox_view(request):
    messages = (Message.objects.for_community(
        community=request.community).with_has_bookmarked(
            request.user).for_recipient(request.user).exclude_blocked(
                request.user).common_select_related())
    if search := request.GET.get("q"):
        messages = messages.search(search).order_by("-rank", "-created")
    else:
        messages = messages.order_by(
            F("read").desc(nulls_first=True), "-created")

    return render_paginated_queryset(
        request,
        messages,
        "private_messages/inbox.html",
        {"search": search},
    )


@login_required
@community_required
def outbox_view(request):
    messages = (Message.objects.for_community(
        community=request.community).with_has_bookmarked(
            request.user).for_sender(request.user).exclude_blocked(
                request.user).common_select_related())
    if search := request.GET.get("q"):
        messages = messages.search(search).order_by("-rank", "-created")
    else:
        messages = messages.order_by("-created")
コード例 #15
0
ファイル: views.py プロジェクト: danjac/localhub
def photo_gallery_view(request):
    photos = (Photo.objects.for_community(
        request.community).published_or_owner(request.user).exclude_blocked(
            request.user).filter(parent__isnull=True).order_by(
                "-created", "-published"))
    return render_paginated_queryset(request, photos, "photos/gallery.html")
コード例 #16
0
ファイル: views.py プロジェクト: danjac/localhub
def community_list_view(request):
    qs = Community.objects.accessible(request.user).order_by("name")
    if request.search:
        qs = qs.filter(name__icontains=request.search)

    if request.user.is_authenticated:

        communities = Community.objects.filter(
            membership__member=request.user,
            membership__active=True).exclude(pk=request.community.id)

        users = (get_user_model().objects.filter(is_active=True).exclude(
            pk__in=request.user.blocked.all()))

        flags = dict(
            communities.filter(membership__role__in=(
                Membership.Role.ADMIN,
                Membership.Role.MODERATOR,
            )).annotate(num_flags=Count("flag", distinct=True)).values_list(
                "id", "num_flags"))
        join_requests = dict(
            communities.filter(
                membership__role=Membership.Role.ADMIN).annotate(
                    num_join_requests=Count(
                        "joinrequest",
                        filter=Q(
                            joinrequest__status=JoinRequest.Status.PENDING),
                        distinct=True,
                    )).values_list("id", "num_join_requests"))
        messages = dict(
            communities.annotate(num_messages=Count(
                "message",
                filter=Q(
                    message__recipient=request.user,
                    message__read__isnull=True,
                    message__sender__pk__in=users,
                    message__sender__membership__active=True,
                    message__sender__membership__community=F("pk"),
                ),
                distinct=True,
            )).values_list("id", "num_messages"))
        notifications = dict(
            communities.annotate(num_notifications=Count(
                "notification",
                filter=Q(
                    notification__recipient=request.user,
                    notification__is_read=False,
                    notification__actor__pk__in=users,
                    notification__actor__membership__active=True,
                    notification__actor__membership__community=F("pk"),
                ),
                distinct=True,
            )).values_list("id", "num_notifications"))

    else:
        flags = {}
        join_requests = {}
        messages = {}
        notifications = {}

    return render_paginated_queryset(
        request,
        qs,
        "communities/community_list.html",
        {
            "counters": {
                "flags": flags,
                "join_requests": join_requests,
                "messages": messages,
                "notifications": notifications,
            },
            "roles": dict(Membership.Role.choices),
        },
    )
コード例 #17
0
        queryset = queryset.search(search)

    if isinstance(ordering, str):
        ordering = [ordering]
    else:
        ordering = list(ordering)
    if search:
        ordering = ["-rank"] + ordering

    queryset = queryset.order_by(*ordering)

    return render_paginated_queryset(
        request,
        queryset,
        template_name,
        {
            "model": queryset.model,
            **(extra_context or {}),
        },
    )


def handle_activity_create(
    request,
    model,
    form_class,
    template_name,
    *,
    is_private=False,
    extra_context=None,
    **form_kwargs,