Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
python: 3.5
python: 3.8
sudo: false

notifications:
Expand All @@ -13,8 +13,8 @@ cache:
- $HOME/.cache/pip

env:
- TOX_ENV=py27-dj111
- TOX_ENV=py35-dj111
- TOX_ENV=py38-dj22
- TOX_ENV=py38-dj30

script:
- tox -e $TOX_ENV
Expand All @@ -26,7 +26,7 @@ deploy:
secure: nyHO+Ouaq/64fhdwtvvbK5jE+GiLFyah3YC8ibUP4QuOGQcl6CSOLTVhVqmvoCbJQBAQi84KefitnaPK/Jvpbpp3jBKsou5cApoarlTCCqKME9B0P5bQYgYoHBo1xxB0RFpjnbyOYPLYEBKo9aHqh0/R0GUPY8lUALZ7lfp0C4FR8Ogugbm5DRwLh/1V4mBYb/jZOrN2VkFlXwmVDrYWdPAA5Bz9rviu0aXLg7UOyNQIf6qywnPBCpZEHl6eGBG8DdMSniV+mNq9L10ISU9DoaVj7jnrEPFvKxnyFl/a4KeCGvP4kH90/gHuUTU6loet4clGpnXa5/n+5Zq0t5WfOr/3NL1lntCbQmqVniqffPW4nz99rMQ36iLl2Xoz9UTwTEyN7AdkmIIHKVox9hmVfM/npoVwyQEBoY6XnysY9s8yrnqWF3cEzoQzCqOxnt6pF/4aO7aUkfA27W5vwCYDJziGAPT0h62lVDJJvNUfis2mAk5kYqFvJZduqzUcDgivCsHN37wShk//rRAZcrjCbaiOvrLKJsS8A8L6NrDainN+U46GWnerZXr1P3kxw8luwMXKpZXS8MN50Ju2mj/T3YNK66K6EBTY9xT1r5ZXEy7TSJ1rEamPJEpRSddyTRoCxgI7EFrY+zl2AeU4ClBzudPqmmnWWKXsv0vwk/omtFU=
on:
tags: true
condition: $TOX_ENV = py35-dj111
condition: $TOX_ENV = py38-dj30
distributions: "bdist_wheel"
before_deploy:
- 'rm -fr build htmlcov dist .eggs .tox'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change history for django-templateselector
------------------------------------------

1.0.0
^^^^^^
* |FIX| Remove support for end-of-life Django and Python versions
* |NEW| Add support for Django 3.0

0.2.5
^^^^^^
* |FIX| Added ``:focus`` visual styles so that keyboard navigation through a form
Expand Down
11 changes: 1 addition & 10 deletions demo_project.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import sys
sys.dont_write_bytecode = True
MISSING_DEPENDENCIES = []
try:
from django.conf import settings
except ImportError:
MISSING_DEPENDENCIES.append("Django\>=1.11")
try:
from os import scandir
except ImportError:
try:
from scandir import scandir
except ImportError:
MISSING_DEPENDENCIES.append("scandir\>=1.5")

MISSING_DEPENDENCIES.append("Django\>=2.0")

if MISSING_DEPENDENCIES:
deps = " ".join(MISSING_DEPENDENCIES)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pytest]
[tool:pytest]
norecursedirs=.* *.egg .svn _build src bin lib local include
testpaths=templateselector/tests
python_files=test_*.py
Expand Down
30 changes: 6 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@
# -*- coding: utf-8 -*-
import sys
import os
from setuptools import setup, __version__ as setuptools_version
from setuptools import setup
from setuptools.command.test import test as TestCommand

INSTALL_REQUIRES = []
EXTRA_REQUIRES = {}
scandir = "scandir>=1.5"
if int(setuptools_version.split(".", 1)[0]) < 18:
assert "bdist_wheel" not in sys.argv, "setuptools 18 required for wheels."
# For legacy setuptools + sdist.
if sys.version_info[0] == 2:
INSTALL_REQUIRES.append(scandir)
else:
EXTRA_REQUIRES[":python_version<'3'"] = [scandir]

if sys.version_info[0] == 2:
# get the Py3K compatible `encoding=` for opening files.
from io import open
HERE = os.path.abspath(os.path.dirname(__file__))


class PyTest(TestCommand):
def initialize_options(self):
TestCommand.initialize_options(self)
Expand Down Expand Up @@ -62,7 +47,7 @@ def make_readme(root_path):

setup(
name="django-templateselector",
version="0.2.5",
version="1.0.0",
author="Keryn Knight",
author_email="[email protected]",
maintainer="Keryn Knight",
Expand All @@ -74,9 +59,8 @@ def make_readme(root_path):
],
include_package_data=True,
install_requires=[
"Django>=1.8",
] + INSTALL_REQUIRES,
extras_require=EXTRA_REQUIRES,
"Django>=2.0",
],
tests_require=[
"pytest>=2.6",
"pytest-django>=2.8.0",
Expand All @@ -93,11 +77,9 @@ def make_readme(root_path):
"Intended Audience :: Developers",
"License :: OSI Approved :: {}".format(LICENSE),
"Natural Language :: English",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Framework :: Django",
"Framework :: Django :: 1.11",
"Framework :: Django :: 2",
"Framework :: Django :: 3",
],
)
10 changes: 4 additions & 6 deletions templateselector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

__version_info__ = '0.2.5'
__version__ = '0.2.5'
version = '0.2.5'
VERSION = '0.2.5'
__version_info__ = '1.0.0'
__version__ = '1.0.0'
version = '1.0.0'
VERSION = '1.0.0'

def get_version():
return version # pragma: no cover
3 changes: 1 addition & 2 deletions templateselector/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.contrib.admin import AllValuesFieldListFilter, FieldListFilter
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


_ALL = _('All')
Expand Down
34 changes: 14 additions & 20 deletions templateselector/fields.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from operator import itemgetter
from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles import finders
from django.utils import six
from django.utils.deconstruct import deconstructible
from django.utils.module_loading import import_string
from django.utils.text import capfirst
Expand All @@ -19,8 +17,7 @@
from django.template import TemplateDoesNotExist, engines
from django.template.loader import get_template
from django.utils.encoding import force_text
from django.utils.functional import curry
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


__all__ = ['TemplateField', 'TemplateChoiceField']
Expand Down Expand Up @@ -78,7 +75,7 @@ def __init__(self, match='^.*$', display_name='templateselector.fields.nice_disp
template_exists_validator = TemplateExistsValidator(self.match)
self.validators.append(template_exists_validator)

if isinstance(display_name, six.text_type) and '.' in display_name:
if isinstance(display_name, str) and '.' in display_name:
display_name = import_string(display_name)
if not callable(display_name):
raise ImproperlyConfigured(_("display_name= argument must be a callable which takes a single string"))
Expand Down Expand Up @@ -140,20 +137,17 @@ def check(self, **kwargs):

def contribute_to_class(self, cls, name, **kwargs):
super(TemplateField, self).contribute_to_class(cls, name, **kwargs)
display = curry(self.__get_FIELD_template_display, field=self)
display.short_description = self.verbose_name
display.admin_order_field = name
setattr(cls, 'get_%s_display' % self.name, display)
template_instance = curry(self.__get_FIELD_template_instance, field=self)
setattr(cls, 'get_%s_instance' % self.name, template_instance)

def __get_FIELD_template_display(self, cls, field):
value = getattr(cls, field.attname)
return self.display_name(value)

def __get_FIELD_template_instance(self, cls, field):
value = getattr(cls, field.attname)
return get_template(value)
field = self
def __get_FIELD_template_display(self):
value = getattr(self, field.attname)
return field.display_name(value)
def __get_FIELD_template_instance(self):
value = getattr(self, field.attname)
return get_template(value)
__get_FIELD_template_display.short_description = self.verbose_name
__get_FIELD_template_display.admin_order_field = name
setattr(cls, 'get_%s_display' % self.name, __get_FIELD_template_display)
setattr(cls, 'get_%s_instance' % self.name, __get_FIELD_template_instance)


class TemplateChoiceField(TypedChoiceField):
Expand All @@ -166,7 +160,7 @@ def __init__(self, match='^.*$', display_name='templateselector.fields.nice_disp
max_length = None
if 'max_length' in kwargs:
max_length = kwargs.pop('max_length')
if isinstance(display_name, six.text_type) and '.' in display_name:
if isinstance(display_name, str) and '.' in display_name:
display_name = import_string(display_name)
if not callable(display_name):
raise ImproperlyConfigured(_("display_name= argument must be a callable which takes a single string"))
Expand Down
17 changes: 1 addition & 16 deletions templateselector/handlers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.template.loaders import app_directories, filesystem, cached
try:
from os import scandir
except ImportError: # pragma: no cover
try:
from scandir import scandir
except ImportError as e:
import sys
from django.utils import six
message = ("You're probably using Python 2.x, so you'll need to "
"install the backport: `pip install scandir\>=1.5`")
flattened = " ".join(e.args) + "\n" + message
e.args = (flattened,)
e.message = flattened
six.reraise(*sys.exc_info())

from os import scandir

__all__ = ['get_results_from_registry']

Expand Down
1 change: 0 additions & 1 deletion templateselector/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
__all__ = []
2 changes: 0 additions & 2 deletions templateselector/tests/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import

from django.contrib import admin
from templateselector.tests.models import MyModel

Expand Down
3 changes: 0 additions & 3 deletions templateselector/tests/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import
from django.db.models import Model
from django.utils.encoding import force_text
from django.utils.six import python_2_unicode_compatible
from templateselector.fields import TemplateField

@python_2_unicode_compatible
class MyModel(Model):
f = TemplateField(match="^admin/.+\.html$", verbose_name="test 'f'")

Expand Down
Loading