Skip to content

Commit aaed573

Browse files
authoredApr 7, 2022
Support Django 2.2, 3.2 and 4.0 with Python 3.7-3.9 (#49)
1 parent 5ffc9c5 commit aaed573

File tree

18 files changed

+87
-359
lines changed

18 files changed

+87
-359
lines changed
 

‎README.rst

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Install django-viewlet in your python environment
2525
2626
$ pip install django-viewlet
2727
28-
Supports ``Django`` versions 1.3 - 2.0 and ``Python`` version 3.6.
28+
Supports ``Django`` versions 2.2, 3.2, 4.0 and ``Python`` versions 3.7 - 3.9.
2929

3030

3131
Configuration
@@ -43,36 +43,6 @@ Add ``viewlet`` to your ``INSTALLED_APPS`` setting so Django can find the templa
4343
Jinja2
4444
______
4545

46-
47-
If you're using ``Coffin`` or ``Jingo``, add the ``ViewletExtension`` to their settings,
48-
and optionally switch to their respective environment.
49-
50-
**Coffin:**
51-
52-
.. code-block:: python
53-
54-
JINJA2_EXTENSIONS = (
55-
...,
56-
"viewlet.loaders.jinja2_loader.ViewletExtension",
57-
)
58-
59-
VIEWLET_JINJA2_ENVIRONMENT = "coffin.common.env"
60-
61-
**Jingo:**
62-
63-
.. code-block:: python
64-
65-
JINJA_CONFIG = {
66-
"extensions": (
67-
...,
68-
"viewlet.loaders.jinja2_loader.ViewletExtension",
69-
),
70-
}
71-
72-
VIEWLET_JINJA2_ENVIRONMENT = "jingo.get_env"
73-
74-
**Django 1.8+:**
75-
7646
Add ``ViewletExtension`` to the list of extensions of Jinja2 template engine
7747

7848
.. code-block:: python

‎run_tests.py

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ def main():
4242
"TEMPLATE_CONTEXT_PROCESSORS": [
4343
"django.core.context_processors.request",
4444
],
45-
"TEMPLATE_DIRS": (os.path.join(ROOT, "template_dir"),),
4645
"TEMPLATES": [
4746
{
4847
"BACKEND": "django.template.backends.django.DjangoTemplates",
@@ -78,47 +77,32 @@ def main():
7877
"JINJA_CONFIG": {"autoescape": True}, # Jingo config
7978
}
8079

81-
if django.VERSION >= (1, 10):
82-
conf["MIDDLEWARE"] = conf.pop("MIDDLEWARE_CLASSES")
83-
84-
if django.VERSION < (1, 8):
85-
conf.pop("TEMPLATES")
86-
else:
87-
conf.pop("TEMPLATE_DEBUG")
88-
conf.pop("TEMPLATE_CONTEXT_PROCESSORS")
89-
conf.pop("TEMPLATE_DIRS")
90-
91-
if django.VERSION >= (1, 2):
92-
conf.update(
93-
DATABASES={
94-
"default": {
95-
"ENGINE": "django.db.backends.sqlite3",
96-
"NAME": ":memory:",
97-
}
98-
}
99-
)
80+
conf["MIDDLEWARE"] = conf.pop("MIDDLEWARE_CLASSES")
81+
82+
conf.pop("TEMPLATE_DEBUG")
83+
conf.pop("TEMPLATE_CONTEXT_PROCESSORS")
10084

101-
conf.update(
102-
CACHES={
103-
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}
85+
conf.update(
86+
DATABASES={
87+
"default": {
88+
"ENGINE": "django.db.backends.sqlite3",
89+
"NAME": ":memory:",
10490
}
105-
)
106-
else:
107-
conf.update(DATABASE_ENGINE="sqlite3")
108-
conf.update(CACHE_BACKEND="locmem://")
91+
}
92+
)
93+
94+
conf.update(
95+
CACHES={"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}}
96+
)
10997

11098
settings.configure(**conf)
11199

112-
if django.VERSION >= (1, 7):
113-
django.setup()
100+
django.setup()
114101

115102
from django.test.utils import get_runner
116103

117-
if django.VERSION < (1, 2):
118-
failures = get_runner(settings)(["viewlet"], verbosity=2, interactive=True)
119-
else:
120-
test_runner = get_runner(settings)(verbosity=2, interactive=True)
121-
failures = test_runner.run_tests(["viewlet"])
104+
test_runner = get_runner(settings)(verbosity=2, interactive=True)
105+
failures = test_runner.run_tests(["viewlet"])
122106

123107
sys.exit(failures)
124108

‎setup.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ def finalize_options(self):
5959
license="MIT",
6060
classifiers=[
6161
"Programming Language :: Python",
62-
"Programming Language :: Python :: 2",
63-
"Programming Language :: Python :: 2.6",
64-
"Programming Language :: Python :: 2.7",
65-
"Programming Language :: Python :: 3",
66-
"Programming Language :: Python :: 3.3",
67-
"Programming Language :: Python :: 3.4",
68-
"Programming Language :: Python :: 3.5",
69-
"Programming Language :: Python :: 3.6",
62+
"Programming Language :: Python :: 3.7",
63+
"Programming Language :: Python :: 3.8",
64+
"Programming Language :: Python :: 3.9",
7065
"Framework :: Django",
7166
"Natural Language :: English",
7267
"Environment :: Web Environment",
@@ -84,7 +79,7 @@ def finalize_options(self):
8479
install_requires=[
8580
"six",
8681
],
87-
tests_require=["coverage", "Jinja2", "jingo", "coffin<2"],
82+
tests_require=["coverage", "Jinja2"],
8883
test_suite="run_tests.main",
8984
cmdclass=cmdclasses,
9085
)

‎tox.ini

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,33 @@
22
# https://github.com/tox-dev/tox/pull/670
33

44
[tox]
5-
envlist = py26-django{ 13, 14, 15, 16 },
6-
py27-django{ 14, 15, 16, 17, 18, 19, 110, 111 },
7-
py33-django{ 15, 16, 17, 18 },
8-
py34-django{ 17, 18, 19, 110, 111, 20 },
9-
py35-django{ 18, 19, 110, 111, 20 },
10-
py36-django{ 111, 20 }
5+
envlist =
6+
py37-django{ 22, 32 }
7+
py38-django{ 32 }
8+
py39-django{ 32, 40 }
119

1210

1311
[testenv]
1412
passenv = COVERAGE_FILE
1513
whitelist_externals = make
16-
commands =
17-
make test
18-
install_command =
19-
pip install --no-binary --pre {opts} {packages}
20-
deps = django12: Django>=1.2,<1.3
21-
django13: Django>=1.3,<1.4
22-
django14: Django>=1.4,<1.5
23-
django15: Django>=1.5,<1.6
24-
django16: Django>=1.6,<1.7
25-
django17: Django>=1.7,<1.8
26-
django18: Django>=1.8,<1.9
27-
django19: Django>=1.9,<1.10
28-
django110: Django>=1.10,<1.11
29-
django111: Django>=1.11,<1.12
30-
django20: Django>=2.0b1,<2.1
31-
coverage
14+
commands = make test
15+
install_command = pip install --pre {opts} {packages}
16+
deps =
17+
django22: Django>=2.2,<2.3
18+
django32: Django>=3.2,<3.3
19+
django40: Django>=4.0,<4.1
20+
coverage
3221

3322
[testenv:coverage]
3423
skip_install = true
3524
passenv = COVERAGE_FILE
36-
basepython = python3.4
37-
commands =
38-
make coverage
39-
deps =
40-
coverage
25+
basepython = python3.9
26+
commands = make coverage
27+
deps = coverage
4128

4229

4330
[testenv:lint]
44-
basepython = python3.4
31+
basepython = python3.9
4532
skip_install = true
46-
commands =
47-
make lint
48-
deps =
49-
flake8
33+
commands = make lint
34+
deps = flake8

‎viewlet/cache.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
import hashlib
22

3-
from .compat import smart_text
3+
from django.utils.encoding import smart_str
4+
45
from .conf import settings
56
from .exceptions import DeprecatedKeyFormat, WrongKeyFormat
67

78

89
def get_cache(alias=None):
9-
import django
1010
from django.core import cache
1111

1212
try:
1313
key = alias or settings.VIEWLET_DEFAULT_CACHE_ALIAS
14-
if django.VERSION >= (1, 7):
15-
c = cache.caches[key]
16-
else:
17-
c = cache.get_cache(key)
14+
c = cache.caches[key]
1815
except (cache.InvalidCacheBackendError, ValueError):
1916
c = cache.cache
2017

2118
return c
2219

2320

2421
def join_args(args):
25-
return ":".join(map(smart_text, args))
22+
return ":".join(map(smart_str, args))
2623

2724

2825
def digest_args(args):

‎viewlet/compat.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

‎viewlet/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self, **conf):
1818
"VIEWLET_DEFAULT_CACHE_ALIAS": "viewlet",
1919
"VIEWLET_CACHE_KEY_FUNCTION": "viewlet.cache.make_key_args_digest",
2020
"VIEWLET_CACHE_KEY_MAX_LENGTH": 255,
21-
"VIEWLET_TEMPLATE_ENGINE": "django",
2221
"VIEWLET_INFINITE_CACHE_TIMEOUT": 31104000, # 60*60*24*30*12, about a year
2322
"VIEWLET_JINJA2_ENVIRONMENT": "viewlet.loaders.jinja2_loader.create_env",
2423
}

‎viewlet/library.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def autodiscover(self):
2828
Autodiscover decorated viewlets.
2929
Imports all views.py and viewlets.py to trigger the decorators.
3030
"""
31-
from django.conf import settings
31+
from importlib import import_module
3232

33-
from .compat import import_module
33+
from django.conf import settings
3434

3535
for app in settings.INSTALLED_APPS:
3636
try:

‎viewlet/loaders/__init__.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +0,0 @@
1-
import warnings
2-
3-
import django
4-
5-
from viewlet.conf import settings
6-
7-
8-
def get_loader():
9-
if settings.VIEWLET_TEMPLATE_ENGINE.lower() == "jinja2":
10-
if django.VERSION < (1, 8):
11-
from . import jinja2_loader as loader
12-
13-
return loader
14-
warnings.warn(
15-
"VIEWLET_TEMPLATE_ENGINE setting is deprecated for Django 1.8+",
16-
DeprecationWarning,
17-
)
18-
from . import django_loader as loader
19-
20-
return loader
21-
22-
23-
def render(*args, **kwargs):
24-
loader = get_loader()
25-
return loader.render_to_string(*args, **kwargs)
26-
27-
28-
def mark_safe(value):
29-
loader = get_loader()
30-
return loader.mark_safe(value)
31-
32-
33-
def querydict_to_kwargs(querydict):
34-
def make_key(k):
35-
return k
36-
37-
return {make_key(k): ",".join(querydict.getlist(k)) for k in querydict}

‎viewlet/loaders/django_loader.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎viewlet/loaders/jinja2_loader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from importlib import import_module
2+
13
from django.conf import settings as django_settings
24
from jinja2 import ChoiceLoader, FileSystemLoader, PackageLoader, nodes
35
from jinja2.environment import Environment
@@ -6,7 +8,6 @@
68

79
import viewlet
810

9-
from ..compat import import_module
1011
from ..conf import settings
1112

1213

0 commit comments

Comments
 (0)
Please sign in to comment.