Skip to content

Release 0.2.2 #12

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

Merged
merged 7 commits into from
Aug 3, 2021
Merged
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
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ plugin use css property [prefers-color-scheme](https://developer.mozilla.org/en-
The application can be configured by editing the project's `settings.py`
file.

| Key | Description | Default |
| ------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------- |
| `EDITORJS_DEFAULT_PLUGINS` | List of plugins names Editor.js from npm | [See above](#plugins) |
| `EDITORJS_DEFAULT_CONFIG_TOOLS` | Map of Tools to use | [See above](#plugins) |
| `EDITORJS_IMAGE_UPLOAD_PATH` | Path uploads images | `settings.MEDIA_URL + 'uploads/images/'` |
| `EDITORJS_IMAGE_NAME_ORIGINAL` | To use the original name of the image file? | `False` |
| `EDITORJS_IMAGE_NAME_POSTFIX` | Image file name postfix. Ignored when `EDITORJS_IMAGE_NAME_ORIGINAL` is `True` | `token_urlsafe(5)` |
| `EDITORJS_IMAGE_NAME` | Image file name postfix. Ignored when `EDITORJS_IMAGE_NAME_ORIGINAL` is `False` | `token_urlsafe(8)` |
| `EDITORJS_VERSION` | Version Editor.js | `2.22.1` |

For `EDITORJS_IMAGE_NAME_POSTFIX` and `EDITORJS_IMAGE_NAME` was used `from secrets import token_urlsafe`
| Key | Description | Default | Type |
| --------------------------------- | ---------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `EDITORJS_DEFAULT_PLUGINS` | List of plugins names Editor.js from npm | [See above](#plugins) | `list[str]`, `tuple[str]` |
| `EDITORJS_DEFAULT_CONFIG_TOOLS` | Map of Tools to use | [See above](#plugins) | `dict[str, dict]` |
| `EDITORJS_IMAGE_UPLOAD_PATH` | Path uploads images | `uploads/images/` | `str` |
| `EDITORJS_IMAGE_UPLOAD_PATH_DATE` | Subdirectories | `%Y/%m/` | `str` |
| `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: django.core.files.uploadedfile.InMemoryUploadedFile)` ([docs](https://docs.djangoproject.com/en/3.0/ref/files/uploads/)) |
| `EDITORJS_VERSION` | Version Editor.js | `2.22.2` | `str` |

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

## Support and updates

Expand Down
2 changes: 1 addition & 1 deletion django_editorjs_fields/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.2.1"
__version__ = "0.2.2"

from .fields import EditorJsJSONField, EditorJsTextField
from .widgets import EditorJsWidget
Expand Down
15 changes: 7 additions & 8 deletions django_editorjs_fields/config.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
from datetime import datetime
from secrets import token_urlsafe

from django.conf import settings

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

VERSION = getattr(settings, "EDITORJS_VERSION", '2.22.1')
VERSION = getattr(settings, "EDITORJS_VERSION", '2.22.2')

IMAGE_UPLOAD_PATH = str(
getattr(settings, 'EDITORJS_IMAGE_UPLOAD_PATH', 'uploads/images/')
) + datetime.now().strftime("%Y/%m/")
getattr(settings, "EDITORJS_IMAGE_UPLOAD_PATH", 'uploads/images/')
)

IMAGE_UPLOAD_PATH_DATE = getattr(
settings, "EDITORJS_IMAGE_UPLOAD_PATH_DATE", '%Y/%m/')

IMAGE_NAME_ORIGINAL = getattr(
settings, "EDITORJS_IMAGE_NAME_ORIGINAL", False)

IMAGE_NAME_POSTFIX = getattr(
settings, "EDITORJS_IMAGE_NAME_POSTFIX", token_urlsafe(5))

IMAGE_NAME = getattr(
settings, "EDITORJS_IMAGE_NAME", token_urlsafe(8))
settings, "EDITORJS_IMAGE_NAME", lambda **_: token_urlsafe(8))

PLUGINS = getattr(
settings, "EDITORJS_DEFAULT_PLUGINS", (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ div[data-editorjs-holder] {
color: #fff;
background: #616161;
}
.change-form #container #content-main .ce-block--selected .ce-block__content {
background: #426b8a;
}
}
22 changes: 13 additions & 9 deletions django_editorjs_fields/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
from datetime import datetime

from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.csrf import csrf_exempt

from .config import (IMAGE_NAME, IMAGE_NAME_ORIGINAL, IMAGE_NAME_POSTFIX,
IMAGE_UPLOAD_PATH)
from .config import (IMAGE_NAME, IMAGE_NAME_ORIGINAL, IMAGE_UPLOAD_PATH,
IMAGE_UPLOAD_PATH_DATE)
from .utils import storage


Expand Down Expand Up @@ -34,20 +35,23 @@ def post(self, request):
{'success': 0, 'message': 'You can only upload images.'}
)

# filesize = len(file['content'])
# filetype = file['content-type']
# filesize = len(the_file['content'])
# filetype = the_file['content-type']

filename, extension = os.path.splitext(the_file.name)

if IMAGE_NAME_ORIGINAL:
filename = filename + IMAGE_NAME_POSTFIX
else:
filename = IMAGE_NAME
if IMAGE_NAME_ORIGINAL is False:
filename = IMAGE_NAME(filename=filename, file=the_file)

filename += extension

upload_path = IMAGE_UPLOAD_PATH

if IMAGE_UPLOAD_PATH_DATE:
upload_path += datetime.now().strftime(IMAGE_UPLOAD_PATH_DATE)

path = storage.save(
os.path.join(IMAGE_UPLOAD_PATH, filename), the_file
os.path.join(upload_path, filename), the_file
)
link = storage.url(path)

Expand Down
3 changes: 3 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,6 @@

# django_editorjs_fields
EDITORJS_VERSION = '2.22.1'
# EDITORJS_IMAGE_NAME_ORIGINAL = True
# EDITORJS_IMAGE_UPLOAD_PATH_DATE = None
# EDITORJS_IMAGE_NAME = lambda filename, **_: f"{filename}_12345"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-editorjs-fields"
version = "0.2.1"
version = "0.2.2"
description = "Django plugin for using Editor.js"
authors = ["Ilya Kotlyakov <[email protected]>"]
license = "MIT"
Expand Down