Beispiel #1
0
def index(request: HttpRequest) -> HttpResponse:
    """Shows list of podcasts: if user has subscriptions,
    show most recently updated, otherwise show promoted podcasts"""

    subscriptions: List[int]

    if request.user.is_anonymous:
        subscriptions = []
    else:
        subscriptions = list(
            request.user.subscription_set.values_list("podcast", flat=True))

    if request.turbo.frame:
        podcasts = Podcast.objects.filter(pub_date__isnull=False).distinct()

        # user's subscribed podcasts

        if subscriptions:
            podcasts = podcasts.filter(
                pk__in=subscriptions).order_by("-pub_date")

            return render_paginated_response(
                request,
                podcasts,
                "podcasts/_podcast_list.html",
            )

        # return promoted list, same as landing_page

        podcasts = Podcast.objects.filter(pub_date__isnull=False,
                                          promoted=True).order_by("-pub_date")

        return render_paginated_response(
            request,
            podcasts,
            "podcasts/_podcast_list_cached.html",
            {"cache_timeout": settings.DEFAULT_CACHE_TIMEOUT},
        )

    top_rated_podcasts = not (subscriptions) and not (request.search)

    return TemplateResponse(
        request,
        "podcasts/index.html",
        {
            "top_rated_podcasts": top_rated_podcasts,
            "search_url": reverse("podcasts:search_podcasts"),
        },
    )
Beispiel #2
0
def category_detail(request: HttpRequest,
                    category_id: int,
                    slug: Optional[str] = None):
    category: Category = get_object_or_404(
        Category.objects.select_related("parent"), pk=category_id)

    if request.turbo.frame:

        podcasts = category.podcast_set.filter(pub_date__isnull=False)

        if request.search:
            podcasts = podcasts.search(request.search).order_by(
                "-rank", "-pub_date")
        else:
            podcasts = podcasts.order_by("-pub_date")

        return render_paginated_response(
            request,
            podcasts,
            "podcasts/_podcast_list_cached.html",
            {"cache_timeout": settings.DEFAULT_CACHE_TIMEOUT},
        )

    return TemplateResponse(
        request,
        "podcasts/category.html",
        {
            "category": category,
            "children": category.children.order_by("name")
        },
    )
Beispiel #3
0
def index(request: HttpRequest) -> HttpResponse:
    if request.turbo.frame:
        favorites = Favorite.objects.filter(user=request.user).select_related(
            "episode", "episode__podcast")
        if request.search:
            favorites = favorites.search(request.search).order_by(
                "-rank", "-created")
        else:
            favorites = favorites.order_by("-created")

        return render_paginated_response(
            request, favorites, "episodes/favorites/_episode_list.html")

    return TemplateResponse(request, "episodes/favorites/index.html")
Beispiel #4
0
def search_podcasts(request: HttpRequest) -> HttpResponse:

    if not request.search:
        return redirect("podcasts:index")

    if request.turbo.frame:
        podcasts = (Podcast.objects.filter(pub_date__isnull=False).search(
            request.search).order_by("-rank", "-pub_date"))
        return render_paginated_response(
            request,
            podcasts,
            "podcasts/_podcast_list_cached.html",
            {"cache_timeout": settings.DEFAULT_CACHE_TIMEOUT},
        )

    return TemplateResponse(request, "podcasts/search.html")
Beispiel #5
0
def index(request: HttpRequest) -> HttpResponse:

    if request.turbo.frame:

        logs = (AudioLog.objects.filter(user=request.user).select_related(
            "episode", "episode__podcast").order_by("-updated"))

        if request.search:
            logs = logs.search(request.search).order_by("-rank", "-updated")
        else:
            logs = logs.order_by("-updated")

        return render_paginated_response(
            request, logs, "episodes/history/_episode_list.html")

    return TemplateResponse(request, "episodes/history/index.html")
Beispiel #6
0
def podcast_episodes(request: HttpRequest,
                     podcast_id: int,
                     slug: Optional[str] = None) -> HttpResponse:

    podcast = get_podcast_or_404(podcast_id)
    ordering: Optional[str] = request.GET.get("ordering")

    if request.turbo.frame:

        # thumbnail will be same for all episodes, so just preload
        # it once here

        episodes = podcast.episode_set.select_related("podcast")

        if request.search:
            episodes = episodes.search(request.search).order_by(
                "-rank", "-pub_date")
        else:
            order_by = "pub_date" if ordering == "asc" else "-pub_date"
            episodes = episodes.order_by(order_by)

        return render_paginated_response(
            request,
            episodes,
            "episodes/_episode_list_cached.html",
            {
                "cache_timeout":
                settings.DEFAULT_CACHE_TIMEOUT,
                "podcast_image":
                podcast.get_cover_image_thumbnail(),
                "podcast_url":
                reverse("podcasts:podcast_detail",
                        args=[podcast.id, podcast.slug]),
            },
        )

    return render_podcast_detail_response(
        request,
        "podcasts/detail/episodes.html",
        podcast,
        {
            "ordering": ordering,
        },
    )