Skip to content

Separate script path configuration parameters #69

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

Open
wants to merge 3 commits into
base: dev
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: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ file.
| `EDITORJS_IMAGE_NAME_ORIGINAL` | To use the original name of the image file? | `False` | `bool` |
| `EDITORJS_IMAGE_NAME` | Image file name. Ignored when `EDITORJS_IMAGE_NAME_ORIGINAL` is `True` | `token_urlsafe(8)` | `callable(filename: str, file: InMemoryUploadedFile)` ([docs](https://docs.djangoproject.com/en/3.0/ref/files/uploads/)) |
| `EDITORJS_EMBED_HOSTNAME_ALLOWED` | List of allowed hostname for embed | `('player.vimeo.com','www.youtube.com','coub.com','vine.co','imgur.com','gfycat.com','player.twitch.tv','player.twitch.tv','music.yandex.ru','codepen.io','www.instagram.com','twitframe.com','assets.pinterest.com','www.facebook.com','www.aparat.com'),` | `list[str]`, `tuple[str]` |
| `EDITORJS_VERSION` | Version Editor.js | `2.25.0` | `str` |
| `EDITORJS_SCRIPT_PATH` | Path to Editor.js script | `//cdn.jsdelivr.net/npm/@editorjs/editorjs@` + `EDITORJS_VERSION` | `str` |
| `PLUGINS_SCRIPT_PATH` | Path to Editor.js plugins scripts | `//cdn.jsdelivr.net/npm/` | `str` |
| `EDITORJS_VERSION` | Version Editor.js | `2.30.8` | `str` |

For `EDITORJS_IMAGE_NAME` was used `from secrets import token_urlsafe`

Expand Down
12 changes: 11 additions & 1 deletion django_editorjs_fields/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@

DEBUG = getattr(settings, "DEBUG", False)

VERSION = getattr(settings, "EDITORJS_VERSION", '2.25.0')
VERSION = getattr(settings, "EDITORJS_VERSION", '2.30.8')

# ATTACHMENT_REQUIRE_AUTHENTICATION = str(
# getattr(settings, "EDITORJS_ATTACHMENT_REQUIRE_AUTHENTICATION", True)
# )

EDITORJS_SCRIPT_PATH = getattr(
settings,
"EDITORJS_SCRIPT_PATH",
'//cdn.jsdelivr.net/npm/@editorjs/editorjs@' + VERSION,
)

PLUGINS_SCRIPT_PATH = getattr(
settings, "PLUGINS_SCRIPT_PATH", '//cdn.jsdelivr.net/npm/'
)

EMBED_HOSTNAME_ALLOWED = str(
getattr(settings, "EDITORJS_EMBED_HOSTNAME_ALLOWED", (
'player.vimeo.com',
Expand Down
8 changes: 3 additions & 5 deletions django_editorjs_fields/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe

from .config import CONFIG_TOOLS, PLUGINS, PLUGINS_KEYS, VERSION
from .config import CONFIG_TOOLS, PLUGINS, PLUGINS_KEYS, EDITORJS_SCRIPT_PATH, PLUGINS_SCRIPT_PATH


class LazyEncoder(DjangoJSONEncoder):
Expand Down Expand Up @@ -76,14 +76,12 @@ def configuration(self):

@cached_property
def media(self):
js_list = [
'//cdn.jsdelivr.net/npm/@editorjs/editorjs@' + VERSION # lib
]
js_list = [EDITORJS_SCRIPT_PATH] # lib

plugins = self.plugins or PLUGINS

if plugins:
js_list += ['//cdn.jsdelivr.net/npm/' + p for p in plugins]
js_list += [PLUGINS_SCRIPT_PATH + p for p in plugins]

js_list.append('django-editorjs-fields/js/django-editorjs-fields.js')

Expand Down