Skip to content

Commit a5541b0

Browse files
committed
Single connection plugins & Fix
1 parent 8203572 commit a5541b0

File tree

10 files changed

+55
-149
lines changed

10 files changed

+55
-149
lines changed

django_editorjs_fields/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
__version__ = "0.1.1"
1+
__version__ = "0.1.9"
22

3-
from .fields import EditorJsTextField, EditorJsJSONField
3+
from .fields import EditorJsJSONField, EditorJsTextField
44
from .widgets import EditorJsWidget
55

6-
__all__ = ("EditorJsTextField", "EditorJsJSONField",
7-
"EditorJsWidget", "__version__")
6+
__all__ = ("EditorJsTextField", "EditorJsJSONField", "EditorJsWidget", "__version__")

django_editorjs_fields/config.py

Lines changed: 23 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33

44
from django.conf import settings
55

6-
76
DEBUG = getattr(settings, "DEBUG", False)
87

9-
EDITORJS_IMAGE_UPLOAD_PATH = str(getattr(
10-
settings,
11-
'EDITORJS_IMAGE_UPLOAD_PATH',
12-
'uploads/images/'
13-
)) + datetime.now().strftime("%Y/%m/")
8+
EDITORJS_IMAGE_UPLOAD_PATH = str(
9+
getattr(settings, 'EDITORJS_IMAGE_UPLOAD_PATH', 'uploads/images/')
10+
) + datetime.now().strftime("%Y/%m/")
1411

15-
EDITORJS_IMAGE_NAME_ORIGINAL = getattr(
16-
settings, "EDITORJS_IMAGE_NAME_ORIGINAL", False)
12+
EDITORJS_IMAGE_NAME_ORIGINAL = getattr(settings, "EDITORJS_IMAGE_NAME_ORIGINAL", False)
1713
EDITORJS_IMAGE_NAME_POSTFIX = getattr(
18-
settings, "EDITORJS_IMAGE_NAME_POSTFIX", token_urlsafe(5))
19-
EDITORJS_IMAGE_NAME = getattr(
20-
settings, "EDITORJS_IMAGE_NAME", token_urlsafe(8))
14+
settings, "EDITORJS_IMAGE_NAME_POSTFIX", token_urlsafe(5)
15+
)
16+
EDITORJS_IMAGE_NAME = getattr(settings, "EDITORJS_IMAGE_NAME", token_urlsafe(8))
2117

2218
DEFAULT_PLUGINS = (
2319
'@editorjs/paragraph',
@@ -34,19 +30,15 @@
3430
'@editorjs/warning',
3531
'@editorjs/link',
3632
'@editorjs/marker',
37-
'@editorjs/table'
33+
'@editorjs/table',
3834
)
3935

4036
DEFAULT_CONFIG_PLUGINS = {
4137
'@editorjs/image': {
4238
'Image': {
4339
'class': 'ImageTool',
4440
'inlineToolbar': True,
45-
"config": {
46-
"endpoints": {
47-
"byFile": "/editorjs/image_upload/"
48-
}
49-
}
41+
"config": {"endpoints": {"byFile": "/editorjs/image_upload/"}},
5042
}
5143
},
5244
'@editorjs/header': {
@@ -56,74 +48,20 @@
5648
'config': {
5749
'placeholder': 'Enter a header',
5850
'levels': [2, 3, 4],
59-
'defaultLevel': 2
60-
}
61-
}
62-
},
63-
'@editorjs/checklist': {
64-
'Checklist': {
65-
'class': 'Checklist',
66-
'inlineToolbar': True
51+
'defaultLevel': 2,
52+
},
6753
}
6854
},
69-
'@editorjs/list': {
70-
'List': {
71-
'class': 'List',
72-
'inlineToolbar': True
73-
}
74-
},
75-
'@editorjs/quote': {
76-
'Quote': {
77-
'class': 'Quote',
78-
'inlineToolbar': True
79-
}
80-
},
81-
'@editorjs/raw': {
82-
'Raw': {
83-
'class': 'RawTool'
84-
}
85-
},
86-
'@editorjs/code': {
87-
'Code': {
88-
'class': 'CodeTool'
89-
}
90-
},
91-
'@editorjs/inline-code': {
92-
'InlineCode': {
93-
'class': 'InlineCode'
94-
}
95-
},
96-
'@editorjs/embed': {
97-
'Embed': {
98-
'class': 'Embed'
99-
}
100-
},
101-
'@editorjs/delimiter': {
102-
'Delimiter': {
103-
'class': 'Delimiter'
104-
}
105-
},
106-
'@editorjs/warning': {
107-
'Warning': {
108-
'class': 'Warning',
109-
'inlineToolbar': True
110-
}
111-
},
112-
'@editorjs/link': {
113-
'LinkTool': {
114-
'class': 'LinkTool'
115-
}
116-
},
117-
'@editorjs/marker': {
118-
'Marker': {
119-
'class': 'Marker',
120-
'inlineToolbar': True
121-
}
122-
},
123-
'@editorjs/table': {
124-
'Table': {
125-
'class': 'Table',
126-
'inlineToolbar': True
127-
}
128-
}
55+
'@editorjs/checklist': {'Checklist': {'class': 'Checklist', 'inlineToolbar': True}},
56+
'@editorjs/list': {'List': {'class': 'List', 'inlineToolbar': True}},
57+
'@editorjs/quote': {'Quote': {'class': 'Quote', 'inlineToolbar': True}},
58+
'@editorjs/raw': {'Raw': {'class': 'RawTool'}},
59+
'@editorjs/code': {'Code': {'class': 'CodeTool'}},
60+
'@editorjs/inline-code': {'InlineCode': {'class': 'InlineCode'}},
61+
'@editorjs/embed': {'Embed': {'class': 'Embed'}},
62+
'@editorjs/delimiter': {'Delimiter': {'class': 'Delimiter'}},
63+
'@editorjs/warning': {'Warning': {'class': 'Warning', 'inlineToolbar': True}},
64+
'@editorjs/link': {'LinkTool': {'class': 'LinkTool'}},
65+
'@editorjs/marker': {'Marker': {'class': 'Marker', 'inlineToolbar': True}},
66+
'@editorjs/table': {'Table': {'class': 'Table', 'inlineToolbar': True}},
12967
}

django_editorjs_fields/fields.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@
1818

1919
class FieldMixin(Field):
2020
def get_internal_type(self):
21-
return "TextField"
21+
return 'TextField'
2222

2323

2424
class EditorJsFieldMixin:
2525
def __init__(self, plugins=None, tools=None, **kwargs):
2626
self.plugins = plugins
2727
self.tools = tools
28-
self.version = kwargs.pop('version', '2.18.0')
28+
self.version = kwargs.pop('version', '2.19.0')
2929
self.use_editor_js = kwargs.pop('use_editor_js', True)
3030
super().__init__(**kwargs)
3131

3232
def formfield(self, **kwargs):
3333
if self.use_editor_js:
3434
widget = EditorJsWidget(
35-
plugins=self.plugins, tools=self.tools, version=self.version)
35+
plugins=self.plugins, tools=self.tools, version=self.version
36+
)
3637
else:
3738
widget = Textarea()
3839

@@ -65,7 +66,7 @@ def _check_supported_json(self):
6566
checks.Warning(
6667
'You don\'t support JSONField, please use'
6768
'EditorJsTextField instead of EditorJsJSONField',
68-
obj=self
69+
obj=self,
6970
)
7071
]
7172
return []

django_editorjs_fields/urls.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from .views import ImageUploadView
55

66
urlpatterns = [
7-
path('image_upload/', staff_member_required(ImageUploadView.as_view()),
8-
name='editorjs_image_upload'),
7+
path(
8+
'image_upload/',
9+
staff_member_required(ImageUploadView.as_view()),
10+
name='editorjs_image_upload',
11+
),
912
]

django_editorjs_fields/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def get_storage_class():
77
getattr(
88
settings,
99
'EDITORJS_STORAGE_BACKEND',
10-
'django.core.files.storage.DefaultStorage'
10+
'django.core.files.storage.DefaultStorage',
1111
)
1212
)()
1313

django_editorjs_fields/views.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ def post(self, request):
2727
'image/x-png',
2828
'image/png',
2929
'image/webp',
30-
'image/gif'
30+
'image/gif',
3131
]
3232
if not the_file.content_type in allowed_types:
3333
return JsonResponse(
34-
{
35-
'success': 0,
36-
'message': 'You can only upload images.'
37-
}
34+
{'success': 0, 'message': 'You can only upload images.'}
3835
)
3936

4037
# filesize = len(file['content'])
@@ -49,16 +46,10 @@ def post(self, request):
4946

5047
filename += extension
5148

52-
path = storage.save(os.path.join(
53-
EDITORJS_IMAGE_UPLOAD_PATH, filename), the_file)
49+
path = storage.save(
50+
os.path.join(EDITORJS_IMAGE_UPLOAD_PATH, filename), the_file
51+
)
5452
link = storage.url(path)
5553

56-
return JsonResponse(
57-
{
58-
'success': 1,
59-
'file': {
60-
"url": link
61-
}
62-
}
63-
)
54+
return JsonResponse({'success': 1, 'file': {"url": link}})
6455
return JsonResponse({'success': 0})

django_editorjs_fields/widgets.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ def media(self):
3535
self.tools = _tools
3636

3737
js_list = [
38-
'https://cdn.jsdelivr.net/npm/@editorjs/editorjs@' + self.version,
38+
'//cdn.jsdelivr.net/npm/@editorjs/editorjs@'
39+
+ self.version # default plugin
3940
]
4041

4142
if plugins:
42-
js_list.append('https://cdn.jsdelivr.net/combine/npm/' +
43-
',npm/'.join(plugins))
43+
js_list += ['//cdn.jsdelivr.net/npm/' + p for p in plugins]
4444

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

4747
return Media(
48-
css={
49-
'all': ['django-editorjs-fields/css/django-editorjs-fields.css']},
50-
js=js_list
48+
css={'all': ['django-editorjs-fields/css/django-editorjs-fields.css']},
49+
js=js_list,
5150
)
5251

5352
def render(self, name, value, attrs=None, renderer=None):
@@ -57,6 +56,9 @@ def render(self, name, value, attrs=None, renderer=None):
5756
<div data-editorjs-holder></div>
5857
<script>
5958
initEditorJsField('%s', %s);
60-
</script>''' % (attrs.get('id'), json.dumps(self.tools))
59+
</script>''' % (
60+
attrs.get('id'),
61+
json.dumps(self.tools),
62+
)
6163

6264
return mark_safe(html)

example/blog/models.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ class Post(models.Model):
2626
}
2727
},
2828
null=True,
29-
blank=True
29+
blank=True,
3030
)
3131
body_textfield = EditorJsTextField(
32-
plugins=[
33-
"@editorjs/image"
34-
],
35-
null=True,
36-
blank=True
32+
plugins=["@editorjs/image"], null=True, blank=True
3733
)

poetry.lock

Lines changed: 1 addition & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ python = "^3.6"
3232
Django = "^3.0.0"
3333
pylint = "^2.6.0"
3434
autopep8 = "^1.5.4"
35-
psycopg2 = "^2.8.6"
3635
pylint-django = "^2.3.0"
3736

3837
[build-system]

0 commit comments

Comments
 (0)