Skip to content

Commit 8e12542

Browse files
authored
Add support for Django 4.1 and drop support for < 3.2 (#86)
* Stop supporting older deprecated Django versions (2.2 and 3.1) * Fix `Tag` name breaking in Django 4.1 Django underwent some refactoring with regards to how it's tag names are generated and registered in the template library * Officially support Django 4.1
1 parent 505d6ba commit 8e12542

File tree

10 files changed

+63
-50
lines changed

10 files changed

+63
-50
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
python-version: ['3.7', '3.8', '3.9', '3.10']
13-
django-version: ['2.2', '3.1', '3.2', '4.0']
13+
django-version: ['3.2', '4.0', '4.1']
1414
os: [
1515
ubuntu-20.04,
1616
]
1717
exclude:
1818
- python-version: '3.7'
1919
django-version: '4.0'
20-
- python-version: '3.10'
21-
django-version: '2.2'
22-
- python-version: '3.10'
23-
django-version: '3.1'
20+
- python-version: '3.7'
21+
django-version: '4.1'
2422

2523
steps:
2624
- uses: actions/checkout@v1
@@ -50,7 +48,6 @@ jobs:
5048
matrix:
5149
python-version: ['3.8', '3.9', '3.10']
5250
django-version: [
53-
'Django==4.1',
5451
'https://github.com/django/django/archive/main.tar.gz'
5552
]
5653
os: [

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ repos:
99
rev: '1.6.1'
1010
hooks:
1111
- id: django-upgrade
12-
args: [--target-version, "2.2"]
12+
args: [--target-version, "3.2"]
1313

1414
- repo: https://github.com/PyCQA/flake8
1515
rev: 4.0.1

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Changelog
55
unreleased
66
==========
77

8-
* Start testing Django 4.1 and Django's `main` branch
8+
* Dropped support for Django < 3.2
9+
* Added support for Django 4.1
10+
* Start testing against Django's `main` branch
911

1012
3.0.1 2022-02-01
1113
================

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ You can run tests by executing::
107107
.. |coverage| image:: https://codecov.io/gh/divio/django-classy-tags/branch/master/graph/badge.svg
108108
:target: https://codecov.io/gh/divio/django-classy-tags
109109

110-
.. |python| image:: https://img.shields.io/badge/python-3.5+-blue.svg
110+
.. |python| image:: https://img.shields.io/badge/python-3.7+-blue.svg
111111
:target: https://pypi.org/project/django-classy-tags/
112-
.. |django| image:: https://img.shields.io/badge/django-2.2,%203.0,%203.1-blue.svg
112+
.. |django| image:: https://img.shields.io/badge/django-3.2,%204.0,%204.0-blue.svg
113113
:target: https://www.djangoproject.com/

classytags/core.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,13 @@ def parse(self, parser, tokens):
108108
class TagMeta(type):
109109
"""
110110
Metaclass for the Tag class that set's the name attribute onto the class
111-
and a _decorated_function pseudo-function which is used by Django's
112-
template system to get the tag name.
113111
"""
114112
def __new__(cls, name, bases, attrs):
115-
parents = [base for base in bases if isinstance(base, TagMeta)]
116-
if not parents:
113+
if not any(base for base in bases if isinstance(base, TagMeta)):
117114
return super().__new__(cls, name, bases, attrs)
118115
tag_name = str(attrs.get('name', get_default_name(name)))
119-
120-
def fake_func():
121-
pass # pragma: no cover
122-
123-
fake_func.__name__ = tag_name
124-
attrs['_decorated_function'] = fake_func
125-
attrs['name'] = str(tag_name)
126-
return super().__new__(cls, name, bases, attrs)
116+
attrs['name'] = tag_name
117+
return super().__new__(cls, tag_name, bases, attrs)
127118

128119

129120
class Tag(TagMeta('TagMeta', (Node,), {})):

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
bump2version
2-
Django>2.2
2+
Django>3.2
33
pip-tools
44
pre-commit
55
wheel

requirements.txt

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,49 @@
44
#
55
# pip-compile
66
#
7-
asgiref==3.4.1
7+
asgiref==3.5.2
88
# via django
9+
build==0.8.0
10+
# via pip-tools
911
bump2version==1.0.1
1012
# via -r requirements.in
1113
cfgv==3.3.1
1214
# via pre-commit
13-
click==8.0.3
15+
click==8.1.3
1416
# via pip-tools
15-
distlib==0.3.4
17+
distlib==0.3.6
1618
# via virtualenv
17-
django==4.0.7
19+
django==4.1.1
1820
# via -r requirements.in
19-
filelock==3.4.2
21+
filelock==3.8.0
2022
# via virtualenv
21-
identify==2.4.4
23+
identify==2.5.5
2224
# via pre-commit
23-
nodeenv==1.6.0
25+
nodeenv==1.7.0
2426
# via pre-commit
25-
pep517==0.12.0
26-
# via pip-tools
27-
pip-tools==6.4.0
27+
packaging==21.3
28+
# via build
29+
pep517==0.13.0
30+
# via build
31+
pip-tools==6.8.0
2832
# via -r requirements.in
29-
platformdirs==2.4.1
33+
platformdirs==2.5.2
3034
# via virtualenv
31-
pre-commit==2.17.0
35+
pre-commit==2.20.0
3236
# via -r requirements.in
37+
pyparsing==3.0.9
38+
# via packaging
3339
pyyaml==6.0
3440
# via pre-commit
35-
six==1.16.0
36-
# via virtualenv
37-
sqlparse==0.4.2
41+
sqlparse==0.4.3
3842
# via django
3943
toml==0.10.2
4044
# via pre-commit
41-
tomli==2.0.0
42-
# via pep517
43-
virtualenv==20.13.0
45+
tomli==2.0.1
46+
# via
47+
# build
48+
# pep517
49+
virtualenv==20.16.5
4450
# via pre-commit
4551
wheel==0.37.1
4652
# via

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
REQUIREMENTS = [
8-
'django>=2.2',
8+
'django>=3.2',
99
]
1010

1111

@@ -21,10 +21,9 @@
2121
'Programming Language :: Python :: 3.9',
2222
'Programming Language :: Python :: 3.10',
2323
'Framework :: Django',
24-
'Framework :: Django :: 2.2',
25-
'Framework :: Django :: 3.1',
2624
'Framework :: Django :: 3.2',
2725
'Framework :: Django :: 4.0',
26+
'Framework :: Django :: 4.1',
2827
'Topic :: Internet :: WWW/HTTP',
2928
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
3029
'Topic :: Software Development',

tests/test_core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,22 @@ class MyTag2(core.Tag):
591591
msg = "'my_tag2' in %s" % lib.tags.keys()
592592
self.assertTrue('my_tag2' not in lib.tags, msg)
593593

594+
# test decorated naming
595+
lib = template.Library()
596+
597+
@lib.tag(name="my_decorated_tag_5")
598+
class MyTag5(core.Tag):
599+
pass
600+
msg = "'my_decorated_tag_5' not in %s" % lib.tags.keys()
601+
self.assertTrue('my_decorated_tag_5' in lib.tags, msg)
602+
603+
# test decorated and explicit naming
604+
# the tag registration takes precedence over the name attribute
605+
lib = template.Library()
606+
lib.tag('my_decorated_tag_6', MyTag2)
607+
msg = "'my_decorated_tag_6' not in %s" % lib.tags.keys()
608+
self.assertTrue('my_decorated_tag_6' in lib.tags, msg)
609+
594610
def test_hello_world(self):
595611
class Hello(core.Tag):
596612
options = core.Options(
@@ -971,6 +987,12 @@ class MyTag(core.Tag):
971987
tag = MyTag(dummy_parser, DummyTokens())
972988
self.assertEqual('<Tag: mytag>', repr(tag))
973989

990+
def test_repr_without_explicit_name(self):
991+
class MyTag(core.Tag):
992+
pass
993+
tag = MyTag(dummy_parser, DummyTokens())
994+
self.assertEqual('<Tag: my_tag>', repr(tag))
995+
974996
def test_non_required_multikwarg(self):
975997
options = core.Options(
976998
arguments.MultiKeywordArgument('multi', required=False),

tox.ini

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
envlist =
33
flake8
44
isort
5-
py{37,38,39}-dj{22,31,32}
6-
py{38,39,310}-dj{31,32,40,41,main}
5+
py{37}-dj32
6+
py{38,39,310}-dj{32,40,41,main}
77

88
skip_missing_interpreters=True
99

1010
[testenv]
1111
deps =
1212
-r{toxinidir}/tests/requirements/base.txt
13-
dj22: Django>=2.2,<3.0
14-
dj31: Django>=3.1,<3.2
1513
dj32: Django>=3.2,<3.3
1614
dj40: Django>=4.0,<4.1
1715
dj41: Django>=4.1,<4.2
@@ -22,10 +20,8 @@ commands =
2220
{env:COMMAND:coverage} run setup.py test
2321
{env:COMMAND:coverage} report
2422
ignore_outcome =
25-
dj41: True
2623
djmain: True
2724
ignore_errors =
28-
dj41: True
2925
djmain: True
3026

3127
[testenv:flake8]

0 commit comments

Comments
 (0)