Add new functionality
This commit is contained in:
parent
7dd96889af
commit
5a818beef3
|
@ -1,3 +1,4 @@
|
|||
from types import FunctionType
|
||||
from django.conf import settings
|
||||
from django.utils.html import strip_spaces_between_tags
|
||||
from django.utils.translation import (
|
||||
|
@ -79,7 +80,7 @@ class JsMinExtension(Extension):
|
|||
[], [], body,
|
||||
).set_lineno(lineno)
|
||||
|
||||
def _strip_whitespace_js(self, caller=None):
|
||||
def _strip_whitespace_js(self, caller: FunctionType):
|
||||
if settings.DEBUG:
|
||||
# Debug mode, no minification
|
||||
return caller().strip()
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
from django.utils.functional import lazy
|
||||
from django.utils.safestring import SafeString, _safety_decorator, mark_safe
|
||||
from django.utils.translation import gettext_lazy as _gettext_lazy
|
||||
|
||||
from .types import StrOrPromise
|
||||
|
||||
|
||||
def _mark_safe(s):
|
||||
"""
|
||||
Keep this in sync with `django.utils.safestring.mark_safe`!
|
||||
This is separated because the `keep_lazy` decorator makes the
|
||||
original `mark_safe` unpickable for cache storage.
|
||||
So if you use the original, you'll get pickle errors from caching.
|
||||
"""
|
||||
if hasattr(s, "__html__"):
|
||||
return s
|
||||
if callable(s):
|
||||
return _safety_decorator(mark_safe, s)
|
||||
return SafeString(s)
|
||||
|
||||
|
||||
def gettext_safelazy(message: StrOrPromise):
|
||||
'Return a translated lazy `SafeString`.'
|
||||
unsafe = _gettext_lazy(message=message)
|
||||
return lazy(_mark_safe, SafeString)(s=unsafe)
|
|
@ -0,0 +1,3 @@
|
|||
from django.utils.functional import Promise
|
||||
|
||||
StrOrPromise = str | Promise
|
Loading…
Reference in New Issue