Skip to content

Commit 3b5fdad

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 15f8650 commit 3b5fdad

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

blog/templatetags/blog_extras.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from html.parser import HTMLParser
2+
13
from django import template
24
from django.utils.html import format_html
3-
from html.parser import HTMLParser
45

56
register = template.Library()
67

8+
79
class LazyLoadingHTMLParser(HTMLParser):
810
def __init__(self):
911
super().__init__()
@@ -38,6 +40,7 @@ def handle_startendtag(self, tag, attrs):
3840
attrs_str = " ".join(f'{k}="{v}"' for k, v in attrs)
3941
self.result.append(f"<{tag}{' ' + attrs_str if attrs_str else ''} />")
4042

43+
4144
@register.filter
4245
def add_lazy_loading(html):
4346
parser = LazyLoadingHTMLParser()

blog/tests/test_lazy_loading.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.test import SimpleTestCase
2+
23
from blog.templatetags.blog_extras import add_lazy_loading
34

5+
46
class AddLazyLoadingFilterTests(SimpleTestCase):
57
def test_adds_attributes_to_img_without_them(self):
68
html = '<p>Example <img src="example.jpg"></p>'
@@ -21,6 +23,6 @@ def test_handles_multiple_images(self):
2123
self.assertEqual(result.count('decoding="async"'), 2)
2224

2325
def test_non_image_tags_are_untouched(self):
24-
html = '<p>No images here</p>'
26+
html = "<p>No images here</p>"
2527
result = add_lazy_loading(html)
2628
self.assertEqual(result, html)

djangoproject/settings/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
DEBUG = False
7-
SECRET_KEY = 'test-secret-key'
7+
SECRET_KEY = "test-secret-key"
88

99
DATABASES = {
1010
"default": {
@@ -14,5 +14,5 @@
1414
}
1515

1616
PASSWORD_HASHERS = [
17-
'django.contrib.auth.hashers.MD5PasswordHasher',
17+
"django.contrib.auth.hashers.MD5PasswordHasher",
1818
]
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
from django.test import TestCase
2-
from foundation.models import Meeting, Business
31
from django.template import Context, Template
2+
from django.test import TestCase
3+
4+
from foundation.models import Business, Meeting
5+
46

57
class LazyLoadingMeetingTemplateTests(TestCase):
68
def test_meeting_body_html_has_lazy_loading(self):
79
meeting = Meeting.objects.create(title="Test Meeting")
8-
business = Business.objects.create(title="Test Business", body_html='<p><img src="img.jpg"></p>')
10+
business = Business.objects.create(
11+
title="Test Business", body_html='<p><img src="img.jpg"></p>'
12+
)
913
meeting.ongoing_business.add(business)
1014

11-
template = Template("""
15+
template = Template(
16+
"""
1217
{% load blog_extras %}
1318
{{ business.body_html|add_lazy_loading|safe }}
14-
""")
15-
rendered = template.render(Context({'business': business}))
19+
"""
20+
)
21+
rendered = template.render(Context({"business": business}))
1622
self.assertIn('loading="lazy"', rendered)
1723
self.assertIn('decoding="async"', rendered)

0 commit comments

Comments
 (0)