From fe121b8b2ed5d2079a4014e5417e58551808b332 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 18:34:00 +0100 Subject: [PATCH 01/16] Use https where possible --- README.md | 2 +- djedi/plugins/img.py | 2 +- docs/Makefile | 2 +- docs/index.rst | 2 +- example/example/settings.py | 2 +- setup.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9e2e79a8..96cc0d0d 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,6 @@ urlpatterns = [ * [React][]: [djedi-react](djedi-react#djedi-react) -[docs]: http://5monkeys.github.io/djedi-cms/ +[docs]: https://djedi-cms.org/ [content-io]: https://github.com/5monkeys/content-io/ [react]: https://reactjs.org/ diff --git a/djedi/plugins/img.py b/djedi/plugins/img.py index 8a4dc4fe..2301555e 100644 --- a/djedi/plugins/img.py +++ b/djedi/plugins/img.py @@ -117,7 +117,7 @@ def delete(self, data): def render(self, data): attrs = { - 'src': 'http://placekitten.com/160/90', + 'src': 'https://placekitten.com/160/90', 'width': 160, 'height': 90 } diff --git a/docs/Makefile b/docs/Makefile index c5e57a1f..62482dda 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -9,7 +9,7 @@ BUILDDIR = _build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) -$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://www.sphinx-doc.org/) endif # Internal variables. diff --git a/docs/index.rst b/docs/index.rst index e48179e5..e370a200 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -34,4 +34,4 @@ User Guide settings -.. _SOUTH_MIGRATION_MODULES: http://south.readthedocs.org/en/latest/settings.html#south-migration-modules +.. _SOUTH_MIGRATION_MODULES: https://south.readthedocs.io/en/latest/settings.html#south-migration-modules diff --git a/example/example/settings.py b/example/example/settings.py index 21f0c7ed..5cf3f38b 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -122,6 +122,6 @@ CORS_ALLOW_CREDENTIALS = True # Djedi -# http://djedi-cms.org/settings.html +# https://djedi-cms.org/settings.html DJEDI_XSS_DOMAIN = 'localhost' diff --git a/setup.py b/setup.py index a7b09a06..c276185a 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ ' :target: https://travis-ci.org/5monkeys/djedi-cms\n' '.. image:: https://coveralls.io/repos/5monkeys/djedi-cms/badge.svg?branch=master\n' ' :target: https://coveralls.io/r/5monkeys/djedi-cms?branch=master\n\n' - '.. _documentation: http://djedi-cms.org/\n' + '.. _documentation: https://djedi-cms.org/\n' '.. _source: https://github.com/5monkeys/djedi-cms\n\n' ), author='Jonas Lundberg', From 684280f77b069251e3af7debdd031f4a2398bf05 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 18:44:00 +0100 Subject: [PATCH 02/16] Persist images in the example app --- .gitignore | 1 - docker-compose.yml | 4 ++++ example/example/settings.py | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 24b26787..b3ba0b7b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,3 @@ htmlcov/ node_modules/ .next/ example/db.sqlite3 -example/djedi/img/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index c80b0bf9..d640055e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: - "8000:8000" volumes: - .:/djedi-cms + - media-files:/media node: build: ./djedi-react @@ -30,3 +31,6 @@ services: volumes: - .:/code - /code/node_modules + +volumes: + media-files: diff --git a/example/example/settings.py b/example/example/settings.py index 5cf3f38b..49e18cdd 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -112,6 +112,8 @@ STATIC_URL = '/static/' MEDIA_URL = '/media/' +MEDIA_ROOT = '/media/' + # CORS # https://github.com/OttoYiu/django-cors-headers From 0be5286b4c1ac3a3379a1d94abd6c4b892a6a0de Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 18:56:00 +0100 Subject: [PATCH 03/16] Default to `alt=""` rather than no alt attribute It is considered better accessibility to set `alt` to the empty string rather than leaving it out. Screen readers might read the `src` attribute otherwise. In the case of djedi where the `src` attribute are long hashes that's especially bad. --- djedi/plugins/img.py | 5 ++--- djedi/tests/test_rest.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/djedi/plugins/img.py b/djedi/plugins/img.py index 2301555e..62eb9ed4 100644 --- a/djedi/plugins/img.py +++ b/djedi/plugins/img.py @@ -125,13 +125,12 @@ def render(self, data): url = data.get('url') width = data.get('width') or 0 height = data.get('height') or 0 - alt = data.get('alt') + alt = data.get('alt') or '' tag_id = data.get('id') tag_class = data.get('class') if url: attrs['src'] = url - if alt: - attrs['alt'] = alt + attrs['alt'] = alt if width and height: attrs['width'] = width attrs['height'] = height diff --git a/djedi/tests/test_rest.py b/djedi/tests/test_rest.py index 98084b03..d252f381 100644 --- a/djedi/tests/test_rest.py +++ b/djedi/tests/test_rest.py @@ -202,7 +202,7 @@ def test_render(self): 'height': '64' })}) self.assertEqual(response.status_code, 200) - self.assertEqual(smart_unicode(response.content), u'') + self.assertEqual(smart_unicode(response.content), u'') def test_editor(self): response = self.get('cms.editor', 'sv-se@page/title.foo') From c031b9fb137a0cea22ee970068442e4f684f8bb4 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 19:03:00 +0100 Subject: [PATCH 04/16] Use the "input" event rather than "keyup" in editors Previously, the "Discard" button would light up after just pressing the arrow keys. Also, pasting something using the mouse only would not trigger a preview. --- djedi/static/djedi/plugins/img/js/img.coffee | 4 ++-- djedi/static/djedi/plugins/img/js/img.js | 4 ++-- djedi/templates/djedi/plugins/txt/editor.html | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/djedi/static/djedi/plugins/img/js/img.coffee b/djedi/static/djedi/plugins/img/js/img.coffee index e0b360ff..06f1eca7 100644 --- a/djedi/static/djedi/plugins/img/js/img.coffee +++ b/djedi/static/djedi/plugins/img/js/img.coffee @@ -251,8 +251,8 @@ class window.ImageEditor extends window.Editor @ratioButton = $ '#ar-lock' # Field events - $('.dimension').on 'keyup', @resizeImage - $('#html-pane input').on 'keyup', => @updateImageAttributes() + $('.dimension').on 'input', @resizeImage + $('#html-pane input').on 'input', => @updateImageAttributes() @ratioButton.on 'click', @toggleAspectRatio @ratioButton.tooltip() diff --git a/djedi/static/djedi/plugins/img/js/img.js b/djedi/static/djedi/plugins/img/js/img.js index 98826d21..a50a7ce4 100644 --- a/djedi/static/djedi/plugins/img/js/img.js +++ b/djedi/static/djedi/plugins/img/js/img.js @@ -336,8 +336,8 @@ this.widthField = $('#field-width'); this.heightField = $('#field-height'); this.ratioButton = $('#ar-lock'); - $('.dimension').on('keyup', this.resizeImage); - $('#html-pane input').on('keyup', (function(_this) { + $('.dimension').on('input', this.resizeImage); + $('#html-pane input').on('input', (function(_this) { return function() { return _this.updateImageAttributes(); }; diff --git a/djedi/templates/djedi/plugins/txt/editor.html b/djedi/templates/djedi/plugins/txt/editor.html index 3e6602de..32e799b3 100644 --- a/djedi/templates/djedi/plugins/txt/editor.html +++ b/djedi/templates/djedi/plugins/txt/editor.html @@ -12,8 +12,8 @@ console.log('TextEditor.initialize()'); var editor = this; editor.$textarea = $('textarea'); - editor.$textarea.on('keyup', function () { - console.log('TextEditor:keyup'); + editor.$textarea.on('input', function () { + console.log('TextEditor:input'); editor.triggerRender(editor.$textarea.val()); editor.$textarea.change() }); From b45e5f73d2a3bd096f780a8b8dbab4057cdc4ee7 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 19:06:00 +0100 Subject: [PATCH 05/16] Use non-deprecated jQuery event listener syntax --- djedi/templates/djedi/plugins/md/editor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djedi/templates/djedi/plugins/md/editor.html b/djedi/templates/djedi/plugins/md/editor.html index 6d4fbcd8..2be0f67a 100644 --- a/djedi/templates/djedi/plugins/md/editor.html +++ b/djedi/templates/djedi/plugins/md/editor.html @@ -12,7 +12,7 @@ editor = this editor.$textarea = $('textarea'); - editor.$textarea.keydown(function(e) { + editor.$textarea.on('keydown', function(e) { if(e.keyCode === 9) { // tab was pressed // ### Get caret position/selection var start = this.selectionStart; From f8173ac17b0a6a52824d0a723293fc87f9e80009 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Tue, 5 Feb 2019 19:28:00 +0100 Subject: [PATCH 06/16] Update md editor preview on the fly Previously, it was only updated when leaving the text area. Now it is updated when you stop typing for 400 ms. I thought for a long time that there the md editor did not support updating the preview, because it never occurred to me that I could unfocus the text area to preview. This should make the feature more obvious. --- djedi/templates/djedi/plugins/md/editor.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/djedi/templates/djedi/plugins/md/editor.html b/djedi/templates/djedi/plugins/md/editor.html index 2be0f67a..99de677d 100644 --- a/djedi/templates/djedi/plugins/md/editor.html +++ b/djedi/templates/djedi/plugins/md/editor.html @@ -6,10 +6,15 @@ {% block plugin_script %}