Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable django-trix to work with Django >= 2.0. Updated Trix to version 1.0.0. #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
django-trix
===========

`Trix rich text editor <http://trix-editor.org>`_ widget for Django, using Trix 0.10.1.
`Trix rich text editor <http://trix-editor.org>`_ widget for Django, using Trix 1.0.0.

.. image:: https://circleci.com/gh/istrategylabs/django-trix/tree/master.svg?style=shield
:target: https://circleci.com/gh/istrategylabs/django-trix/tree/master


Using django-trix
-----------------
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django>=1.11.18,<1.12
Django>=4.0,<=5.0
pytest>=3.0,<3.1
pytest-django>=3.1,<3.2
tox>=2.6,<2.7
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from setuptools import setup

long_description = open('README.rst').read()
long_description = open("README.rst").read()

setup(
name="django-trix",
version='0.3.1',
version="0.3.3",
packages=["trix"],
include_package_data=True,
description="Trix rich text editor widget for Django",
url="https://github.com/istrategylabs/django-trix",
url="https://github.com/bodedev/django-trix",
author="Jeremy Carbaugh",
author_email="jeremy@isl.co",
license='BSD',
license="BSD",
long_description=long_description,
platforms=["any"],
classifiers=[
Expand All @@ -21,9 +21,9 @@
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
],
)
6 changes: 6 additions & 0 deletions tests/test_rendering.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from django.contrib.auth.models import User


def test_django_admin(admin_client):

User.objects.create_superuser('bode', 'bode@example.com', 'cabrito')

login = admin_client.login(username='bode', password='cabrito')

resp = admin_client.get('/admin/testapp/post/add/')

assert b'/static/trix/trix.css' in resp.content
Expand Down
2 changes: 2 additions & 0 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
'django.contrib.messages.middleware.MessageMiddleware',
)

MIDDLEWARE = MIDDLEWARE_CLASSES

ROOT_URLCONF = 'tests.testapp.urls'

TEMPLATES = [
Expand Down
10 changes: 5 additions & 5 deletions tests/testapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.conf.urls import include, url
from django.urls import include, path
from django.contrib import admin
from django.views.generic import FormView

Expand All @@ -12,11 +12,11 @@ class EditorForm(forms.Form):

class EditorView(FormView):
form_class = EditorForm
template_name = 'index.html'
template_name = "index.html"


urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^trix/', include('trix.urls')),
url(r'^$', EditorView.as_view()),
path("admin/", admin.site.urls),
path("trix/", include("trix.urls")),
path("", EditorView.as_view()),
]
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[tox]
envlist =
{py27,py35,py36}-dj{19,110}
{py27}-dj{19,110}
{py36}-dj{20}

[testenv]
commands = pytest tests --ds=tests.testapp.settings

deps =
dj19: Django>=1.9,<1.10
dj110: Django>=1.10,<1.11
dj20: Django>=2.0,<2.1
pytest-django
16 changes: 8 additions & 8 deletions trix/static/trix/trix-core.js

Large diffs are not rendered by default.

499 changes: 291 additions & 208 deletions trix/static/trix/trix.css

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions trix/static/trix/trix.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions trix/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf.urls import include, url
from django.urls import path
from .views import AttachmentView


urlpatterns = [
url(r'^attachment/$', AttachmentView.as_view()),
path("attachment/", AttachmentView.as_view()),
]
13 changes: 10 additions & 3 deletions trix/widgets.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
from __future__ import unicode_literals

import django
from django import forms
from django.contrib.admin import widgets as admin_widgets
from django.utils.html import format_html
from django.utils.safestring import mark_safe


class TrixEditor(forms.Textarea):

def render(self, name, value, attrs=None):
def render(self, name, value, attrs=None, renderer=None):

if attrs is None:
attrs = {}
attrs.update({'style': 'visibility: hidden; position: absolute;'})

if renderer is None and django.get_version() > "2.0":
renderer = forms.get_default_renderer()

params = {
'input': attrs.get('id') or '{}_id'.format(name),
'class': 'trix-content',
}
param_str = ' '.join('{}="{}"'.format(k, v) for k, v in params.items())

html = super(TrixEditor, self).render(name, value, attrs)
if django.get_version() >= "2.0":
html = super(TrixEditor, self).render(name, value, attrs, renderer=renderer)
else:
html = super(TrixEditor, self).render(name, value, attrs)
html = format_html(
'{}<p><trix-editor {}></trix-editor></p>',
html,
Expand Down