forked from adamchainz/django-htmx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mixins.py
25 lines (17 loc) · 887 Bytes
/
mixins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.core.exceptions import ImproperlyConfigured
from django.views.generic.base import TemplateResponseMixin
class HtmxTemplateResponseMixin(TemplateResponseMixin):
htmx_template_name = None
def get_template_names(self):
"""
Return a list of template names to be used for the request. Must return
a list. May not be called if render_to_response() is overridden.
"""
super().get_template_names()
if self.template_name is None or self.htmx_template_name is None:
raise ImproperlyConfigured(
"HtmxTemplateResponseMixin requires either a definition of "
"'htmx_template_name' and 'template_name' or an implementation of 'get_template_names()'")
if self.request.htmx:
return [self.htmx_template_name]
return [self.template_name]