mirror of
https://github.com/jazzband/django-dbtemplates.git
synced 2026-03-16 22:20:28 +00:00
Merge pull request #125 from jazzband/add-3.10
Add support for Python 3.10
This commit is contained in:
commit
8e8b76fc0a
16 changed files with 60 additions and 51 deletions
6
.github/workflows/release.yml
vendored
6
.github/workflows/release.yml
vendored
|
|
@ -11,14 +11,14 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: 3.8
|
python-version: "3.10"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
10
.github/workflows/test.yml
vendored
10
.github/workflows/test.yml
vendored
|
|
@ -9,13 +9,13 @@ jobs:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 5
|
max-parallel: 5
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.6', '3.7', '3.8', '3.9']
|
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11-dev']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v2
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ jobs:
|
||||||
echo "::set-output name=dir::$(pip cache dir)"
|
echo "::set-output name=dir::$(pip cache dir)"
|
||||||
|
|
||||||
- name: Cache
|
- name: Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.pip-cache.outputs.dir }}
|
path: ${{ steps.pip-cache.outputs.dir }}
|
||||||
key:
|
key:
|
||||||
|
|
@ -43,6 +43,6 @@ jobs:
|
||||||
tox -v
|
tox -v
|
||||||
|
|
||||||
- name: Upload coverage
|
- name: Upload coverage
|
||||||
uses: codecov/codecov-action@v1
|
uses: codecov/codecov-action@v2
|
||||||
with:
|
with:
|
||||||
name: Python ${{ matrix.python-version }}
|
name: Python ${{ matrix.python-version }}
|
||||||
|
|
|
||||||
15
.pre-commit-config.yaml
Normal file
15
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v2.34.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py37-plus]
|
||||||
|
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.3.0
|
||||||
|
hooks:
|
||||||
|
- id: check-merge-conflict
|
||||||
|
- id: check-yaml
|
||||||
|
|
||||||
|
ci:
|
||||||
|
autoupdate_schedule: quarterly
|
||||||
|
|
@ -35,8 +35,8 @@ class CodeMirrorTextArea(forms.Textarea):
|
||||||
def render(self, name, value, attrs=None, renderer=None):
|
def render(self, name, value, attrs=None, renderer=None):
|
||||||
result = []
|
result = []
|
||||||
result.append(
|
result.append(
|
||||||
super(CodeMirrorTextArea, self).render(name, value, attrs))
|
super().render(name, value, attrs))
|
||||||
result.append(u"""
|
result.append("""
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var editor = CodeMirror.fromTextArea('id_%(name)s', {
|
var editor = CodeMirror.fromTextArea('id_%(name)s', {
|
||||||
path: "%(media_prefix)sjs/",
|
path: "%(media_prefix)sjs/",
|
||||||
|
|
@ -50,7 +50,7 @@ class CodeMirrorTextArea(forms.Textarea):
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
""" % dict(media_prefix=settings.DBTEMPLATES_MEDIA_PREFIX, name=name))
|
""" % dict(media_prefix=settings.DBTEMPLATES_MEDIA_PREFIX, name=name))
|
||||||
return mark_safe(u"".join(result))
|
return mark_safe("".join(result))
|
||||||
|
|
||||||
|
|
||||||
if settings.DBTEMPLATES_USE_CODEMIRROR:
|
if settings.DBTEMPLATES_USE_CODEMIRROR:
|
||||||
|
|
@ -144,7 +144,7 @@ class TemplateAdmin(TemplateModelAdmin):
|
||||||
for template in queryset:
|
for template in queryset:
|
||||||
valid, error = check_template_syntax(template)
|
valid, error = check_template_syntax(template)
|
||||||
if not valid:
|
if not valid:
|
||||||
errors.append('%s: %s' % (template.name, error))
|
errors.append(f'{template.name}: {error}')
|
||||||
if errors:
|
if errors:
|
||||||
count = len(errors)
|
count = len(errors)
|
||||||
message = ungettext(
|
message = ungettext(
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ class Loader(BaseLoader):
|
||||||
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)
|
template = Template.objects.get(name__exact=template_name, **params)
|
||||||
db = router.db_for_read(Template, instance=template)
|
db = router.db_for_read(Template, instance=template)
|
||||||
display_name = 'dbtemplates:%s:%s:%s' % (db, template_name, site.domain)
|
display_name = f'dbtemplates:{db}:{template_name}:{site.domain}'
|
||||||
return set_and_return(cache_key, template.content, display_name)
|
return set_and_return(cache_key, template.content, display_name)
|
||||||
|
|
||||||
def _load_template_source(self, template_name, template_dirs=None):
|
def _load_template_source(self, template_name, template_dirs=None):
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class Command(BaseCommand):
|
||||||
for template in Template.objects.all():
|
for template in Template.objects.all():
|
||||||
valid, error = check_template_syntax(template)
|
valid, error = check_template_syntax(template)
|
||||||
if not valid:
|
if not valid:
|
||||||
errors.append('%s: %s' % (template.name, error))
|
errors.append(f'{template.name}: {error}')
|
||||||
if errors:
|
if errors:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
'Some templates contained errors\n%s' % '\n'.join(errors))
|
'Some templates contained errors\n%s' % '\n'.join(errors))
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class Command(BaseCommand):
|
||||||
verbosity = int(options.get('verbosity', 1))
|
verbosity = int(options.get('verbosity', 1))
|
||||||
for error_code in (404, 500):
|
for error_code in (404, 500):
|
||||||
template, created = Template.objects.get_or_create(
|
template, created = Template.objects.get_or_create(
|
||||||
name="%s.html" % error_code)
|
name=f"{error_code}.html")
|
||||||
if created or (not created and force):
|
if created or (not created and force):
|
||||||
template.content = TEMPLATES.get(error_code, '')
|
template.content = TEMPLATES.get(error_code, '')
|
||||||
template.save()
|
template.save()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.management.base import CommandError, BaseCommand
|
from django.core.management.base import CommandError, BaseCommand
|
||||||
|
|
@ -53,7 +52,7 @@ class Command(BaseCommand):
|
||||||
delete = options.get('delete')
|
delete = options.get('delete')
|
||||||
|
|
||||||
if not extension.startswith("."):
|
if not extension.startswith("."):
|
||||||
extension = ".%s" % extension
|
extension = f".{extension}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
site = Site.objects.get_current()
|
site = Site.objects.get_current()
|
||||||
|
|
@ -84,7 +83,7 @@ class Command(BaseCommand):
|
||||||
"database.\nCreate it with '%s'?"
|
"database.\nCreate it with '%s'?"
|
||||||
" (y/[n]): """ % (name, path))
|
" (y/[n]): """ % (name, path))
|
||||||
if force or confirm.lower().startswith('y'):
|
if force or confirm.lower().startswith('y'):
|
||||||
with io.open(path, encoding='utf-8') as f:
|
with open(path, encoding='utf-8') as f:
|
||||||
t = Template(name=name, content=f.read())
|
t = Template(name=name, content=f.read())
|
||||||
t.save()
|
t.save()
|
||||||
t.sites.add(site)
|
t.sites.add(site)
|
||||||
|
|
@ -102,7 +101,7 @@ class Command(BaseCommand):
|
||||||
if confirm in ('', FILES_TO_DATABASE,
|
if confirm in ('', FILES_TO_DATABASE,
|
||||||
DATABASE_TO_FILES):
|
DATABASE_TO_FILES):
|
||||||
if confirm == FILES_TO_DATABASE:
|
if confirm == FILES_TO_DATABASE:
|
||||||
with io.open(path, encoding='utf-8') as f:
|
with open(path, encoding='utf-8') as f:
|
||||||
t.content = f.read()
|
t.content = f.read()
|
||||||
t.save()
|
t.save()
|
||||||
t.sites.add(site)
|
t.sites.add(site)
|
||||||
|
|
@ -111,9 +110,9 @@ class Command(BaseCommand):
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except OSError:
|
except OSError:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
u"Couldn't delete %s" % path)
|
f"Couldn't delete {path}")
|
||||||
elif confirm == DATABASE_TO_FILES:
|
elif confirm == DATABASE_TO_FILES:
|
||||||
with io.open(path, 'w', encoding='utf-8') as f:
|
with open(path, 'w', encoding='utf-8') as f:
|
||||||
f.write(t.content)
|
f.write(t.content)
|
||||||
if delete:
|
if delete:
|
||||||
t.delete()
|
t.delete()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import django
|
import django
|
||||||
from django.db import models, migrations
|
from django.db import models, migrations
|
||||||
import django.utils.timezone
|
import django.utils.timezone
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
from dbtemplates.conf import settings
|
from dbtemplates.conf import settings
|
||||||
from dbtemplates.utils.cache import (add_template_to_cache,
|
from dbtemplates.utils.cache import (add_template_to_cache,
|
||||||
remove_cached_template)
|
remove_cached_template)
|
||||||
|
|
@ -20,7 +19,7 @@ class Template(models.Model):
|
||||||
name = models.CharField(_('name'), max_length=100,
|
name = models.CharField(_('name'), max_length=100,
|
||||||
help_text=_("Example: 'flatpages/default.html'"))
|
help_text=_("Example: 'flatpages/default.html'"))
|
||||||
content = models.TextField(_('content'), blank=True)
|
content = models.TextField(_('content'), blank=True)
|
||||||
sites = models.ManyToManyField(Site, verbose_name=_(u'sites'),
|
sites = models.ManyToManyField(Site, verbose_name=_('sites'),
|
||||||
blank=True)
|
blank=True)
|
||||||
creation_date = models.DateTimeField(_('creation date'),
|
creation_date = models.DateTimeField(_('creation date'),
|
||||||
default=now)
|
default=now)
|
||||||
|
|
@ -59,7 +58,7 @@ class Template(models.Model):
|
||||||
# populate the template instance with its content.
|
# populate the template instance with its content.
|
||||||
if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT and not self.content:
|
if settings.DBTEMPLATES_AUTO_POPULATE_CONTENT and not self.content:
|
||||||
self.populate()
|
self.populate()
|
||||||
super(Template, self).save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def add_default_site(instance, **kwargs):
|
def add_default_site(instance, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -103,9 +102,9 @@ class DbTemplatesTestCase(TestCase):
|
||||||
old_template_dirs = settings.TEMPLATES[0].get('DIRS', [])
|
old_template_dirs = settings.TEMPLATES[0].get('DIRS', [])
|
||||||
temp_template_dir = tempfile.mkdtemp('dbtemplates')
|
temp_template_dir = tempfile.mkdtemp('dbtemplates')
|
||||||
temp_template_path = os.path.join(temp_template_dir, 'temp_test.html')
|
temp_template_path = os.path.join(temp_template_dir, 'temp_test.html')
|
||||||
temp_template = io.open(temp_template_path, 'w', encoding='utf-8')
|
temp_template = open(temp_template_path, 'w', encoding='utf-8')
|
||||||
try:
|
try:
|
||||||
temp_template.write(u'temp test')
|
temp_template.write('temp test')
|
||||||
settings.TEMPLATES[0]['DIRS'] = (temp_template_dir,)
|
settings.TEMPLATES[0]['DIRS'] = (temp_template_dir,)
|
||||||
# these works well if is not settings patched at runtime
|
# these works well if is not settings patched at runtime
|
||||||
# for supporting django < 1.7 tests we must patch dirs in runtime
|
# for supporting django < 1.7 tests we must patch dirs in runtime
|
||||||
|
|
@ -120,12 +119,12 @@ class DbTemplatesTestCase(TestCase):
|
||||||
Template.objects.filter(name='temp_test.html').exists())
|
Template.objects.filter(name='temp_test.html').exists())
|
||||||
|
|
||||||
t = Template.objects.get(name='temp_test.html')
|
t = Template.objects.get(name='temp_test.html')
|
||||||
t.content = u'temp test modified'
|
t.content = 'temp test modified'
|
||||||
t.save()
|
t.save()
|
||||||
call_command('sync_templates', force=True,
|
call_command('sync_templates', force=True,
|
||||||
verbosity=0, overwrite=DATABASE_TO_FILES)
|
verbosity=0, overwrite=DATABASE_TO_FILES)
|
||||||
self.assertEqual(u'temp test modified',
|
self.assertEqual('temp test modified',
|
||||||
io.open(temp_template_path,
|
open(temp_template_path,
|
||||||
encoding='utf-8').read())
|
encoding='utf-8').read())
|
||||||
|
|
||||||
call_command('sync_templates', force=True, verbosity=0,
|
call_command('sync_templates', force=True, verbosity=0,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ cache = get_cache_backend()
|
||||||
|
|
||||||
def get_cache_key(name):
|
def get_cache_key(name):
|
||||||
current_site = Site.objects.get_current()
|
current_site = Site.objects.get_current()
|
||||||
return 'dbtemplates::%s::%s' % (slugify(name), current_site.pk)
|
return f'dbtemplates::{slugify(name)}::{current_site.pk}'
|
||||||
|
|
||||||
|
|
||||||
def get_cache_notfound_key(name):
|
def get_cache_notfound_key(name):
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# django-dbtemplates documentation build configuration file, created by
|
# django-dbtemplates documentation build configuration file, created by
|
||||||
# sphinx-quickstart on Fri Oct 9 14:52:11 2009.
|
# sphinx-quickstart on Fri Oct 9 14:52:11 2009.
|
||||||
|
|
@ -37,8 +36,8 @@ source_suffix = '.txt'
|
||||||
master_doc = 'index'
|
master_doc = 'index'
|
||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'django-dbtemplates'
|
project = 'django-dbtemplates'
|
||||||
copyright = u'2007-2019, Jannis Leidel and contributors'
|
copyright = '2007-2019, Jannis Leidel and contributors'
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
|
|
@ -177,8 +176,8 @@ htmlhelp_basename = 'django-dbtemplatesdoc'
|
||||||
# Grouping the document tree into LaTeX files. List of tuples
|
# Grouping the document tree into LaTeX files. List of tuples
|
||||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||||
latex_documents = [
|
latex_documents = [
|
||||||
('index', 'django-dbtemplates.tex', u'django-dbtemplates Documentation',
|
('index', 'django-dbtemplates.tex', 'django-dbtemplates Documentation',
|
||||||
u'Jannis Leidel and contributors', 'manual'),
|
'Jannis Leidel and contributors', 'manual'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# The name of an image file (relative to this directory) to place at the top of
|
# The name of an image file (relative to this directory) to place at the top of
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,3 @@
|
||||||
source-dir = docs/
|
source-dir = docs/
|
||||||
build-dir = docs/_build
|
build-dir = docs/_build
|
||||||
all_files = 1
|
all_files = 1
|
||||||
|
|
||||||
[bdist_wheel]
|
|
||||||
universal=1
|
|
||||||
|
|
|
||||||
8
setup.py
8
setup.py
|
|
@ -5,7 +5,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
def read(*parts):
|
def read(*parts):
|
||||||
filename = os.path.join(os.path.dirname(__file__), *parts)
|
filename = os.path.join(os.path.dirname(__file__), *parts)
|
||||||
with io.open(filename, encoding="utf-8") as fp:
|
with open(filename, encoding="utf-8") as fp:
|
||||||
return fp.read()
|
return fp.read()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -27,6 +27,7 @@ setup(
|
||||||
"static/dbtemplates/js/*.js",
|
"static/dbtemplates/js/*.js",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
python_requires=">=3.7",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Environment :: Web Environment",
|
"Environment :: Web Environment",
|
||||||
|
|
@ -35,10 +36,11 @@ setup(
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
"Programming Language :: Python",
|
"Programming Language :: Python",
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"Programming Language :: Python :: 3.5",
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
"Programming Language :: Python :: 3.6",
|
|
||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
"Framework :: Django",
|
"Framework :: Django",
|
||||||
],
|
],
|
||||||
install_requires=["django-appconf >= 0.4"],
|
install_requires=["django-appconf >= 0.4"],
|
||||||
|
|
|
||||||
14
tox.ini
14
tox.ini
|
|
@ -4,22 +4,24 @@ usedevelop = True
|
||||||
minversion = 1.8
|
minversion = 1.8
|
||||||
envlist =
|
envlist =
|
||||||
flake8
|
flake8
|
||||||
py3{6,7,8,9}-dj22
|
py3{7,8,9}-dj22
|
||||||
py3{6,7,8,9}-dj32
|
py3{7,8,9,10,11}-dj32
|
||||||
|
|
||||||
[gh-actions]
|
[gh-actions]
|
||||||
python =
|
python =
|
||||||
3.6: py36
|
|
||||||
3.7: py37
|
3.7: py37
|
||||||
3.8: py38, flake8
|
3.8: py38
|
||||||
3.9: py39
|
3.9: py39
|
||||||
|
3.10: py310, flake8
|
||||||
|
3.11: py311
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
basepython =
|
basepython =
|
||||||
py36: python3.6
|
|
||||||
py37: python3.7
|
py37: python3.7
|
||||||
py38: python3.8
|
py38: python3.8
|
||||||
py39: python3.9
|
py39: python3.9
|
||||||
|
py310: python3.10
|
||||||
|
py311: python3.11
|
||||||
usedevelop = true
|
usedevelop = true
|
||||||
setenv =
|
setenv =
|
||||||
DJANGO_SETTINGS_MODULE = dbtemplates.test_settings
|
DJANGO_SETTINGS_MODULE = dbtemplates.test_settings
|
||||||
|
|
@ -36,7 +38,7 @@ commands =
|
||||||
coverage xml
|
coverage xml
|
||||||
|
|
||||||
[testenv:flake8]
|
[testenv:flake8]
|
||||||
basepython = python3.9
|
basepython = python3.10
|
||||||
commands = flake8 dbtemplates
|
commands = flake8 dbtemplates
|
||||||
deps = flake8
|
deps = flake8
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue