Skip to content

Commit

Permalink
Drop support for Python 2 & Django < 2.2, add support for Django 3.0 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap3 committed Dec 2, 2019
1 parent 45890e3 commit 2e9b3ab
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 87 deletions.
15 changes: 3 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
7 changes: 2 additions & 5 deletions djrichtextfield/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from __future__ import unicode_literals

from django.db import models

from djrichtextfield.sanitizer import SanitizerMixin
from djrichtextfield.widgets import RichTextWidget


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):
Expand Down
14 changes: 5 additions & 9 deletions djrichtextfield/sanitizer.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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):
Expand All @@ -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
2 changes: 0 additions & 2 deletions djrichtextfield/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions djrichtextfield/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.conf.urls import url

from djrichtextfield.views import InitView
Expand Down
2 changes: 0 additions & 2 deletions djrichtextfield/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import json

from django.utils.encoding import force_text
Expand Down
9 changes: 2 additions & 7 deletions djrichtextfield/widgets.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions testproject/testapp/models.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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()
Expand Down
51 changes: 11 additions & 40 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2e9b3ab

Please sign in to comment.