Skip to content

Commit d7ecd93

Browse files
committed
Port to Python 3 and removed legacy code
1 parent 1e2a4f0 commit d7ecd93

20 files changed

+168
-248
lines changed

.coveragerc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[run]
2+
source = dbtemplates
3+
branch = 1
4+
5+
[report]
6+
omit = *tests*,*migrations*

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ MANIFEST
44
build
55
dist
66
*.egg-info
7-
example/example.db
87
docs/_build
98
.tox/
109
*.egg/

.travis.yml

+27-29
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1+
language: python
2+
python: 3.5
13
sudo: false
24
cache: pip
3-
language: python
4-
python:
5-
- 2.6
6-
- 2.7
7-
install:
8-
- pip install -e .
9-
- pip install -r requirements/tests.txt Django==$DJANGO
10-
before_script:
11-
- flake8 dbtemplates --ignore=E501 --exclude=migrations
12-
script:
13-
- coverage run --branch --source=dbtemplates `which django-admin.py` test dbtemplates
14-
- coverage report --omit="dbtemplates/test*,dbtemplates/migrations*"
155
env:
16-
global:
17-
- DJANGO_SETTINGS_MODULE=dbtemplates.test_settings
18-
matrix:
19-
- DJANGO="1.4.5 importlib"
20-
- DJANGO="1.5.1 importlib"
21-
- DJANGO=1.7.8
22-
- DJANGO=1.8.11
23-
- DJANGO=1.9.4
24-
matrix:
25-
exclude:
26-
- python: 2.6
27-
env: DJANGO=1.7.8
28-
- python: 2.6
29-
env: DJANGO=1.8.11
30-
- python: 2.6
31-
env: DJANGO=1.9.4
6+
- TOXENV=flake8-py27
7+
- TOXENV=flake8-py35
8+
- TOXENV=readme-py27
9+
- TOXENV=py27-dj18
10+
- TOXENV=py27-dj19
11+
- TOXENV=py27-dj110
12+
- TOXENV=py27-djmaster
13+
- TOXENV=py34-dj18
14+
- TOXENV=py34-dj19
15+
- TOXENV=py34-dj110
16+
- TOXENV=py34-djmaster
17+
- TOXENV=py35-dj18
18+
- TOXENV=py35-dj19
19+
- TOXENV=py35-dj110
20+
- TOXENV=py35-djmaster
21+
- TOXENV=pypy-dj18
22+
- TOXENV=pypy-dj19
23+
- TOXENV=pypy-dj110
24+
- TOXENV=pypy-djmaster
25+
install:
26+
- pip install tox codecov
27+
script: tox -v
28+
after_success:
29+
- codecov
3230
deploy:
3331
provider: pypi
3432
user: jazzband
@@ -39,4 +37,4 @@ deploy:
3937
tags: true
4038
repo: jazzband/django-dbtemplates
4139
python: "2.7"
42-
condition: "$DJANGO = 1.8.11"
40+
condition: "$TOXENV = py27-dj110"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2007-2012, Jannis Leidel and contributors
1+
Copyright (c) 2007-2016, Jannis Leidel and contributors
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

dbtemplates/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# following PEP 386
2-
__version__ = "1.3.2"
1+
__version__ = "2.0"

dbtemplates/loader.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import django
21
from django.contrib.sites.models import Site
32
from django.db import router
43
from django.template import TemplateDoesNotExist
4+
from django.template.loaders.base import Loader as BaseLoader
55

66
from dbtemplates.models import Template
77
from dbtemplates.utils.cache import (cache, get_cache_key,
88
set_and_return, get_cache_notfound_key)
99

10-
if django.VERSION[:2] >= (1, 8):
11-
from django.template.loaders.base import Loader as BaseLoader
12-
else:
13-
from django.template.loader import BaseLoader # noqa
14-
1510

1611
class Loader(BaseLoader):
1712
"""
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from django.core.management.base import CommandError, NoArgsCommand
1+
from django.core.management.base import CommandError, BaseCommand
22

33
from dbtemplates.models import Template
44
from dbtemplates.utils.template import check_template_syntax
55

66

7-
class Command(NoArgsCommand):
7+
class Command(BaseCommand):
88
help = "Ensures templates stored in the database don't have syntax errors."
99

10-
def handle_noargs(self, **options):
10+
def handle(self, **options):
1111
errors = []
1212
for template in Template.objects.all():
1313
valid, error = check_template_syntax(template)
@@ -16,6 +16,4 @@ def handle_noargs(self, **options):
1616
if errors:
1717
raise CommandError(
1818
'Some templates contained errors\n%s' % '\n'.join(errors))
19-
# NOTE: printing instead of using self.stdout.write to maintain
20-
# Django 1.2 compatibility
21-
print('OK')
19+
self.stdout.write('OK')

dbtemplates/management/commands/create_error_templates.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import sys
2-
from optparse import make_option
3-
4-
from django.core.management.base import CommandError, NoArgsCommand
2+
from django.core.management.base import CommandError, BaseCommand
53
from django.contrib.sites.models import Site
64

75
from dbtemplates.models import Template
@@ -26,14 +24,15 @@
2624
}
2725

2826

29-
class Command(NoArgsCommand):
27+
class Command(BaseCommand):
3028
help = "Creates the default error templates as database template objects."
31-
option_list = NoArgsCommand.option_list + (
32-
make_option("-f", "--force", action="store_true", dest="force",
33-
default=False,
34-
help="overwrite existing database templates"),)
3529

36-
def handle_noargs(self, **options):
30+
def add_arguments(self, parser):
31+
parser.add_argument(
32+
"-f", "--force", action="store_true", dest="force",
33+
default=False, help="overwrite existing database templates")
34+
35+
def handle(self, **options):
3736
force = options.get('force')
3837
try:
3938
site = Site.objects.get_current()

dbtemplates/management/commands/sync_templates.py

+34-40
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,54 @@
11
import os
22
import codecs
3-
from optparse import make_option
4-
from django import VERSION
53
from django.contrib.sites.models import Site
6-
from django.core.management.base import CommandError, NoArgsCommand
4+
from django.core.management.base import CommandError, BaseCommand
5+
from django.template.utils import get_app_template_dirs
6+
from django.template.loader import _engine_list
77
try:
88
from django.utils.six import input as raw_input
99
except ImportError:
1010
pass
1111

12-
from dbtemplates.conf import settings
1312
from dbtemplates.models import Template
1413

1514
ALWAYS_ASK, FILES_TO_DATABASE, DATABASE_TO_FILES = ('0', '1', '2')
1615

1716
DIRS = []
17+
for engine in _engine_list():
18+
DIRS.extend(engine.dirs)
19+
app_template_dirs = get_app_template_dirs('templates')
1820

19-
if VERSION[:2] < (1, 8):
20-
from django.template.loaders.app_directories import app_template_dirs
21-
DIRS = settings.TEMPLATE_DIRS
22-
else:
23-
from django.template.utils import get_app_template_dirs
24-
from django.template.loader import _engine_list
25-
for engine in _engine_list():
26-
DIRS.extend(engine.dirs)
27-
app_template_dirs = get_app_template_dirs('templates')
2821

29-
30-
class Command(NoArgsCommand):
22+
class Command(BaseCommand):
3123
help = "Syncs file system templates with the database bidirectionally."
32-
option_list = NoArgsCommand.option_list + (
33-
make_option("-e", "--ext",
34-
dest="ext", action="store", default="html",
35-
help="extension of the files you want to "
36-
"sync with the database [default: %default]"),
37-
make_option("-f", "--force",
38-
action="store_true", dest="force", default=False,
39-
help="overwrite existing database templates"),
40-
make_option("-o", "--overwrite",
41-
action="store", dest="overwrite", default='0',
42-
help="'0' - ask always, '1' - overwrite database "
43-
"templates from template files, '2' - overwrite "
44-
"template files from database templates"),
45-
make_option("-a", "--app-first",
46-
action="store_true", dest="app_first", default=False,
47-
help="look for templates in applications "
48-
"directories before project templates"),
49-
make_option("-d", "--delete",
50-
action="store_true", dest="delete", default=False,
51-
help="Delete templates after syncing"))
5224

53-
def handle_noargs(self, **options):
25+
def add_arguments(self, parser):
26+
parser.add_argument(
27+
"-e", "--ext",
28+
dest="ext", action="store", default="html",
29+
help="extension of the files you want to "
30+
"sync with the database [default: %default]")
31+
parser.add_argument(
32+
"-f", "--force",
33+
action="store_true", dest="force", default=False,
34+
help="overwrite existing database templates")
35+
parser.add_argument(
36+
"-o", "--overwrite",
37+
action="store", dest="overwrite", default='0',
38+
help="'0' - ask always, '1' - overwrite database "
39+
"templates from template files, '2' - overwrite "
40+
"template files from database templates")
41+
parser.add_argument(
42+
"-a", "--app-first",
43+
action="store_true", dest="app_first", default=False,
44+
help="look for templates in applications "
45+
"directories before project templates")
46+
parser.add_argument(
47+
"-d", "--delete",
48+
action="store_true", dest="delete", default=False,
49+
help="Delete templates after syncing")
50+
51+
def handle(self, **options):
5452
extension = options.get('ext')
5553
force = options.get('force')
5654
overwrite = options.get('overwrite')
@@ -66,10 +64,6 @@ def handle_noargs(self, **options):
6664
raise CommandError("Please make sure to have the sites contrib "
6765
"app installed and setup with a site object")
6866

69-
if not type(settings.TEMPLATE_DIRS) in (tuple, list):
70-
raise CommandError("Please make sure settings.TEMPLATE_DIRS is a "
71-
"list or tuple.")
72-
7367
if app_first:
7468
tpl_dirs = app_template_dirs + DIRS
7569
else:

dbtemplates/migrations/0001_initial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Migration(migrations.Migration):
3636
'verbose_name_plural': 'templates',
3737
},
3838
bases=(models.Model,),
39-
managers = [
39+
managers=[
4040
('objects', django.db.models.manager.Manager()),
4141
('on_site', django.contrib.sites.managers.CurrentSiteManager(
4242
b'sites')),

dbtemplates/models.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
from django.db.models import signals
1010
from django.template import TemplateDoesNotExist
1111
from django.utils.translation import ugettext_lazy as _
12-
13-
try:
14-
from django.utils.timezone import now
15-
except ImportError:
16-
from datetime import datetime
17-
now = datetime.now
12+
from django.utils.timezone import now
1813

1914

2015
class Template(models.Model):

dbtemplates/south_migrations/0001_initial.py

-55
This file was deleted.

dbtemplates/south_migrations/0002_auto__del_unique_template_name.py

-34
This file was deleted.

dbtemplates/south_migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)