Skip to content

Commit

Permalink
did: disable cache, consider LOGIN_URL settings, allow submit-buttons…
Browse files Browse the repository at this point in the history
… to use ajax
  • Loading branch information
saemideluxe committed Dec 19, 2024
1 parent 6bacb44 commit 4220911
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion basxbread/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def render(request, layout, context=None, **response_kwargs):
return HttpResponse(hg.prerender(layout).render(defaultcontext), **response_kwargs)
"""

return HttpResponse(layout.render(defaultcontext), **response_kwargs)
response = HttpResponse(layout.render(defaultcontext), **response_kwargs)
response["Cache-Control"] = "no-cache"
return response


render.CONTEXT_PROCESSORS = None # type: ignore
14 changes: 11 additions & 3 deletions basxbread/layout/components/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def from_link(link, dialog=True, **kwargs):
def as_href(self, href):
return hg.A(*self, **{**self.attributes, "href": href})

def as_submit(self, href, formfields={}, confirm_text=None, dialog=True, **kwargs):
def as_submit(
self, href, formfields={}, confirm_text=None, dialog=True, ajax=False, **kwargs
):
from django.forms import Form as DjangoForm

from ..utils import slugify
Expand Down Expand Up @@ -108,8 +110,14 @@ def as_submit(self, href, formfields={}, confirm_text=None, dialog=True, **kwarg
for name, value in formfields.items()
],
confirm_dialog if dialog else None,
action=href,
**hg.merge_html_attrs(kwargs, {"style": "display: inline"}),
**hg.merge_html_attrs(
kwargs,
(
{"style": "display: inline", "hx-post": href}
if ajax
else {"style": "display: inline", "action": href}
),
),
)


Expand Down
4 changes: 3 additions & 1 deletion basxbread/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ def process_view(self, request, view_func, view_args, view_kwargs):
request.user = user
return None

return HttpResponseRedirect(reverse("login") + "?next=" + request.path)
return HttpResponseRedirect(
reverse(settings.LOGIN_URL) + "?next=" + request.path
)

0 comments on commit 4220911

Please sign in to comment.