Skip to content

Commit 2b0e02b

Browse files
authored
Merge pull request #12 from 2ik/dev
Release 0.2.2
2 parents 7e42835 + 5ea53fb commit 2b0e02b

File tree

7 files changed

+39
-30
lines changed

7 files changed

+39
-30
lines changed

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ plugin use css property [prefers-color-scheme](https://developer.mozilla.org/en-
275275
The application can be configured by editing the project's `settings.py`
276276
file.
277277

278-
| Key | Description | Default |
279-
| ------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------- |
280-
| `EDITORJS_DEFAULT_PLUGINS` | List of plugins names Editor.js from npm | [See above](#plugins) |
281-
| `EDITORJS_DEFAULT_CONFIG_TOOLS` | Map of Tools to use | [See above](#plugins) |
282-
| `EDITORJS_IMAGE_UPLOAD_PATH` | Path uploads images | `settings.MEDIA_URL + 'uploads/images/'` |
283-
| `EDITORJS_IMAGE_NAME_ORIGINAL` | To use the original name of the image file? | `False` |
284-
| `EDITORJS_IMAGE_NAME_POSTFIX` | Image file name postfix. Ignored when `EDITORJS_IMAGE_NAME_ORIGINAL` is `True` | `token_urlsafe(5)` |
285-
| `EDITORJS_IMAGE_NAME` | Image file name postfix. Ignored when `EDITORJS_IMAGE_NAME_ORIGINAL` is `False` | `token_urlsafe(8)` |
286-
| `EDITORJS_VERSION` | Version Editor.js | `2.22.1` |
287-
288-
For `EDITORJS_IMAGE_NAME_POSTFIX` and `EDITORJS_IMAGE_NAME` was used `from secrets import token_urlsafe`
278+
| Key | Description | Default | Type |
279+
| --------------------------------- | ---------------------------------------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
280+
| `EDITORJS_DEFAULT_PLUGINS` | List of plugins names Editor.js from npm | [See above](#plugins) | `list[str]`, `tuple[str]` |
281+
| `EDITORJS_DEFAULT_CONFIG_TOOLS` | Map of Tools to use | [See above](#plugins) | `dict[str, dict]` |
282+
| `EDITORJS_IMAGE_UPLOAD_PATH` | Path uploads images | `uploads/images/` | `str` |
283+
| `EDITORJS_IMAGE_UPLOAD_PATH_DATE` | Subdirectories | `%Y/%m/` | `str` |
284+
| `EDITORJS_IMAGE_NAME_ORIGINAL` | To use the original name of the image file? | `False` | `bool` |
285+
| `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/)) |
286+
| `EDITORJS_VERSION` | Version Editor.js | `2.22.2` | `str` |
287+
288+
For `EDITORJS_IMAGE_NAME` was used `from secrets import token_urlsafe`
289289

290290
## Support and updates
291291

django_editorjs_fields/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.1"
1+
__version__ = "0.2.2"
22

33
from .fields import EditorJsJSONField, EditorJsTextField
44
from .widgets import EditorJsWidget

django_editorjs_fields/config.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
from datetime import datetime
21
from secrets import token_urlsafe
32

43
from django.conf import settings
54

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

8-
VERSION = getattr(settings, "EDITORJS_VERSION", '2.22.1')
7+
VERSION = getattr(settings, "EDITORJS_VERSION", '2.22.2')
98

109
IMAGE_UPLOAD_PATH = str(
11-
getattr(settings, 'EDITORJS_IMAGE_UPLOAD_PATH', 'uploads/images/')
12-
) + datetime.now().strftime("%Y/%m/")
10+
getattr(settings, "EDITORJS_IMAGE_UPLOAD_PATH", 'uploads/images/')
11+
)
12+
13+
IMAGE_UPLOAD_PATH_DATE = getattr(
14+
settings, "EDITORJS_IMAGE_UPLOAD_PATH_DATE", '%Y/%m/')
1315

1416
IMAGE_NAME_ORIGINAL = getattr(
1517
settings, "EDITORJS_IMAGE_NAME_ORIGINAL", False)
1618

17-
IMAGE_NAME_POSTFIX = getattr(
18-
settings, "EDITORJS_IMAGE_NAME_POSTFIX", token_urlsafe(5))
19-
2019
IMAGE_NAME = getattr(
21-
settings, "EDITORJS_IMAGE_NAME", token_urlsafe(8))
20+
settings, "EDITORJS_IMAGE_NAME", lambda **_: token_urlsafe(8))
2221

2322
PLUGINS = getattr(
2423
settings, "EDITORJS_DEFAULT_PLUGINS", (

django_editorjs_fields/static/django-editorjs-fields/css/django-editorjs-fields.css

+3
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,7 @@ div[data-editorjs-holder] {
9595
color: #fff;
9696
background: #616161;
9797
}
98+
.change-form #container #content-main .ce-block--selected .ce-block__content {
99+
background: #426b8a;
100+
}
98101
}

django_editorjs_fields/views.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
2+
from datetime import datetime
23

34
from django.http import JsonResponse
45
from django.utils.decorators import method_decorator
56
from django.views import View
67
from django.views.decorators.csrf import csrf_exempt
78

8-
from .config import (IMAGE_NAME, IMAGE_NAME_ORIGINAL, IMAGE_NAME_POSTFIX,
9-
IMAGE_UPLOAD_PATH)
9+
from .config import (IMAGE_NAME, IMAGE_NAME_ORIGINAL, IMAGE_UPLOAD_PATH,
10+
IMAGE_UPLOAD_PATH_DATE)
1011
from .utils import storage
1112

1213

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

37-
# filesize = len(file['content'])
38-
# filetype = file['content-type']
38+
# filesize = len(the_file['content'])
39+
# filetype = the_file['content-type']
3940

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

42-
if IMAGE_NAME_ORIGINAL:
43-
filename = filename + IMAGE_NAME_POSTFIX
44-
else:
45-
filename = IMAGE_NAME
43+
if IMAGE_NAME_ORIGINAL is False:
44+
filename = IMAGE_NAME(filename=filename, file=the_file)
4645

4746
filename += extension
4847

48+
upload_path = IMAGE_UPLOAD_PATH
49+
50+
if IMAGE_UPLOAD_PATH_DATE:
51+
upload_path += datetime.now().strftime(IMAGE_UPLOAD_PATH_DATE)
52+
4953
path = storage.save(
50-
os.path.join(IMAGE_UPLOAD_PATH, filename), the_file
54+
os.path.join(upload_path, filename), the_file
5155
)
5256
link = storage.url(path)
5357

example/example/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,6 @@
139139

140140
# django_editorjs_fields
141141
EDITORJS_VERSION = '2.22.1'
142+
# EDITORJS_IMAGE_NAME_ORIGINAL = True
143+
# EDITORJS_IMAGE_UPLOAD_PATH_DATE = None
144+
# EDITORJS_IMAGE_NAME = lambda filename, **_: f"{filename}_12345"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "django-editorjs-fields"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Django plugin for using Editor.js"
55
authors = ["Ilya Kotlyakov <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)