From 9e4a6f7c78db15a9c3411fde2bbd51e988f8cb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:20:06 +0200 Subject: [PATCH 01/26] Django 4.x --- tox.ini | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index ae6d32e..c36793c 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,8 @@ envlist = py{35,36}-dj111 py{35,36,37}-dj21 py{35,36,37,38,39}-dj22 - py{36,37,38,39}-dj{30,31} + py{36,37,38,39,310}-dj{30,31,32} + py{38,39,310}-dj{40,41} [gh-actions] python = @@ -16,6 +17,7 @@ python = 3.7: py37 3.8: py38, flake8 3.9: py39 + 3.10: py310 [testenv] basepython = @@ -24,6 +26,7 @@ basepython = py37: python3.7 py38: python3.8 py39: python3.9 + py310: python3.10 usedevelop = true setenv = DJANGO_SETTINGS_MODULE = dbtemplates.test_settings @@ -35,11 +38,14 @@ deps = dj22: Django<2.3 dj30: Django<3.1 dj31: Django<3.2 + dj32: Django<3.3 + dj40: Django<4.1 + dj41: Django<4.2 djmain: https://github.com/django/django/archive/main.tar.gz#egg=django commands = python --version - coverage run {envbindir}/django-admin.py test -v2 {posargs:dbtemplates} + coverage run {envbindir}/django-admin test -v2 {posargs:dbtemplates} coverage report coverage xml From 2d622ee28cdc0fffae5855f10cacbf564a7998ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:22:32 +0200 Subject: [PATCH 02/26] Python 3.10 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b39f323..a3f0cce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false max-parallel: 5 matrix: - python-version: ['3.6', '3.7', '3.8', '3.9'] + python-version: ['3.6', '3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 From e4775618106e018c7ace4d457558be84d678fa81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:22:42 +0200 Subject: [PATCH 03/26] Proper image path --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 4ddc5b5..de0c92f 100644 --- a/README.rst +++ b/README.rst @@ -5,8 +5,8 @@ django-dbtemplates :alt: Jazzband :target: https://jazzband.co/ -.. image:: https://github.com/jazzband/django-dbtemplates/workflows/Test/badge.svg - :target: https://github.com/jazzband/django-dbtemplates/actions +.. image:: https://github.com/mpasternak/django-dbtemplates-iplweb/workflows/Test/badge.svg + :target: https://github.com/mpasternak/django-dbtemplates-iplweb/actions :alt: GitHub Actions .. image:: https://codecov.io/github/jazzband/django-dbtemplates/coverage.svg?branch=master From 9f664ea43c99035f6207c4fa52ebc2b24ee0e409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:22:48 +0200 Subject: [PATCH 04/26] Django 4.x fix --- dbtemplates/apps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbtemplates/apps.py b/dbtemplates/apps.py index d913c95..9b16d38 100644 --- a/dbtemplates/apps.py +++ b/dbtemplates/apps.py @@ -1,6 +1,8 @@ from django.apps import AppConfig -from django.utils.translation import ugettext_lazy as _ - +try: + from django.utils.translation import ugettext_lazy as _ +except ImportError: + from django.utils.translation import gettext_lazy as _ class DBTemplatesConfig(AppConfig): name = 'dbtemplates' From e1e11c42cb284d38ef4115456fc81e767eed9494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:25:32 +0200 Subject: [PATCH 05/26] Django 4.x fixes --- dbtemplates/admin.py | 5 ++++- dbtemplates/models.py | 6 +++++- dbtemplates/utils/cache.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 4ce3e34..2e4486c 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -2,7 +2,10 @@ from django import forms from django.contrib import admin from django.core.exceptions import ImproperlyConfigured -from django.utils.translation import ungettext, ugettext_lazy as _ +try: + from django.utils.translation import ungettext, ugettext_lazy as _ +except ImportError: + from django.utils.translation import ngettext, gettext_lazy as _ from django.utils.safestring import mark_safe from dbtemplates.conf import settings diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 10cb83c..f201ce4 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -8,7 +8,11 @@ from django.db import models from django.db.models import signals from django.template import TemplateDoesNotExist -from django.utils.translation import ugettext_lazy as _ +try: + from django.utils.translation import ugettext_lazy as _ +except ImportError: + from django.utils.translation import gettext_lazy as _ + from django.utils.timezone import now diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 53f0078..ddf37a6 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -10,7 +10,7 @@ def get_cache_backend(): """ Compatibilty wrapper for getting Django's cache backend instance """ - if django.VERSION[0] >= 3 and django.VERSION[1] >= 2: + if (django.VERSION[0] >= 3 and django.VERSION[1] >= 2) or django.VERSION[0] >= 4: from django.core.cache import caches cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND) else: From 9dbdb95227fd336c1dd79e27cd46e907ea8591aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:29:06 +0200 Subject: [PATCH 06/26] Rename for PyPI release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 51a3989..2485ea1 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def read(*parts): setup( - name="django-dbtemplates", + name="django-dbtemplates-iplweb", use_scm_version={"version_scheme": "post-release"}, setup_requires=["setuptools_scm"], description="Template loader for templates stored in the database", From 5281b74ea7487eba80a90e2ddd4fc82e9899cfad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:31:46 +0200 Subject: [PATCH 07/26] Don't change basepython for flake8 --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index dbde404..da7812f 100644 --- a/tox.ini +++ b/tox.ini @@ -45,10 +45,10 @@ commands = coverage xml [testenv:flake8] -basepython = python3.9 +# basepython = python3.8 commands = flake8 dbtemplates deps = flake8 [flake8] exclude=.tox -ignore=E501,E127,E128,E124 +pignore=E501,E127,E128,E124 From de4babcad48c9d5f1d0ebd1ff8cae31208675ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:39:44 +0200 Subject: [PATCH 08/26] Describe changes --- docs/changelog.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index f969846..c6e63b0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,6 +1,13 @@ Changelog ========= +v4.1 (2022-06-15, iplweb) + +* Python 3.9, 3.10 support + +* Django 4.x support + + v4.0 (unreleased) ----------------- From 7ffc0fa33facc043eeced66b46e1cffcef2dcc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:43:32 +0200 Subject: [PATCH 09/26] Don't build unversal wheel --- setup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7b62a50..b731fa8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,5 +3,3 @@ source-dir = docs/ build-dir = docs/_build all_files = 1 -[bdist_wheel] -universal=1 From 013057425fd31ab1286ca30a2e27b2159f130d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:43:43 +0200 Subject: [PATCH 10/26] Min. Python version --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 2485ea1..fe38595 100644 --- a/setup.py +++ b/setup.py @@ -41,5 +41,7 @@ def read(*parts): "Programming Language :: Python :: 3.8", "Framework :: Django", ], + python_requires='>=3.6', install_requires=["django-appconf >= 0.4"], ) + From 1a20742b71e52a9c66874ff2b60306b73467a459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 15 Jun 2022 14:58:13 +0200 Subject: [PATCH 11/26] Fix flake8 target on GitHub --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index da7812f..d0b6715 100644 --- a/tox.ini +++ b/tox.ini @@ -45,7 +45,7 @@ commands = coverage xml [testenv:flake8] -# basepython = python3.8 +basepython = python3.8 commands = flake8 dbtemplates deps = flake8 From f98fb8ca2489b23a9c1628873b280d934bee5581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Mon, 8 Aug 2022 00:40:17 +0200 Subject: [PATCH 12/26] Min. supported Python version --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index aa1c549..8b2cbb0 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,6 @@ def read(*parts): "static/dbtemplates/js/*.js", ], }, - python_requires=">=3.7", classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", @@ -43,7 +42,7 @@ def read(*parts): "Programming Language :: Python :: 3.10", "Framework :: Django", ], - python_requires='>=3.6', + python_requires=">=3.7", install_requires=["django-appconf >= 0.4"], ) From b138cafcfaee099bcd8bc73fcadab4c516444284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Mon, 8 Aug 2022 00:49:40 +0200 Subject: [PATCH 13/26] Passing flake8 --- dbtemplates/admin.py | 12 +- dbtemplates/apps.py | 1 + dbtemplates/conf.py | 4 +- dbtemplates/loader.py | 7 +- .../management/commands/sync_templates.py | 126 +++++++++++------- dbtemplates/migrations/0001_initial.py | 73 +++++++--- dbtemplates/models.py | 2 +- dbtemplates/test_cases.py | 2 +- dbtemplates/utils/cache.py | 15 ++- 9 files changed, 159 insertions(+), 83 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index bb079bb..9bfefa7 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -5,7 +5,8 @@ try: from django.utils.translation import ungettext, ugettext_lazy as _ except ImportError: - from django.utils.translation import ngettext, gettext_lazy as _ + from django.utils.translation import ngettext as ungettext, \ + gettext_lazy as _ from django.utils.safestring import mark_safe from dbtemplates.conf import settings @@ -17,7 +18,8 @@ # use reversion_compare's CompareVersionAdmin or reversion's VersionAdmin as # the base admin class if yes if settings.DBTEMPLATES_USE_REVERSION_COMPARE: - from reversion_compare.admin import CompareVersionAdmin as TemplateModelAdmin + from reversion_compare.admin import CompareVersionAdmin \ + as TemplateModelAdmin elif settings.DBTEMPLATES_USE_REVERSION: from reversion.admin import VersionAdmin as TemplateModelAdmin else: @@ -33,7 +35,8 @@ class CodeMirrorTextArea(forms.Textarea): class Media: css = dict(screen=[posixpath.join( settings.DBTEMPLATES_MEDIA_PREFIX, 'css/editor.css')]) - js = [posixpath.join(settings.DBTEMPLATES_MEDIA_PREFIX, 'js/codemirror.js')] + js = [posixpath.join(settings.DBTEMPLATES_MEDIA_PREFIX, + 'js/codemirror.js')] def render(self, name, value, attrs=None, renderer=None): result = [] @@ -152,7 +155,8 @@ def check_syntax(self, request, queryset): count = len(errors) message = ungettext( "Template syntax check FAILED for %(names)s.", - "Template syntax check FAILED for %(count)d templates: %(names)s.", + "Template syntax check FAILED for " + "%(count)d templates: %(names)s.", count) self.message_user(request, message % {'count': count, 'names': ', '.join(errors)}) diff --git a/dbtemplates/apps.py b/dbtemplates/apps.py index 9b16d38..21141b3 100644 --- a/dbtemplates/apps.py +++ b/dbtemplates/apps.py @@ -4,6 +4,7 @@ except ImportError: from django.utils.translation import gettext_lazy as _ + class DBTemplatesConfig(AppConfig): name = 'dbtemplates' verbose_name = _('Database templates') diff --git a/dbtemplates/conf.py b/dbtemplates/conf.py index 8b8809a..010db5b 100644 --- a/dbtemplates/conf.py +++ b/dbtemplates/conf.py @@ -47,8 +47,8 @@ def configure_use_reversion(self, value): def configure_use_reversion_compare(self, value): if value and 'reversion_compare' not in settings.INSTALLED_APPS: - raise ImproperlyConfigured("Please add 'reversion_compare' to your " - "INSTALLED_APPS setting to make " + raise ImproperlyConfigured("Please add 'reversion_compare' to your" + " INSTALLED_APPS setting to make " "use of it in dbtemplates.") return value diff --git a/dbtemplates/loader.py b/dbtemplates/loader.py index 403c460..5a57f27 100644 --- a/dbtemplates/loader.py +++ b/dbtemplates/loader.py @@ -30,7 +30,8 @@ def get_contents(self, origin): content, _ = self._load_template_source(origin.template_name) return content - def _load_and_store_template(self, template_name, cache_key, site, **params): + def _load_and_store_template(self, template_name, cache_key, site, + **params): template = Template.objects.get(name__exact=template_name, **params) db = router.db_for_read(Template, instance=template) display_name = f'dbtemplates:{db}:{template_name}:{site.domain}' @@ -73,11 +74,11 @@ def _load_template_source(self, template_name, template_dirs=None): try: return self._load_and_store_template(template_name, cache_key, - site, sites__in=[site.id]) + site, sites__in=[site.id]) except (Template.MultipleObjectsReturned, Template.DoesNotExist): try: return self._load_and_store_template(template_name, cache_key, - site, sites__isnull=True) + site, sites__isnull=True) except (Template.MultipleObjectsReturned, Template.DoesNotExist): pass diff --git a/dbtemplates/management/commands/sync_templates.py b/dbtemplates/management/commands/sync_templates.py index b01e61e..7e336e0 100644 --- a/dbtemplates/management/commands/sync_templates.py +++ b/dbtemplates/management/commands/sync_templates.py @@ -1,18 +1,18 @@ import os -from django.contrib.sites.models import Site -from django.core.management.base import CommandError, BaseCommand -from django.template.utils import get_app_template_dirs -from django.template.loader import _engine_list from dbtemplates.models import Template +from django.contrib.sites.models import Site +from django.core.management.base import BaseCommand, CommandError +from django.template.loader import _engine_list +from django.template.utils import get_app_template_dirs -ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2') +ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ("0", "1", "2") DIRS = [] for engine in _engine_list(): DIRS.extend(engine.dirs) DIRS = tuple(DIRS) -app_template_dirs = get_app_template_dirs('templates') +app_template_dirs = get_app_template_dirs("templates") class Command(BaseCommand): @@ -20,36 +20,56 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument( - "-e", "--ext", - dest="ext", action="store", default="html", + "-e", + "--ext", + dest="ext", + action="store", + default="html", help="extension of the files you want to " - "sync with the database [default: %(default)s]") + "sync with the database [default: %(default)s]", + ) parser.add_argument( - "-f", "--force", - action="store_true", dest="force", default=False, - help="overwrite existing database templates") + "-f", + "--force", + action="store_true", + dest="force", + default=False, + help="overwrite existing database templates", + ) parser.add_argument( - "-o", "--overwrite", - action="store", dest="overwrite", default='0', + "-o", + "--overwrite", + action="store", + dest="overwrite", + default="0", help="'0' - ask always, '1' - overwrite database " - "templates from template files, '2' - overwrite " - "template files from database templates") + "templates from template files, '2' - overwrite " + "template files from database templates", + ) parser.add_argument( - "-a", "--app-first", - action="store_true", dest="app_first", default=False, + "-a", + "--app-first", + action="store_true", + dest="app_first", + default=False, help="look for templates in applications " - "directories before project templates") + "directories before project templates", + ) parser.add_argument( - "-d", "--delete", - action="store_true", dest="delete", default=False, - help="Delete templates after syncing") + "-d", + "--delete", + action="store_true", + dest="delete", + default=False, + help="Delete templates after syncing", + ) def handle(self, **options): - extension = options.get('ext') - force = options.get('force') - overwrite = options.get('overwrite') - app_first = options.get('app_first') - delete = options.get('delete') + extension = options.get("ext") + force = options.get("force") + overwrite = options.get("overwrite") + app_first = options.get("app_first") + delete = options.get("delete") if not extension.startswith("."): extension = f".{extension}" @@ -57,8 +77,10 @@ def handle(self, **options): try: site = Site.objects.get_current() except Exception: - raise CommandError("Please make sure to have the sites contrib " - "app installed and setup with a site object") + raise CommandError( + "Please make sure to have the sites contrib " + "app installed and setup with a site object" + ) if app_first: tpl_dirs = app_template_dirs + DIRS @@ -68,11 +90,14 @@ def handle(self, **options): for templatedir in templatedirs: for dirpath, subdirs, filenames in os.walk(templatedir): - for f in [f for f in filenames - if f.endswith(extension) and not f.startswith(".")]: + for f in [ + f + for f in filenames + if f.endswith(extension) and not f.startswith(".") + ]: path = os.path.join(dirpath, f) name = path.split(str(templatedir))[1] - if name.startswith('/'): + if name.startswith("/"): name = name[1:] try: t = Template.on_site.get(name__exact=name) @@ -81,27 +106,35 @@ def handle(self, **options): confirm = input( "\nA '%s' template doesn't exist in the " "database.\nCreate it with '%s'?" - " (y/[n]): """ % (name, path)) - if force or confirm.lower().startswith('y'): - with open(path, encoding='utf-8') as f: + " (y/[n]): " + "" % (name, path) + ) + if force or confirm.lower().startswith("y"): + with open(path, encoding="utf-8") as f: t = Template(name=name, content=f.read()) t.save() t.sites.add(site) else: - while 1: + while True: if overwrite == ALWAYS_ASK: - confirm = input( + _i = ( "\n%(template)s exists in the database.\n" - "(1) Overwrite %(template)s with '%(path)s'\n" - "(2) Overwrite '%(path)s' with %(template)s\n" - "Type 1 or 2 or press to skip: " % - {'template': t.__repr__(), 'path': path}) + "(1) Overwrite %(template)s with '%(path)s'\n" # noqa + "(2) Overwrite '%(path)s' with %(template)s\n" # noqa + "Type 1 or 2 or press to skip: " + % {"template": t.__repr__(), "path": path} + ) + + confirm = input(_i) else: confirm = overwrite - if confirm in ('', FILES_TO_DATABASE, - DATABASE_TO_FILES): + if confirm in ( + "", + FILES_TO_DATABASE, + DATABASE_TO_FILES, + ): if confirm == FILES_TO_DATABASE: - with open(path, encoding='utf-8') as f: + with open(path, encoding="utf-8") as f: t.content = f.read() t.save() t.sites.add(site) @@ -110,9 +143,10 @@ def handle(self, **options): os.remove(path) except OSError: raise CommandError( - f"Couldn't delete {path}") + f"Couldn't delete {path}" + ) elif confirm == DATABASE_TO_FILES: - with open(path, 'w', encoding='utf-8') as f: + with open(path, "w", encoding="utf-8") as f: # noqa f.write(t.content) if delete: t.delete() diff --git a/dbtemplates/migrations/0001_initial.py b/dbtemplates/migrations/0001_initial.py index 5d5b1f4..7ac217f 100644 --- a/dbtemplates/migrations/0001_initial.py +++ b/dbtemplates/migrations/0001_initial.py @@ -1,40 +1,73 @@ import django -from django.db import models, migrations import django.utils.timezone +from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('sites', '0001_initial'), + ("sites", "0001_initial"), ] operations = [ migrations.CreateModel( - name='Template', + name="Template", fields=[ - ('id', models.AutoField( - verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), - ('name', models.CharField( - help_text="Example: 'flatpages/default.html'", max_length=100, verbose_name='name')), - ('content', models.TextField(verbose_name='content', blank=True)), - ('creation_date', models.DateTimeField( - default=django.utils.timezone.now, verbose_name='creation date')), - ('last_changed', models.DateTimeField( - default=django.utils.timezone.now, verbose_name='last changed')), - ('sites', models.ManyToManyField( - to='sites.Site', verbose_name='sites', blank=True)), + ( + "id", + models.AutoField( + verbose_name="ID", + serialize=False, + auto_created=True, + primary_key=True, + ), + ), + ( + "name", + models.CharField( + help_text="Example: 'flatpages/default.html'", + max_length=100, + verbose_name="name", + ), + ), + ( + "content", + models.TextField(verbose_name="content", blank=True), + ), # noqa + ( + "creation_date", + models.DateTimeField( + default=django.utils.timezone.now, + verbose_name="creation date", # noqa + ), + ), + ( + "last_changed", + models.DateTimeField( + default=django.utils.timezone.now, + verbose_name="last changed", # noqa + ), + ), + ( + "sites", + models.ManyToManyField( + to="sites.Site", verbose_name="sites", blank=True + ), + ), ], options={ - 'ordering': ('name',), - 'db_table': 'django_template', - 'verbose_name': 'template', - 'verbose_name_plural': 'templates', + "ordering": ("name",), + "db_table": "django_template", + "verbose_name": "template", + "verbose_name_plural": "templates", }, bases=(models.Model,), managers=[ - ('objects', django.db.models.manager.Manager()), - ('on_site', django.contrib.sites.managers.CurrentSiteManager('sites')), + ("objects", django.db.models.manager.Manager()), + ( + "on_site", + django.contrib.sites.managers.CurrentSiteManager("sites"), + ), # noqa ], ), ] diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 2ca806b..42c03e2 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _ except ImportError: from django.utils.translation import gettext_lazy as _ - + from django.utils.timezone import now diff --git a/dbtemplates/test_cases.py b/dbtemplates/test_cases.py index 8dc1363..ab553e5 100644 --- a/dbtemplates/test_cases.py +++ b/dbtemplates/test_cases.py @@ -125,7 +125,7 @@ def test_sync_templates(self): verbosity=0, overwrite=DATABASE_TO_FILES) self.assertEqual('temp test modified', open(temp_template_path, - encoding='utf-8').read()) + encoding='utf-8').read()) call_command('sync_templates', force=True, verbosity=0, delete=True, overwrite=DATABASE_TO_FILES) diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index dd9d00f..32a0423 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -1,20 +1,23 @@ import django -from django.core import signals +from dbtemplates.conf import settings from django.contrib.sites.models import Site +from django.core import signals from django.template.defaultfilters import slugify -from dbtemplates.conf import settings - def get_cache_backend(): """ Compatibilty wrapper for getting Django's cache backend instance """ - if (django.VERSION[0] >= 3 and django.VERSION[1] >= 2) or django.VERSION[0] >= 4: + if (django.VERSION[0] >= 3 and django.VERSION[1] >= 2) or django.VERSION[ + 0 + ] >= 4: # noqa from django.core.cache import caches + cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND) else: from django.core.cache import _create_cache + cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND) # Some caches -- python-memcached in particular -- need to do a cleanup at # the end of a request cycle. If not implemented in a particular backend @@ -28,11 +31,11 @@ def get_cache_backend(): def get_cache_key(name): current_site = Site.objects.get_current() - return f'dbtemplates::{slugify(name)}::{current_site.pk}' + return f"dbtemplates::{slugify(name)}::{current_site.pk}" def get_cache_notfound_key(name): - return get_cache_key(name) + '::notfound' + return get_cache_key(name) + "::notfound" def remove_notfound_key(instance): From 2b5034951f8e225c577f12fcdb24eceb39a85012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:34:06 +0200 Subject: [PATCH 14/26] Remove unsupported Django versions --- tox.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/tox.ini b/tox.ini index 773fe7a..1a25182 100644 --- a/tox.ini +++ b/tox.ini @@ -28,10 +28,7 @@ setenv = DJANGO_SETTINGS_MODULE = dbtemplates.test_settings deps = -r requirements/tests.txt - dj22: Django<2.3 - dj30: Django<3.1 dj31: Django<3.2 - dj32: Django<3.3 dj40: Django<4.1 dj41: Django<4.2 djmain: https://github.com/django/django/archive/main.tar.gz#egg=django From a68caedc2d173ff3e247cee159189d4fd2136a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:34:14 +0200 Subject: [PATCH 15/26] Revert unintentional typo --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 1a25182..4fce5d6 100644 --- a/tox.ini +++ b/tox.ini @@ -46,4 +46,4 @@ deps = flake8 [flake8] exclude=.tox -pignore=E501,E127,E128,E124 +ignore=E501,E127,E128,E124 From 6dd23d2325ce0f66747434139a312ef72a1906ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:34:29 +0200 Subject: [PATCH 16/26] Proper links to CI badge --- README.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index de0c92f..fee2f2e 100644 --- a/README.rst +++ b/README.rst @@ -5,9 +5,8 @@ django-dbtemplates :alt: Jazzband :target: https://jazzband.co/ -.. image:: https://github.com/mpasternak/django-dbtemplates-iplweb/workflows/Test/badge.svg - :target: https://github.com/mpasternak/django-dbtemplates-iplweb/actions - :alt: GitHub Actions +.. image:: https://github.com/jazzband/django-dbtemplates/workflows/Test/badge.svg + :target: https://github.com/jazzband/django-dbtemplates/actions .. image:: https://codecov.io/github/jazzband/django-dbtemplates/coverage.svg?branch=master :alt: Codecov From e08a8d3950f4d7768a41f683c89f0b327bf993ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:35:13 +0200 Subject: [PATCH 17/26] Document changes in 4.0 (unreleased) --- docs/changelog.txt | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c6e63b0..d2deee4 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,13 +1,6 @@ Changelog ========= -v4.1 (2022-06-15, iplweb) - -* Python 3.9, 3.10 support - -* Django 4.x support - - v4.0 (unreleased) ----------------- @@ -17,12 +10,14 @@ v4.0 (unreleased) * Dropped support for Python 2.7. -* Added support for Python 3.8. +* Added support for Python 3.8, 3.9, 3.10. * Moved test runner to GitHub Actions: http://github.com/jazzband/django-dbtemplates/actions +* Django 4.x support + v3.0 (2019-01-27) ----------------- From 36fbb80fc07998b62d8a56804b975b1d30701acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:38:39 +0200 Subject: [PATCH 18/26] Update to Django 4.0 i18n style --- dbtemplates/admin.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dbtemplates/admin.py b/dbtemplates/admin.py index 9bfefa7..1c9095f 100644 --- a/dbtemplates/admin.py +++ b/dbtemplates/admin.py @@ -3,15 +3,18 @@ from django.contrib import admin from django.core.exceptions import ImproperlyConfigured try: - from django.utils.translation import ungettext, ugettext_lazy as _ + # Django 4.0 + from django.utils.translation import gettext_lazy as _ + from django.utils.translation import ngettext except ImportError: - from django.utils.translation import ngettext as ungettext, \ - gettext_lazy as _ + # Before Django 4.0 + from django.utils.translation import ugettext_lazy as _ + from django.utils.translation import ungettext as ngettext + from django.utils.safestring import mark_safe from dbtemplates.conf import settings -from dbtemplates.models import (Template, remove_cached_template, - add_template_to_cache) +from dbtemplates.models import Template, add_template_to_cache, remove_cached_template from dbtemplates.utils.template import check_template_syntax # Check if either django-reversion-compare or django-reversion is installed and @@ -125,7 +128,7 @@ def invalidate_cache(self, request, queryset): for template in queryset: remove_cached_template(template) count = queryset.count() - message = ungettext( + message = ngettext( "Cache of one template successfully invalidated.", "Cache of %(count)d templates successfully invalidated.", count) @@ -137,7 +140,7 @@ def repopulate_cache(self, request, queryset): for template in queryset: add_template_to_cache(template) count = queryset.count() - message = ungettext( + message = ngettext( "Cache successfully repopulated with one template.", "Cache successfully repopulated with %(count)d templates.", count) @@ -153,7 +156,7 @@ def check_syntax(self, request, queryset): errors.append(f'{template.name}: {error}') if errors: count = len(errors) - message = ungettext( + message = ngettext( "Template syntax check FAILED for %(names)s.", "Template syntax check FAILED for " "%(count)d templates: %(names)s.", @@ -162,7 +165,7 @@ def check_syntax(self, request, queryset): {'count': count, 'names': ', '.join(errors)}) else: count = queryset.count() - message = ungettext( + message = ngettext( "Template syntax OK.", "Template syntax OK for %(count)d templates.", count) self.message_user(request, message % {'count': count}) From b6b0bf48ba2d2a55a6da6059e8eac83abfd9b078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:38:47 +0200 Subject: [PATCH 19/26] Django 4.0 i18n fixes --- dbtemplates/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 42c03e2..34620d5 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -8,9 +8,11 @@ from django.db.models import signals from django.template import TemplateDoesNotExist try: - from django.utils.translation import ugettext_lazy as _ -except ImportError: + # Django >= 4.0 from django.utils.translation import gettext_lazy as _ +except ImportError: + # Django 3.2 + from django.utils.translation import ugettext_lazy as _ from django.utils.timezone import now From 98bc9921b060a254c21a04e1784c953b6da0bf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:41:44 +0200 Subject: [PATCH 20/26] Remove trailing whitespace --- dbtemplates/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbtemplates/models.py b/dbtemplates/models.py index 34620d5..f846b2b 100644 --- a/dbtemplates/models.py +++ b/dbtemplates/models.py @@ -8,7 +8,7 @@ from django.db.models import signals from django.template import TemplateDoesNotExist try: - # Django >= 4.0 + # Django >= 4.0 from django.utils.translation import gettext_lazy as _ except ImportError: # Django 3.2 From 2c8dc827211e95aaf42f27ac7976e9eac9ba9f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 9 Aug 2022 17:50:42 +0200 Subject: [PATCH 21/26] Update tox.ini Co-authored-by: Hugo van Kemenade --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 4fce5d6..16d6e9c 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ setenv = DJANGO_SETTINGS_MODULE = dbtemplates.test_settings deps = -r requirements/tests.txt - dj31: Django<3.2 + dj32: Django<3.3 dj40: Django<4.1 dj41: Django<4.2 djmain: https://github.com/django/django/archive/main.tar.gz#egg=django From 5a363dbe3471e2ef5d0ea55d77cfb4f3305fecae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 10 Aug 2022 10:47:46 +0200 Subject: [PATCH 22/26] Update setup.py Co-authored-by: Hugo van Kemenade --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8b2cbb0..5a43497 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def read(*parts): setup( - name="django-dbtemplates-iplweb", + name="django-dbtemplates", use_scm_version={"version_scheme": "post-release"}, setup_requires=["setuptools_scm"], description="Template loader for templates stored in the database", From 45e216b8ac377d53dbaeaff576629f9ae91d7f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 10 Aug 2022 22:28:21 +0200 Subject: [PATCH 23/26] Remove compatibility wrapper --- dbtemplates/utils/cache.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index 32a0423..ef86a53 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -9,16 +9,9 @@ def get_cache_backend(): """ Compatibilty wrapper for getting Django's cache backend instance """ - if (django.VERSION[0] >= 3 and django.VERSION[1] >= 2) or django.VERSION[ - 0 - ] >= 4: # noqa - from django.core.cache import caches - - cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND) - else: - from django.core.cache import _create_cache - - cache = _create_cache(settings.DBTEMPLATES_CACHE_BACKEND) + from django.core.cache import caches + cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND) + # Some caches -- python-memcached in particular -- need to do a cleanup at # the end of a request cycle. If not implemented in a particular backend # cache.close is a no-op From 6ca53981d3bc1a1c63736c18281b790ddf5b1eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 10 Aug 2022 22:28:36 +0200 Subject: [PATCH 24/26] Test all the supported versions --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 4fce5d6..d0178be 100644 --- a/tox.ini +++ b/tox.ini @@ -4,8 +4,8 @@ usedevelop = True minversion = 1.8 envlist = flake8 - py3{7,8,9}-dj22 py3{7,8,9,10,11}-dj32 + py3{8,9,10,11}-dj{40,41,main} [gh-actions] python = @@ -28,7 +28,7 @@ setenv = DJANGO_SETTINGS_MODULE = dbtemplates.test_settings deps = -r requirements/tests.txt - dj31: Django<3.2 + dj32: Django<3.3 dj40: Django<4.1 dj41: Django<4.2 djmain: https://github.com/django/django/archive/main.tar.gz#egg=django From fac9f6a80757ec63d581947be0c81609e1fc567c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 10 Aug 2022 22:29:46 +0200 Subject: [PATCH 25/26] Mention dropping Django below 3.2 --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index d2deee4..03a3c16 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -8,7 +8,7 @@ v4.0 (unreleased) This is a backwards-incompatible release! -* Dropped support for Python 2.7. +* Dropped support for Python 2.7 and Django < 3.2. * Added support for Python 3.8, 3.9, 3.10. From fa72b2771b350d62f607945c5e27c44182fa8912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Wed, 10 Aug 2022 22:32:23 +0200 Subject: [PATCH 26/26] Flake8 --- dbtemplates/utils/cache.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dbtemplates/utils/cache.py b/dbtemplates/utils/cache.py index ef86a53..923ee59 100644 --- a/dbtemplates/utils/cache.py +++ b/dbtemplates/utils/cache.py @@ -1,4 +1,3 @@ -import django from dbtemplates.conf import settings from django.contrib.sites.models import Site from django.core import signals @@ -11,7 +10,7 @@ def get_cache_backend(): """ from django.core.cache import caches cache = caches.create_connection(settings.DBTEMPLATES_CACHE_BACKEND) - + # Some caches -- python-memcached in particular -- need to do a cleanup at # the end of a request cycle. If not implemented in a particular backend # cache.close is a no-op