You've already forked hotpocket
This commit is contained in:
12
services/backend/hotpocket_backend/apps/htmx/apps.py
Normal file
12
services/backend/hotpocket_backend/apps/htmx/apps.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class HTMXConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
label = 'htmx'
|
||||
name = 'hotpocket_backend.apps.htmx'
|
||||
verbose_name = _('HTMX')
|
||||
40
services/backend/hotpocket_backend/apps/htmx/messages.py
Normal file
40
services/backend/hotpocket_backend/apps/htmx/messages.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib.messages.constants import ( # noqa: F401
|
||||
DEBUG,
|
||||
DEFAULT_TAGS,
|
||||
ERROR,
|
||||
INFO,
|
||||
SUCCESS,
|
||||
WARNING,
|
||||
)
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django_htmx.http import trigger_client_event
|
||||
|
||||
|
||||
def add_htmx_message(*,
|
||||
request: HttpRequest,
|
||||
response: HttpResponse,
|
||||
level: str,
|
||||
message: str,
|
||||
extra_tags: str = '',
|
||||
fail_silently: bool = False,
|
||||
):
|
||||
if not request.htmx:
|
||||
if fail_silently is False:
|
||||
raise RuntimeError(
|
||||
"This doesn't look like an HTMX request: request=`%s`",
|
||||
request,
|
||||
)
|
||||
else:
|
||||
trigger_client_event(
|
||||
response,
|
||||
'HotPocket:UI:Messages:addMessage',
|
||||
{
|
||||
'level': DEFAULT_TAGS.get(level, DEFAULT_TAGS[INFO]),
|
||||
'message': message,
|
||||
'extra_tags': extra_tags,
|
||||
},
|
||||
after='swap',
|
||||
)
|
||||
Reference in New Issue
Block a user