Skip to content

Commit

Permalink
refactor: remove template-partials dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
danjac committed Aug 29, 2024
1 parent dbac4d4 commit 8c0c4cd
Show file tree
Hide file tree
Showing 34 changed files with 472 additions and 572 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies = [
"django-model-utils",
"django-permissions-policy",
"django-redis",
"django-template-partials",
"django-version-checks",
"gunicorn",
"heroicons[django]",
Expand Down
2 changes: 1 addition & 1 deletion radiofeed/episodes/templatetags/audio_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_media_metadata(context: RequestContext, episode: Episode) -> dict:
}


@register.inclusion_tag("episodes/detail.html#audio_player", takes_context=True)
@register.inclusion_tag("episodes/_audio_player.html", takes_context=True)
def audio_player(context: RequestContext) -> dict:
"""Renders audio player if audio log in current session."""

Expand Down
23 changes: 11 additions & 12 deletions radiofeed/episodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
HttpResponseUnauthorized,
require_DELETE,
)
from radiofeed.pagination import render_pagination_response


@require_safe
Expand All @@ -39,11 +38,11 @@ def index(request: HttpRequest) -> TemplateResponse:
.order_by("-pub_date", "-id")
)

return render_pagination_response(
return TemplateResponse(
request,
episodes,
"episodes/index.html",
{
"episodes": episodes,
"search_url": reverse("episodes:search_episodes"),
},
)
Expand All @@ -64,11 +63,11 @@ def search_episodes(request: HttpRequest) -> HttpResponseRedirect | TemplateResp
.order_by("-rank", "-pub_date")
)

return render_pagination_response(
return TemplateResponse(
request,
episodes,
"episodes/search.html",
{
"episodes": episodes,
"clear_search_url": index_url,
},
)
Expand Down Expand Up @@ -182,11 +181,11 @@ def history(request: HttpRequest) -> TemplateResponse:
else audio_logs.order_by("listened" if ordering_asc else "-listened")
)

return render_pagination_response(
return TemplateResponse(
request,
audio_logs,
"episodes/history.html",
{
"audio_logs": audio_logs,
"ordering_asc": ordering_asc,
},
)
Expand All @@ -211,7 +210,7 @@ def remove_audio_log(request: HttpRequest, episode_id: int) -> TemplateResponse:

return TemplateResponse(
request,
"episodes/detail.html#audio_log",
"episodes/_audio_log.html",
{
"episode": audio_log.episode,
},
Expand All @@ -232,11 +231,11 @@ def bookmarks(request: HttpRequest) -> TemplateResponse:
else bookmarks.order_by("created" if ordering_asc else "-created")
)

return render_pagination_response(
return TemplateResponse(
request,
bookmarks,
"episodes/bookmarks.html",
{
"bookmarks": bookmarks,
"ordering_asc": ordering_asc,
},
)
Expand Down Expand Up @@ -280,7 +279,7 @@ def _render_audio_player_action(
) -> TemplateResponse:
return TemplateResponse(
request,
"episodes/detail.html#audio_player_button",
"episodes/_audio_player_button.html",
{
"audio_log": audio_log,
"episode": audio_log.episode,
Expand All @@ -296,7 +295,7 @@ def _render_bookmark_action(
) -> TemplateResponse:
return TemplateResponse(
request,
"episodes/detail.html#bookmark_button",
"episodes/_bookmark_button.html",
{
"episode": episode,
"is_bookmarked": is_bookmarked,
Expand Down
54 changes: 0 additions & 54 deletions radiofeed/pagination.py

This file was deleted.

41 changes: 22 additions & 19 deletions radiofeed/podcasts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

from radiofeed.http import HttpResponseConflict, require_DELETE, require_form_methods
from radiofeed.http_client import get_client
from radiofeed.pagination import render_pagination_response
from radiofeed.podcasts import itunes
from radiofeed.podcasts.forms import PrivateFeedForm
from radiofeed.podcasts.models import Category, Podcast
from radiofeed.template import render_template_partial


@require_safe
Expand All @@ -40,6 +38,7 @@ def index(request: HttpRequest) -> HttpResponseRedirect | TemplateResponse:
def subscriptions(request: HttpRequest) -> TemplateResponse:
"""Render podcast index page."""
podcasts = _get_podcasts().subscribed(request.user)

podcasts = (
podcasts.search(request.search.value).order_by(
"-exact_match",
Expand All @@ -50,23 +49,24 @@ def subscriptions(request: HttpRequest) -> TemplateResponse:
else podcasts.order_by("-pub_date")
)

return render_pagination_response(
return TemplateResponse(
request,
podcasts,
"podcasts/subscriptions.html",
{
"podcasts": podcasts,
},
)


@require_safe
@login_required
def discover(request: HttpRequest) -> TemplateResponse:
"""Shows all promoted podcasts."""

return render_pagination_response(
return TemplateResponse(
request,
_get_promoted_podcasts().order_by("-pub_date"),
"podcasts/discover.html",
{
"podcasts": _get_promoted_podcasts().order_by("-pub_date"),
"search_url": reverse("podcasts:search_podcasts"),
},
)
Expand All @@ -91,11 +91,11 @@ def search_podcasts(request: HttpRequest) -> HttpResponseRedirect | TemplateResp
)
)

return render_pagination_response(
return TemplateResponse(
request,
podcasts,
"podcasts/search_podcasts.html",
{
"podcasts": podcasts,
"clear_search_url": discover_url,
},
)
Expand Down Expand Up @@ -166,12 +166,12 @@ def episodes(
else episodes.order_by("pub_date" if ordering_asc else "-pub_date")
)

return render_pagination_response(
return TemplateResponse(
request,
episodes,
"podcasts/episodes.html",
{
"podcast": podcast,
"episodes": episodes,
"ordering_asc": ordering_asc,
},
)
Expand Down Expand Up @@ -256,12 +256,12 @@ def category_detail(
else podcasts.order_by("-pub_date")
)

return render_pagination_response(
return TemplateResponse(
request,
podcasts,
"podcasts/category_detail.html",
{
"category": category,
"podcasts": podcasts,
},
)

Expand Down Expand Up @@ -308,8 +308,13 @@ def private_feeds(request: HttpRequest) -> TemplateResponse:
if request.search
else podcasts.order_by("-pub_date")
)

return render_pagination_response(request, podcasts, "podcasts/private_feeds.html")
return TemplateResponse(
request,
"podcasts/private_feeds.html",
{
"podcasts": podcasts,
},
)


@require_form_methods
Expand Down Expand Up @@ -337,14 +342,12 @@ def add_private_feed(
else:
form = PrivateFeedForm(request.user)

return render_template_partial(
return TemplateResponse(
request,
"podcasts/private_feed_form.html",
{
"form": form,
},
partial="form",
target="private-feed-form",
)


Expand Down Expand Up @@ -375,7 +378,7 @@ def _render_subscribe_action(
) -> TemplateResponse:
return TemplateResponse(
request,
"podcasts/detail.html#subscribe_button",
"podcasts/_subscribe_button.html",
{
"podcast": podcast,
"is_subscribed": is_subscribed,
Expand Down
1 change: 0 additions & 1 deletion radiofeed/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"health_check.contrib.psutil",
"health_check.contrib.redis",
"heroicons",
"template_partials",
"radiofeed.episodes",
"radiofeed.feedparser",
"radiofeed.podcasts",
Expand Down
19 changes: 0 additions & 19 deletions radiofeed/template.py

This file was deleted.

17 changes: 17 additions & 0 deletions radiofeed/templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from django import template
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.paginator import Page, Paginator
from django.shortcuts import resolve_url
from django.template.defaultfilters import pluralize

from radiofeed import cover_image, markdown

if TYPE_CHECKING: # pragma: nocover
from django.db.models import QuerySet
from django.template.context import RequestContext

from radiofeed.cover_image import CoverImageVariant
Expand Down Expand Up @@ -57,6 +59,21 @@ def theme_color() -> dict:
return settings.PWA_CONFIG["manifest"]["theme_color"]


@register.simple_tag(takes_context=True)
def paginate(
context: RequestContext,
object_list: QuerySet,
page_size: int = settings.PAGE_SIZE,
param: str = "page",
**pagination_kwargs,
) -> Page:
"""Returns paginated object list."""
return Paginator(object_list, page_size).get_page(
context.request.GET.get(param, ""),
**pagination_kwargs,
)


@register.simple_tag
@functools.cache
def get_site() -> Site:
Expand Down
30 changes: 0 additions & 30 deletions radiofeed/tests/test_partials.py

This file was deleted.

Loading

0 comments on commit 8c0c4cd

Please sign in to comment.