Skip to content

Commit

Permalink
#116 move htmx request type into helpers module
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed Dec 29, 2023
1 parent fc56525 commit 9f4af3f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions cast/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .audio import Audio, ChapterMark, sync_chapter_marks
from .file import File
from .gallery import Gallery, get_or_create_gallery
from .index_pages import Blog, HtmxHttpRequest, Podcast
from .index_pages import Blog, Podcast
from .itunes import ItunesArtWork
from .moderation import SpamFilter
from .pages import Episode, HomePage, Post, sync_media_ids
Expand All @@ -24,7 +24,6 @@
"get_template_base_dir",
"get_template_base_dir_choices",
"HomePage",
"HtmxHttpRequest",
"ItunesArtWork",
"Post",
"PostCategory",
Expand Down
9 changes: 6 additions & 3 deletions cast/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from django.contrib.auth.models import User
from django.http import HttpRequest
from django_htmx.middleware import HtmxDetails

from .htmx_helpers import HtmxHttpRequest


class AuthenticatedHttpRequest(HttpRequest):
user: User


class HtmxHttpRequest(HttpRequest):
htmx: HtmxDetails
__all__ = [
"HtmxHttpRequest",
"AuthenticatedHttpRequest",
]
8 changes: 8 additions & 0 deletions cast/views/htmx_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.http import HttpRequest
from django_htmx.middleware import HtmxDetails


# Typing pattern recommended by django-stubs:
# https://github.com/typeddjango/django-stubs#how-can-i-create-a-httprequest-thats-guaranteed-to-have-an-authenticated-user
class HtmxHttpRequest(HttpRequest):
htmx: HtmxDetails
3 changes: 2 additions & 1 deletion cast/views/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from django.shortcuts import render

from ..forms import SelectThemeForm
from ..models import HtmxHttpRequest, get_template_base_dir
from ..models import get_template_base_dir
from .htmx_helpers import HtmxHttpRequest


def set_template_base_dir(request: HtmxHttpRequest, template_base_dir: str) -> None:
Expand Down

0 comments on commit 9f4af3f

Please sign in to comment.