From 6c8043b836df4df4cd3c988084622e3cd9372425 Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Fri, 20 Jul 2018 13:37:28 -0400 Subject: [PATCH 01/13] Changes to work with TinyMCE 4 and filebrowser --- tinymce/settings.py | 2 ++ .../templates/tinymce/filebrowser_tinymce4.js | 16 ++++++++++++++++ tinymce/views.py | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tinymce/templates/tinymce/filebrowser_tinymce4.js diff --git a/tinymce/settings.py b/tinymce/settings.py index 731a3279..8c167445 100644 --- a/tinymce/settings.py +++ b/tinymce/settings.py @@ -16,6 +16,8 @@ USE_FILEBROWSER = getattr(settings, 'TINYMCE_FILEBROWSER', 'filebrowser' in settings.INSTALLED_APPS) +TINYMCE_VERSION = getattr(settings, 'TINYMCE_VERSION', (3,5,11)) + if 'staticfiles' in settings.INSTALLED_APPS or 'django.contrib.staticfiles' in settings.INSTALLED_APPS: JS_URL = getattr(settings, 'TINYMCE_JS_URL', os.path.join(settings.STATIC_URL, 'tiny_mce/tiny_mce.js')) JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', finders.find('tiny_mce', all=False)) diff --git a/tinymce/templates/tinymce/filebrowser_tinymce4.js b/tinymce/templates/tinymce/filebrowser_tinymce4.js new file mode 100644 index 00000000..42dbcd55 --- /dev/null +++ b/tinymce/templates/tinymce/filebrowser_tinymce4.js @@ -0,0 +1,16 @@ +function djangoFileBrowser(field_name, url, type, win) { + var url = "{{ fb_url }}?pop=4&type=" + type; + + tinyMCE.activeEditor.windowManager.open( + { + 'file': url, + 'width': 820, + 'height': 500, + }, + { + 'window': win, + 'input': field_name, + } + ); + return false; +} diff --git a/tinymce/views.py b/tinymce/views.py index a01da647..4d26c2a6 100644 --- a/tinymce/views.py +++ b/tinymce/views.py @@ -22,6 +22,7 @@ from django.core.urlresolvers import reverse from tinymce.compressor import gzip_compressor +import tinymce.settings try: import enchant @@ -115,9 +116,14 @@ def filebrowser(request): except Exception: fb_url = request.build_absolute_uri(reverse('filebrowser:fb_browse')) + if tinymce.settings.TINYMCE_VERSION < (4,0,0): + filebrowser_js = 'tinymce/filebrowser.js' + else: + filebrowser_js = 'tinymce/filebrowser_tinymce4.js' + return render( request, - 'tinymce/filebrowser.js', + filebrowser_js, {'fb_url': fb_url}, content_type='application/javascript' ) From f1df68fca9b216c3718c9d7a51b12fa443857738 Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Mon, 23 Jul 2018 11:24:08 -0400 Subject: [PATCH 02/13] Add spaces after commas to make flake8 happy --- tinymce/settings.py | 2 +- tinymce/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tinymce/settings.py b/tinymce/settings.py index 8c167445..2fd0646f 100644 --- a/tinymce/settings.py +++ b/tinymce/settings.py @@ -16,7 +16,7 @@ USE_FILEBROWSER = getattr(settings, 'TINYMCE_FILEBROWSER', 'filebrowser' in settings.INSTALLED_APPS) -TINYMCE_VERSION = getattr(settings, 'TINYMCE_VERSION', (3,5,11)) +TINYMCE_VERSION = getattr(settings, 'TINYMCE_VERSION', (3, 5, 11)) if 'staticfiles' in settings.INSTALLED_APPS or 'django.contrib.staticfiles' in settings.INSTALLED_APPS: JS_URL = getattr(settings, 'TINYMCE_JS_URL', os.path.join(settings.STATIC_URL, 'tiny_mce/tiny_mce.js')) diff --git a/tinymce/views.py b/tinymce/views.py index 4d26c2a6..b90e4941 100644 --- a/tinymce/views.py +++ b/tinymce/views.py @@ -116,7 +116,7 @@ def filebrowser(request): except Exception: fb_url = request.build_absolute_uri(reverse('filebrowser:fb_browse')) - if tinymce.settings.TINYMCE_VERSION < (4,0,0): + if tinymce.settings.TINYMCE_VERSION < (4, 0, 0): filebrowser_js = 'tinymce/filebrowser.js' else: filebrowser_js = 'tinymce/filebrowser_tinymce4.js' From 84649df3f1901f35b82043d2dc86cd38b09f08c1 Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Tue, 24 Jul 2018 08:27:31 -0400 Subject: [PATCH 03/13] Determine TinyMCE version from TinyMCE itself --- tinymce/settings.py | 2 - tinymce/templates/tinymce/filebrowser.js | 54 ++++++++++++++++-------- tinymce/views.py | 8 +--- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/tinymce/settings.py b/tinymce/settings.py index 2fd0646f..731a3279 100644 --- a/tinymce/settings.py +++ b/tinymce/settings.py @@ -16,8 +16,6 @@ USE_FILEBROWSER = getattr(settings, 'TINYMCE_FILEBROWSER', 'filebrowser' in settings.INSTALLED_APPS) -TINYMCE_VERSION = getattr(settings, 'TINYMCE_VERSION', (3, 5, 11)) - if 'staticfiles' in settings.INSTALLED_APPS or 'django.contrib.staticfiles' in settings.INSTALLED_APPS: JS_URL = getattr(settings, 'TINYMCE_JS_URL', os.path.join(settings.STATIC_URL, 'tiny_mce/tiny_mce.js')) JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', finders.find('tiny_mce', all=False)) diff --git a/tinymce/templates/tinymce/filebrowser.js b/tinymce/templates/tinymce/filebrowser.js index b89be04a..11ced6f5 100644 --- a/tinymce/templates/tinymce/filebrowser.js +++ b/tinymce/templates/tinymce/filebrowser.js @@ -1,21 +1,39 @@ function djangoFileBrowser(field_name, url, type, win) { - var url = "{{ fb_url }}?pop=2&type=" + type; + if (tinyMCE.majorVersion >= 4) { + var url = "{{ fb_url }}?pop=4&type=" + type; - tinyMCE.activeEditor.windowManager.open( - { - 'file': url, - 'width': 820, - 'height': 500, - 'resizable': "yes", - 'scrollbars': "yes", - 'inline': "no", - 'close_previous': "no" - }, - { - 'window': win, - 'input': field_name, - 'editor_id': tinyMCE.selectedInstance.editorId - } - ); - return false; + tinyMCE.activeEditor.windowManager.open( + { + 'file': url, + 'width': 820, + 'height': 500, + }, + { + 'window': win, + 'input': field_name, + } + ); + return false; + } + else { + var url = "{{ fb_url }}?pop=2&type=" + type; + + tinyMCE.activeEditor.windowManager.open( + { + 'file': url, + 'width': 820, + 'height': 500, + 'resizable': "yes", + 'scrollbars': "yes", + 'inline': "no", + 'close_previous': "no" + }, + { + 'window': win, + 'input': field_name, + 'editor_id': tinyMCE.selectedInstance.editorId + } + ); + return false; + } } diff --git a/tinymce/views.py b/tinymce/views.py index b90e4941..a01da647 100644 --- a/tinymce/views.py +++ b/tinymce/views.py @@ -22,7 +22,6 @@ from django.core.urlresolvers import reverse from tinymce.compressor import gzip_compressor -import tinymce.settings try: import enchant @@ -116,14 +115,9 @@ def filebrowser(request): except Exception: fb_url = request.build_absolute_uri(reverse('filebrowser:fb_browse')) - if tinymce.settings.TINYMCE_VERSION < (4, 0, 0): - filebrowser_js = 'tinymce/filebrowser.js' - else: - filebrowser_js = 'tinymce/filebrowser_tinymce4.js' - return render( request, - filebrowser_js, + 'tinymce/filebrowser.js', {'fb_url': fb_url}, content_type='application/javascript' ) From 732cb3355ab3ac7edca9090498e333275f259716 Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Tue, 24 Jul 2018 08:28:23 -0400 Subject: [PATCH 04/13] Remove now unused file --- .../templates/tinymce/filebrowser_tinymce4.js | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 tinymce/templates/tinymce/filebrowser_tinymce4.js diff --git a/tinymce/templates/tinymce/filebrowser_tinymce4.js b/tinymce/templates/tinymce/filebrowser_tinymce4.js deleted file mode 100644 index 42dbcd55..00000000 --- a/tinymce/templates/tinymce/filebrowser_tinymce4.js +++ /dev/null @@ -1,16 +0,0 @@ -function djangoFileBrowser(field_name, url, type, win) { - var url = "{{ fb_url }}?pop=4&type=" + type; - - tinyMCE.activeEditor.windowManager.open( - { - 'file': url, - 'width': 820, - 'height': 500, - }, - { - 'window': win, - 'input': field_name, - } - ); - return false; -} From 46aa927c57a7b76ac17fa9f8ad0c5f52d62e665c Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Thu, 26 Jul 2018 13:58:55 -0400 Subject: [PATCH 05/13] Update test_filebrowser --- tinymce/tests/test_views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tinymce/tests/test_views.py b/tinymce/tests/test_views.py index c1c4103a..cdae3c6a 100644 --- a/tinymce/tests/test_views.py +++ b/tinymce/tests/test_views.py @@ -12,6 +12,9 @@ devnull = open(os.devnull, 'w') +def compress_whitespace(s): + # replace whitespace runs with a single space + return ' '.join(s.split()) class TestViews(TestCase): @@ -115,6 +118,8 @@ def test_render_to_image_list(self): @patch('tinymce.views.reverse', return_value='/filebrowser') def test_filebrowser(self, reverse_mock): response = self.client.get('/tinymce/filebrowser/') - response_ok = b'function djangoFileBrowser(field_name, url, type, win) {\n var url = "http://testserver/filebrowser?pop=2&type=" + type;\n\n tinyMCE.activeEditor.windowManager.open(\n {\n \'file\': url,\n \'width\': 820,\n \'height\': 500,\n \'resizable\': "yes",\n \'scrollbars\': "yes",\n \'inline\': "no",\n \'close_previous\': "no"\n },\n {\n \'window\': win,\n \'input\': field_name,\n \'editor_id\': tinyMCE.selectedInstance.editorId\n }\n );\n return false;\n}\n' + with open('tinymce/templates/tinymce/filebrowser.js') as f: + response_ok = f.read() + response_ok = response_ok.replace('{{ fb_url }}', 'http://testserver/filebrowser') self.assertEqual(200, response.status_code) - self.assertEqual(response_ok, response.content) + self.assertEqual(compress_whitespace(response_ok), compress_whitespace(response.content)) From e291c0c0ba0c93f8b451e6390cc46c426a4254a7 Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Thu, 26 Jul 2018 14:11:44 -0400 Subject: [PATCH 06/13] Fix python 3 error in unit test --- tinymce/tests/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinymce/tests/test_views.py b/tinymce/tests/test_views.py index cdae3c6a..392b9513 100644 --- a/tinymce/tests/test_views.py +++ b/tinymce/tests/test_views.py @@ -122,4 +122,4 @@ def test_filebrowser(self, reverse_mock): response_ok = f.read() response_ok = response_ok.replace('{{ fb_url }}', 'http://testserver/filebrowser') self.assertEqual(200, response.status_code) - self.assertEqual(compress_whitespace(response_ok), compress_whitespace(response.content)) + self.assertEqual(compress_whitespace(response_ok), compress_whitespace(response.content.decode())) From 1d87d139ca8555823bc01509e1887057d7572c6f Mon Sep 17 00:00:00 2001 From: Michael Glassford Date: Thu, 26 Jul 2018 14:14:49 -0400 Subject: [PATCH 07/13] Make flake8 happy --- tinymce/tests/test_views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tinymce/tests/test_views.py b/tinymce/tests/test_views.py index 392b9513..b5426632 100644 --- a/tinymce/tests/test_views.py +++ b/tinymce/tests/test_views.py @@ -12,10 +12,12 @@ devnull = open(os.devnull, 'w') + def compress_whitespace(s): # replace whitespace runs with a single space return ' '.join(s.split()) + class TestViews(TestCase): @patch('tinymce.views.enchant') From 402477ffecab2640217e8a5306c7d88fe2459a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Fri, 4 Jan 2019 09:27:13 +0100 Subject: [PATCH 08/13] Fallback on os.path if the INSTALLED_APPS is not properly loaded. --- tinymce/settings.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tinymce/settings.py b/tinymce/settings.py index 731a3279..45d3860b 100644 --- a/tinymce/settings.py +++ b/tinymce/settings.py @@ -1,6 +1,6 @@ import os from django.conf import settings -from django.contrib.staticfiles import finders +from django.core.exceptions import AppRegistryNotReady DEFAULT_CONFIG = getattr(settings, 'TINYMCE_DEFAULT_CONFIG', {'theme': "simple", 'relative_urls': False}) @@ -18,7 +18,11 @@ if 'staticfiles' in settings.INSTALLED_APPS or 'django.contrib.staticfiles' in settings.INSTALLED_APPS: JS_URL = getattr(settings, 'TINYMCE_JS_URL', os.path.join(settings.STATIC_URL, 'tiny_mce/tiny_mce.js')) - JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', finders.find('tiny_mce', all=False)) + try: + from django.contrib.staticfiles import finders + JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', finders.find('tiny_mce', all=False)) + except AppRegistryNotReady: + JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', os.path.join(settings.STATIC_ROOT, 'tiny_mce')) else: JS_URL = getattr(settings, 'TINYMCE_JS_URL', '{!s}js/tiny_mce/tiny_mce.js'.format(settings.MEDIA_URL)) JS_ROOT = getattr(settings, 'TINYMCE_JS_ROOT', os.path.join(settings.MEDIA_ROOT, 'js/tiny_mce')) From c3fd5245ef25155bbffa488574d2530a745ca15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Tue, 15 Jan 2019 12:18:00 +0100 Subject: [PATCH 09/13] Fix flake8 --- tinymce/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tinymce/models.py b/tinymce/models.py index f6ae3089..d364a09b 100644 --- a/tinymce/models.py +++ b/tinymce/models.py @@ -6,7 +6,7 @@ from tinymce import widgets as tinymce_widgets try: from south.modelsinspector import add_introspection_rules - add_introspection_rules([], ['^tinymce\.models\.HTMLField']) + add_introspection_rules([], ['^tinymce\\.models\\.HTMLField']) except ImportError: pass From 986398a4a018f44fafa95cf07f42e6886da2c438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Tue, 15 Jan 2019 12:26:03 +0100 Subject: [PATCH 10/13] Preparing release 2.8.0 --- CHANGELOG.rst | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ab2010aa..b91a05ad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,10 +4,10 @@ Changelog This document describes changes between each past release. -2.8.0 (unreleased) +2.8.0 (2019-01-15) ================== -- Nothing changed yet. +- Use the attrs set on instantiation as well as the attrs passed to render (#237) 2.7.0 (2017-12-19) diff --git a/setup.py b/setup.py index c73a445b..9bd62084 100755 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ def read_file(filename): setup( name="django-tinymce", - version='2.8.0.dev0', + version='2.8.0', packages=find_packages(), include_package_data=True, author="Aljosa Mohorovic", From 68b9e6950565a0bd5faf31ee9d5d7c5fbc3581db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Tue, 15 Jan 2019 12:26:31 +0100 Subject: [PATCH 11/13] Back to development: 2.9.0 --- CHANGELOG.rst | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b91a05ad..ec2e73f5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,12 @@ Changelog This document describes changes between each past release. +2.9.0 (unreleased) +================== + +- Nothing changed yet. + + 2.8.0 (2019-01-15) ================== diff --git a/setup.py b/setup.py index 9bd62084..c199a5bd 100755 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ def read_file(filename): setup( name="django-tinymce", - version='2.8.0', + version='2.9.0.dev0', packages=find_packages(), include_package_data=True, author="Aljosa Mohorovic", From 29a71bfa0ebbfd2824177aaaf3984be60965a6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Tue, 15 Jan 2019 13:31:09 +0100 Subject: [PATCH 12/13] Upgrade test matrix to include Python 3.7 and Django 2.1 --- .travis.yml | 14 ++++++++++++++ CHANGELOG.rst | 2 +- setup.py | 3 ++- tox.ini | 7 ++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa55783a..04378373 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,25 @@ matrix: - python: 3.5 env: TOX_ENV=py35-django20 + - python: 3.5 + env: TOX_ENV=py35-django21 - python: 3.6 env: TOX_ENV=flake8 - python: 3.6 env: TOX_ENV=py36-django20 + - python: 3.6 + env: TOX_ENV=py36-django21 + + - python: 3.7 + dist: xenial + env: TOX_ENV=flake8 + - python: 3.7 + dist: xenial + env: TOX_ENV=py37-django20 + - python: 3.7 + dist: xenial + env: TOX_ENV=py37-django21 addons: apt: packages: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ec2e73f5..78c61a84 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,7 +7,7 @@ This document describes changes between each past release. 2.9.0 (unreleased) ================== -- Nothing changed yet. +- Upgrade test matrix to Python 3.7 and Django 2.1 2.8.0 (2019-01-15) diff --git a/setup.py b/setup.py index c199a5bd..d4356b46 100755 --- a/setup.py +++ b/setup.py @@ -40,8 +40,9 @@ def read_file(filename): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Software Development :: Libraries :: Application Frameworks', 'Topic :: Software Development :: Libraries :: Python Modules', ], diff --git a/tox.ini b/tox.ini index c515c9cf..dc570532 100644 --- a/tox.ini +++ b/tox.ini @@ -1,15 +1,16 @@ [tox] envlist = py27-django{111}, - py34-django{111}, - py35-django{2}, - py36-django{2}, + py35-django{20,21}, + py36-django{20,21}, + py37-django{20,21}, flake8 [testenv] deps = django111: Django>=1.11,<2.0 django20: Django>=2.0,<2.1 + django21: Django>=2.1,<2.2 coverage mock pyenchant From 7ca89845869fad049db81cf82aec29fdddabeee0 Mon Sep 17 00:00:00 2001 From: Slava Sorokin Date: Fri, 10 Apr 2020 17:27:11 +0700 Subject: [PATCH 13/13] Upgrade test matrix to include Django 2.2. Add required context processor --- .travis.yml | 7 +++++++ CHANGELOG.rst | 2 +- testtinymce/settings.py | 1 + tox.ini | 7 ++++--- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 04378373..b25918f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ matrix: env: TOX_ENV=py35-django20 - python: 3.5 env: TOX_ENV=py35-django21 + - python: 3.5 + env: TOX_ENV=py35-django22 - python: 3.6 env: TOX_ENV=flake8 @@ -16,6 +18,8 @@ matrix: env: TOX_ENV=py36-django20 - python: 3.6 env: TOX_ENV=py36-django21 + - python: 3.6 + env: TOX_ENV=py36-django22 - python: 3.7 dist: xenial @@ -26,6 +30,9 @@ matrix: - python: 3.7 dist: xenial env: TOX_ENV=py37-django21 + - python: 3.7 + dist: xenial + env: TOX_ENV=py37-django22 addons: apt: packages: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 78c61a84..4bba7fa2 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,7 +7,7 @@ This document describes changes between each past release. 2.9.0 (unreleased) ================== -- Upgrade test matrix to Python 3.7 and Django 2.1 +- Upgrade test matrix to Python 3.7 and Django 2.1, 2.2 2.8.0 (2019-01-15) diff --git a/testtinymce/settings.py b/testtinymce/settings.py index 17a3e6b6..b3887136 100644 --- a/testtinymce/settings.py +++ b/testtinymce/settings.py @@ -45,6 +45,7 @@ 'OPTIONS': { 'context_processors': [ "django.contrib.auth.context_processors.auth", + "django.contrib.messages.context_processors.messages", ] }, }, diff --git a/tox.ini b/tox.ini index dc570532..c40227b1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] envlist = py27-django{111}, - py35-django{20,21}, - py36-django{20,21}, - py37-django{20,21}, + py35-django{20,21,22}, + py36-django{20,21,22}, + py37-django{20,21,22}, flake8 [testenv] @@ -11,6 +11,7 @@ deps = django111: Django>=1.11,<2.0 django20: Django>=2.0,<2.1 django21: Django>=2.1,<2.2 + django22: Django>=2.2,<3.0 coverage mock pyenchant