Skip to content

Commit

Permalink
#105 if there's a template base dir setting in the session use this i…
Browse files Browse the repository at this point in the history
…nstead of the default template base dir of blog or site
  • Loading branch information
ephes committed Aug 30, 2023
1 parent d2cb1ed commit c17ef18
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cast/models/index_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def __str__(self):
return self.title

def get_template_base_dir(self, request: HttpRequest) -> str:
if hasattr(request, "session") and (template_base_dir := request.session.get("template_base_dir")) is not None:
return template_base_dir
if self.template_base_dir is not None:
return self.template_base_dir
else:
Expand Down
1 change: 1 addition & 0 deletions docs/releases/0.2.21.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Smaller fixes and improvements.

- Added a snippet viewset to be able to do CRUD on tags via wagtail admin #100
- Let users select a theme for the site and store the choice in the session #105
7 changes: 7 additions & 0 deletions tests/blog_index_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def test_blog_template_base_dir_overwrites_site_setting(self, simple_request):
template = blog.get_template(simple_request)
assert chosen_base_dir in template

def test_session_template_base_dir_overwrites_blog_setting(self, simple_request):
blog = Blog(template_base_dir="plain")
chosen_base_dir = "from_session"
simple_request.session["template_base_dir"] = "from_session"
template = blog.get_template(simple_request)
assert chosen_base_dir in template

def test_blog_use_partial_template_for_htmx_request_without_target(self, htmx_request_without_target):
blog = Blog()
with pytest.raises(ValueError, match="HTMX target is None"):
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ def request_factory():
def simple_request(request_factory):
request = request_factory.get("/")
request.htmx = HtmxDetails(request)
request.session = {}
return request


Expand Down

0 comments on commit c17ef18

Please sign in to comment.