Skip to content

Commit 4220911

Browse files
committed
did: disable cache, consider LOGIN_URL settings, allow submit-buttons to use ajax
1 parent 6bacb44 commit 4220911

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

basxbread/layout/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def render(request, layout, context=None, **response_kwargs):
6767
return HttpResponse(hg.prerender(layout).render(defaultcontext), **response_kwargs)
6868
"""
6969

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

7274

7375
render.CONTEXT_PROCESSORS = None # type: ignore

basxbread/layout/components/button.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def from_link(link, dialog=True, **kwargs):
7373
def as_href(self, href):
7474
return hg.A(*self, **{**self.attributes, "href": href})
7575

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

7981
from ..utils import slugify
@@ -108,8 +110,14 @@ def as_submit(self, href, formfields={}, confirm_text=None, dialog=True, **kwarg
108110
for name, value in formfields.items()
109111
],
110112
confirm_dialog if dialog else None,
111-
action=href,
112-
**hg.merge_html_attrs(kwargs, {"style": "display: inline"}),
113+
**hg.merge_html_attrs(
114+
kwargs,
115+
(
116+
{"style": "display: inline", "hx-post": href}
117+
if ajax
118+
else {"style": "display: inline", "action": href}
119+
),
120+
),
113121
)
114122

115123

basxbread/middleware.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ def process_view(self, request, view_func, view_args, view_kwargs):
6969
request.user = user
7070
return None
7171

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

0 commit comments

Comments
 (0)