Skip to content

Добавление картинок по урлу #25

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 2 commits into from Oct 27, 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ EDITORJS_DEFAULT_CONFIG_TOOLS = {
'Image': {
'class': 'ImageTool',
'inlineToolbar': True,
"config": {"endpoints": {"byFile": reverse_lazy('editorjs_image_upload')}},
"config": {"endpoints": {
"byFile": reverse_lazy('editorjs_image_upload'),
"byUrl": reverse_lazy('editorjs_image_by_url')
}},
},
'Header': {
'class': 'Header',
Expand Down
5 changes: 4 additions & 1 deletion django_editorjs_fields/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
'Image': {
'class': 'ImageTool',
'inlineToolbar': True,
"config": {"endpoints": {"byFile": reverse_lazy('editorjs_image_upload')}},
"config": {"endpoints": {
"byFile": reverse_lazy('editorjs_image_upload'),
"byUrl": reverse_lazy('editorjs_image_by_url')
}},
},
'Header': {
'class': 'Header',
Expand Down
7 changes: 6 additions & 1 deletion django_editorjs_fields/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.urls import path

from .views import ImageUploadView, LinkToolView
from .views import ImageUploadView, LinkToolView, ImageByUrl

urlpatterns = [
path(
Expand All @@ -14,4 +14,9 @@
staff_member_required(LinkToolView.as_view()),
name='editorjs_linktool',
),
path(
'image_by_url/',
ImageByUrl.as_view(),
name='editorjs_image_by_url',
),
]
14 changes: 14 additions & 0 deletions django_editorjs_fields/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ def get(self, request):
})

return JsonResponse({'success': 0})


class ImageByUrl(View):
http_method_names = ["post"]

@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def post(self, request):
body = json.loads(request.body.decode())
if 'url' in body:
return JsonResponse({'success': 1, 'file': {"url": body['url']}})
return JsonResponse({'success': 0})