Skip to content

Commit

Permalink
refactor: tidy up redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
danjac committed Jan 10, 2025
1 parent c54bc26 commit 3c71b97
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions radiofeed/podcasts/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Final, cast
from typing import cast

from django.conf import settings
from django.contrib import messages
Expand All @@ -8,7 +8,7 @@
from django.http import Http404, HttpRequest, HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.urls import reverse_lazy
from django.urls import reverse
from django.views.decorators.http import require_POST, require_safe

from radiofeed.http import HttpResponseConflict, require_DELETE, require_form_methods
Expand All @@ -20,9 +20,6 @@
from radiofeed.podcasts.models import Category, Podcast
from radiofeed.users.models import User

_discover_url: Final = reverse_lazy("podcasts:discover")
_private_feeds_url: Final = reverse_lazy("podcasts:private_feeds")


@require_safe
@login_required
Expand Down Expand Up @@ -84,7 +81,7 @@ def search_podcasts(

return render_pagination(request, "podcasts/search_podcasts.html", podcasts)

return HttpResponseRedirect(_discover_url)
return HttpResponseRedirect(reverse("podcasts:discover"))


@require_safe
Expand All @@ -107,7 +104,7 @@ def search_itunes(request: HttpRequest) -> HttpResponseRedirect | TemplateRespon
},
)

return HttpResponseRedirect(_discover_url)
return HttpResponseRedirect(reverse("podcasts:discover"))


@require_safe
Expand Down Expand Up @@ -322,7 +319,8 @@ def add_private_feed(
request,
"Podcast added to your Private Feeds and will appear here soon",
)
return HttpResponseRedirect(_private_feeds_url)

return HttpResponseRedirect(reverse("podcasts:private_feeds"))

messages.success(request, "Podcast added to your Private Feeds")
return HttpResponseRedirect(podcast.get_absolute_url())
Expand All @@ -347,7 +345,7 @@ def remove_private_feed(request: HttpRequest, podcast_id: int) -> HttpResponseRe
podcast = _get_podcast_or_404(podcast_id, private=True)
request.user.subscriptions.filter(podcast=podcast).delete()
messages.info(request, "Removed from Private Feeds")
return HttpResponseRedirect(_private_feeds_url)
return HttpResponseRedirect(reverse("podcasts:private_feeds"))


def _get_podcasts() -> QuerySet[Podcast]:
Expand Down

0 comments on commit 3c71b97

Please sign in to comment.