diff --git a/.travis.yml b/.travis.yml index e289260..0e92763 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,11 @@ # Config file for automatic testing at travis-ci.org language: python python: - - 3.5 - 3.6 + - 3.7 env: - - DJANGO_VERSION=\>=1.11,\<2.0 - - DJANGO_VERSION=\>=2.0,\<2.1 - - DJANGO_VERSION=\>=2.1,\<2.2 -matrix: - include: - - python: 2.7 - env: DJANGO_VERSION=\>=1.11,\<2.0 - - python: 3.4 - env: DJANGO_VERSION=\>=1.11,\<2.0 - - python: 3.4 - env: DJANGO_VERSION=\>=2.0,\<2.1 + - DJANGO_VERSION=\>=2.2,\<3.0 + - DJANGO_VERSION=\>=3.0a,\<3.1 install: - pip install --upgrade pip - pip install --upgrade Django$DJANGO_VERSION diff --git a/HISTORY.rst b/HISTORY.rst index ef25c7e..ed17cf5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,16 +1,18 @@ History ------- -1.4.1 (unreleased) +1.5.0 (unreleased) ^^^^^^^^^^^^^^^^^^ -- Nothing changed yet. +- Drop support for Python 2 +- Drop support for Django < 2.2 +- Add support for Django 3.0 1.4.0 (2019-01-31) ^^^^^^^^^^^^^^^^^^ -* Add support for pluggable server side content sanitizers +* Add support for plugable server side content sanitizers 1.3.0 (2018-11-05) diff --git a/djrichtextfield/models.py b/djrichtextfield/models.py index 637f6a5..4750514 100644 --- a/djrichtextfield/models.py +++ b/djrichtextfield/models.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.db import models from djrichtextfield.sanitizer import SanitizerMixin @@ -7,9 +5,8 @@ class RichTextField(SanitizerMixin, models.TextField): - def __init__(self, *args, **kwargs): - # Python 2 does not allow keywords between *args and **kwargs - self.field_settings = kwargs.pop('field_settings', None) + def __init__(self, *args, field_settings=None, **kwargs): + self.field_settings = field_settings super(RichTextField, self).__init__(*args, **kwargs) def formfield(self, **kwargs): diff --git a/djrichtextfield/sanitizer.py b/djrichtextfield/sanitizer.py index 2f28c13..309aed5 100644 --- a/djrichtextfield/sanitizer.py +++ b/djrichtextfield/sanitizer.py @@ -1,6 +1,3 @@ -from __future__ import unicode_literals - -from django.utils import six from django.utils.module_loading import import_string from djrichtextfield import settings @@ -10,7 +7,7 @@ def noop(value): return value -class SanitizerMixin(object): +class SanitizerMixin: """ Get the field sanitizer from the provided kwargs during init, or from the settings. @@ -19,9 +16,8 @@ class SanitizerMixin(object): SANITIZER_KEY = 'sanitizer' SANITIZER_PROFILES_KEY = 'sanitizer_profiles' - def __init__(self, *args, **kwargs): - # Python 2 does not allow keywords between *args and **kwargs - self.sanitizer = kwargs.pop('sanitizer', None) + def __init__(self, *args, sanitizer=None, **kwargs): + self.sanitizer = sanitizer super(SanitizerMixin, self).__init__(*args, **kwargs) def get_sanitizer(self): @@ -40,13 +36,13 @@ def get_sanitizer(self): if not sanitizer: default_sanitizer = settings.CONFIG.get(self.SANITIZER_KEY) field_settings = getattr(self, 'field_settings', None) - if isinstance(field_settings, six.string_types): + if isinstance(field_settings, str): profiles = settings.CONFIG.get(self.SANITIZER_PROFILES_KEY, {}) sanitizer = profiles.get(field_settings, default_sanitizer) else: sanitizer = default_sanitizer - if isinstance(sanitizer, six.string_types): + if isinstance(sanitizer, str): sanitizer = import_string(sanitizer) return sanitizer or noop diff --git a/djrichtextfield/settings.py b/djrichtextfield/settings.py index 851cedb..201090f 100644 --- a/djrichtextfield/settings.py +++ b/djrichtextfield/settings.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.conf import settings from django.dispatch import receiver from django.test.signals import setting_changed diff --git a/djrichtextfield/urls.py b/djrichtextfield/urls.py index 531bc5c..fd4302f 100644 --- a/djrichtextfield/urls.py +++ b/djrichtextfield/urls.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.conf.urls import url from djrichtextfield.views import InitView diff --git a/djrichtextfield/views.py b/djrichtextfield/views.py index 6ff21c6..18631ef 100644 --- a/djrichtextfield/views.py +++ b/djrichtextfield/views.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import json from django.utils.encoding import force_text diff --git a/djrichtextfield/widgets.py b/djrichtextfield/widgets.py index 6d416bd..e1c132f 100644 --- a/djrichtextfield/widgets.py +++ b/djrichtextfield/widgets.py @@ -1,13 +1,8 @@ -from __future__ import unicode_literals - import json -import django - from django.conf import settings as django_settings from django.forms.widgets import Media, Textarea from django.urls import reverse -from django.utils import six from django.utils.encoding import force_text from django.utils.html import format_html @@ -19,7 +14,7 @@ class RichTextWidget(SanitizerMixin, Textarea): CSS_CLASS = 'djrichtextfield' INIT_URL = 'djrichtextfield_init' SETTINGS_ATTR = 'data-field-settings' - CONTAINER_CLASS = 'fieldBox' if django.VERSION >= (2, 1) else 'field-box' + CONTAINER_CLASS = 'fieldBox' PROFILE_KEY = 'profiles' def __init__(self, attrs=None, field_settings=None, sanitizer=None): @@ -49,7 +44,7 @@ def get_field_settings(self): """ field_settings = None if self.field_settings: - if isinstance(self.field_settings, six.string_types): + if isinstance(self.field_settings, str): profiles = settings.CONFIG.get(self.PROFILE_KEY, {}) field_settings = profiles.get(self.field_settings) else: diff --git a/testproject/testapp/models.py b/testproject/testapp/models.py index 8e45571..910261f 100644 --- a/testproject/testapp/models.py +++ b/testproject/testapp/models.py @@ -1,12 +1,8 @@ -from __future__ import unicode_literals - from django.db import models -from django.utils.encoding import python_2_unicode_compatible from djrichtextfield.models import RichTextField -@python_2_unicode_compatible class Post(models.Model): title = models.CharField(max_length=50) lead = RichTextField(field_settings='mini') @@ -16,7 +12,6 @@ def __str__(self): return self.title -@python_2_unicode_compatible class Comment(models.Model): post = models.ForeignKey(Post, on_delete=models.CASCADE) content = models.TextField() diff --git a/tox.ini b/tox.ini index 81ad2c5..f92627a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,54 +1,25 @@ [tox] -envlist = py27-dj111, py34-dj111, py35-dj111, py36-dj111, - py34-dj20, py35-dj20, py36-dj20, py37-dj20 - py35-dj20, py36-dj21, py37-dj21 +envlist = py36-dj22, py37-dj22, + py36-dj30, py37-dj30 [testenv] -commands = python manage.py test testproject +commands = python -W module manage.py test testproject -[testenv:py27-dj111] -basepython = python2.7 -deps = Django>=1.11,<2.0 - -[testenv:py34-dj111] -basepython = python3.4 -deps = Django>=1.11,<2.0 - -[testenv:py35-dj111] -basepython = python3.5 -deps = Django>=1.11,<2.0 - -[testenv:py36-dj111] -basepython = python3.6 -deps = Django>=1.11,<2.0 - -[testenv:py34-dj20] -basepython = python3.4 -deps = Django>=2.0,<2.1 - -[testenv:py35-dj20] -basepython = python3.5 -deps = Django>=2.0,<2.1 - -[testenv:py36-dj20] +[testenv:py36-dj22] basepython = python3.6 -deps = Django>=2.0,<2.1 +deps = Django>=2.2,<3.0 -[testenv:py37-dj20] +[testenv:py37-dj22] basepython = python3.7 -deps = Django>=2.0,<2.1 - -[testenv:py35-dj21] -basepython = python3.5 -deps = Django>=2.1,<2.2 +deps = Django>=2.2,<3.0 -[testenv:py36-dj21] +[testenv:py36-dj30] basepython = python3.6 -deps = Django>=2.1,<2.2 +deps = Django>=3.0a,<3.1 -[testenv:py37-dj21] +[testenv:py37-dj30] basepython = python3.7 -deps = Django>=2.1,<2.2 +deps = Django>=3.0a,<3.1 [testenv:flake8] commands = flake8 djrichtextfield testproject