forked from 2ik/django-editorjs-fields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
342 lines (275 loc) · 16.1 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# -*- coding: utf-8 -*-
from setuptools import setup
packages = \
['django_editorjs_fields', 'django_editorjs_fields.templatetags']
package_data = \
{'': ['*'],
'django_editorjs_fields': ['static/django-editorjs-fields/css/*',
'static/django-editorjs-fields/js/*',
'templates/django-editorjs-fields/*']}
setup_kwargs = {
'name': 'django-editorjs-fields',
'version': '0.2.7',
'description': 'Django plugin for using Editor.js',
'author': 'Ilya Kotlyakov',
'author_email': '[email protected]',
'maintainer': 'None',
'maintainer_email': 'None',
'url': 'https://github.com/2ik/django-editorjs-fields',
'packages': packages,
'package_data': package_data,
'python_requires': '>=3.6,<4.0',
'long_description': """# Editor.js for Django
Django plugin for using [Editor.js](https://editorjs.io/)
> This plugin works fine with JSONField in Django >= 3.1
[![Django Editor.js](https://i.ibb.co/r6xt4HJ/image.png)](https://github.com/2ik/django-editorjs-fields)
[![Python versions](https://img.shields.io/pypi/pyversions/django-editorjs-fields)](https://pypi.org/project/django-editorjs-fields/)
[![Python versions](https://img.shields.io/pypi/djversions/django-editorjs-fields)](https://pypi.org/project/django-editorjs-fields/)
[![Downloads](https://static.pepy.tech/personalized-badge/django-editorjs-fields?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/django-editorjs-fields)
## Installation
```bash
pip install django-editorjs-fields
```
Add `django_editorjs_fields` to `INSTALLED_APPS` in `settings.py` for your project:
```python
# settings.py
INSTALLED_APPS = [
...
\'django_editorjs_fields\',
]
```
## Upgrade
```bash
pip install django-editorjs-fields --upgrade
python manage.py collectstatic # upgrade js and css files
```
## Usage
Add code in your model
```python
# models.py
from django.db import models
from django_editorjs_fields import EditorJsJSONField # Django >= 3.1
from django_editorjs_fields import EditorJsTextField
class Post(models.Model):
body_default = models.TextField()
body_editorjs = EditorJsJSONField() # Django >= 3.1
body_editorjs_text = EditorJsTextField()
```
#### New in version 0.2.1. Django Templates support
```html
<!-- template.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
{% load editorjs %}
{{ post.body_default }}
{{ post.body_editorjs | editorjs}}
{{ post.body_editorjs_text | editorjs}}
</body>
</html>
```
## Additionally
You can add custom Editor.js plugins and configs ([List plugins](https://github.com/editor-js/awesome-editorjs))
Example custom field in models.py
```python
# models.py
from django.db import models
from django_editorjs_fields import EditorJsJSONField
class Post(models.Model):
body_editorjs_custom = EditorJsJSONField(
plugins=[
"@editorjs/image",
"@editorjs/header",
"editorjs-github-gist-plugin",
"@editorjs/[email protected]", # version allowed :)
"@editorjs/list@latest",
"@editorjs/inline-code",
"@editorjs/table",
],
tools={
"Gist": {
"class": "Gist" # Include the plugin class. See docs Editor.js plugins
},
"Image": {
"config": {
"endpoints": {
"byFile": "/editorjs/image_upload/" # Your custom backend file uploader endpoint
}
}
}
},
i18n={
\'messages\': {
\'blockTunes\': {
"delete": {
"Delete": "Удалить"
},
"moveUp": {
"Move up": "Переместить вверх"
},
"moveDown": {
"Move down": "Переместить вниз"
}
}
},
}
null=True,
blank=True
)
```
**django-editorjs-fields** support this list of Editor.js plugins by default:
<a name="plugins"></a>
<details>
<summary>EDITORJS_DEFAULT_PLUGINS</summary>
```python
EDITORJS_DEFAULT_PLUGINS = (
\'@editorjs/paragraph\',
\'@editorjs/image\',
\'@editorjs/header\',
\'@editorjs/list\',
\'@editorjs/checklist\',
\'@editorjs/quote\',
\'@editorjs/raw\',
\'@editorjs/code\',
\'@editorjs/inline-code\',
\'@editorjs/embed\',
\'@editorjs/delimiter\',
\'@editorjs/warning\',
\'@editorjs/link\',
\'@editorjs/marker\',
\'@editorjs/table\',
)
```
</details>
<details>
<summary>EDITORJS_DEFAULT_CONFIG_TOOLS</summary>
```python
EDITORJS_DEFAULT_CONFIG_TOOLS = {
\'Image\': {
\'class\': \'ImageTool\',
\'inlineToolbar\': True,
"config": {
"endpoints": {
"byFile": reverse_lazy(\'editorjs_image_upload\'),
"byUrl": reverse_lazy(\'editorjs_image_by_url\')
}
},
},
\'Header\': {
\'class\': \'Header\',
\'inlineToolbar\': True,
\'config\': {
\'placeholder\': \'Enter a header\',
\'levels\': [2, 3, 4],
\'defaultLevel\': 2,
}
},
\'Checklist\': {\'class\': \'Checklist\', \'inlineToolbar\': True},
\'List\': {\'class\': \'List\', \'inlineToolbar\': True},
\'Quote\': {\'class\': \'Quote\', \'inlineToolbar\': True},
\'Raw\': {\'class\': \'RawTool\'},
\'Code\': {\'class\': \'CodeTool\'},
\'InlineCode\': {\'class\': \'InlineCode\'},
\'Embed\': {\'class\': \'Embed\'},
\'Delimiter\': {\'class\': \'Delimiter\'},
\'Warning\': {\'class\': \'Warning\', \'inlineToolbar\': True},
\'LinkTool\': {
\'class\': \'LinkTool\',
\'config\': {
\'endpoint\': reverse_lazy(\'editorjs_linktool\'),
}
},
\'Marker\': {\'class\': \'Marker\', \'inlineToolbar\': True},
\'Table\': {\'class\': \'Table\', \'inlineToolbar\': True},
}
```
</details>
`EditorJsJSONField` accepts all the arguments of `JSONField` class.
`EditorJsTextField` accepts all the arguments of `TextField` class.
Additionally, it includes arguments such as:
| Args | Description | Default |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| `plugins` | List plugins Editor.js | `EDITORJS_DEFAULT_PLUGINS` |
| `tools` | Map of Tools to use. Set config `tools` for Editor.js [See docs](https://editorjs.io/configuration#passing-saved-data) | `EDITORJS_DEFAULT_CONFIG_TOOLS` |
| `use_editor_js` | Enables or disables the Editor.js plugin for the field | `True` |
| `autofocus` | If true, set caret at the first Block after Editor is ready | `False` |
| `hideToolbar` | If true, toolbar won\'t be shown | `False` |
| `inlineToolbar` | Defines default toolbar for all tools. | `True` |
| `readOnly` | Enable read-only mode | `False` |
| `minHeight` | Height of Editor\'s bottom area that allows to set focus on the last Block | `300` |
| `logLevel` | Editors log level (how many logs you want to see) | `ERROR` |
| `placeholder` | First Block placeholder | `Type text...` |
| `defaultBlock` | This Tool will be used as default. Name should be equal to one of Tool`s keys of passed tools. If not specified, Paragraph Tool will be used | `paragraph` |
| `i18n` | Internalization config | `{}` |
| `sanitizer` | Define default sanitizer configuration | `{ p: true, b: true, a: true }` |
## Image uploads
If you want to upload images to the editor then add `django_editorjs_fields.urls` to `urls.py` for your project with `DEBUG=True`:
```python
# urls.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
...
path(\'editorjs/\', include(\'django_editorjs_fields.urls\')),
...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```
In production `DEBUG=False` (use nginx to display images):
```python
# urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
...
path(\'editorjs/\', include(\'django_editorjs_fields.urls\')),
...
]
```
See an example of how you can work with the plugin [here](https://github.com/2ik/django-editorjs-fields/blob/main/example)
## Forms
```python
from django import forms
from django_editorjs_fields import EditorJsWidget
class TestForm(forms.ModelForm):
class Meta:
model = Post
exclude = []
widgets = {
\'body_editorjs\': EditorJsWidget(config={\'minHeight\': 100}),
\'body_editorjs_text\': EditorJsWidget(plugins=["@editorjs/image", "@editorjs/header"])
}
```
## Theme
### Default Theme
![image](https://user-images.githubusercontent.com/6692517/124242133-7a7dad00-db2d-11eb-812f-84a5c44e88c9.png)
### Dark Theme
plugin use css property [prefers-color-scheme](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme) to define a dark theme in browser
![image](https://user-images.githubusercontent.com/6692517/124240864-3dfd8180-db2c-11eb-85c1-21f0faf41775.png)
## Configure
The application can be configured by editing the project\'s `settings.py`
file.
| 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: 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` |
For `EDITORJS_IMAGE_NAME` was used `from secrets import token_urlsafe`
## Support and updates
Use github issues https://github.com/2ik/django-editorjs-fields/issues
""",
}
setup(**setup_kwargs)
# This setup.py was autogenerated using poetry.