/usr/lib/python2.7/dist-packages/crispy_forms/templatetags/crispy_forms_utils.py is in python-django-crispy-forms 1.7.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # -*- coding: utf-8 -*-
import re
from django import template
from django.utils.encoding import force_text
from crispy_forms.compatibility import text_type
try:
from django.utils.functional import keep_lazy
except ImportError:
# django < 1.10
from django.utils.functional import allow_lazy
# bare version for remove_spaces
def keep_lazy(*args):
def decorator(func):
return allow_lazy(func, *args)
return decorator
register = template.Library()
@keep_lazy(text_type)
def remove_spaces(value):
html = re.sub(r'>\s{3,}<', '> <', force_text(value))
return re.sub(r'/><', r'/> <', force_text(html))
class SpecialSpacelessNode(template.Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context):
return remove_spaces(self.nodelist.render(context).strip())
@register.tag
def specialspaceless(parser, token):
"""
Removes whitespace between HTML tags, and introduces a whitespace
after buttons an inputs, necessary for Bootstrap to place them
correctly in the layout.
"""
nodelist = parser.parse(('endspecialspaceless',))
parser.delete_first_token()
return SpecialSpacelessNode(nodelist)
|