diff --git a/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/dialogs/filerImageDialog.js b/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/dialogs/filerImageDialog.js index 0200ff6..5e12fcb 100755 --- a/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/dialogs/filerImageDialog.js +++ b/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/dialogs/filerImageDialog.js @@ -319,9 +319,20 @@ // Flag the insertion mode for later use. this.insertMode = true; } - else + else { this.insertMode = false; + // try to guess filer_id from canonical url. + var filer_id = element.getAttribute('filer_id'); + if (!filer_id ) { + var src = element.getAttribute('src'); + if (src.startsWith(editor.canonical_url_prefix)) { + var parts = src.split('/'); + element.setAttribute('filer_id', parseInt(parts[parts.length-2])); + } + } + } + // Store the reference to the element in an internal property, for later use. this.element = element; diff --git a/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/plugin.js b/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/plugin.js index 3fee423..8715a00 100755 --- a/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/plugin.js +++ b/ckeditor_filebrowser_filer/static/ckeditor/ckeditor/plugins/filerimage/plugin.js @@ -66,10 +66,16 @@ } }); + // jQuery.get('/filebrowser_filer/url_reverse/', + // { url_name: 'admin:filer-directory_listing-last' }, + // function(data) { + + // }); + jQuery.get('/filebrowser_filer/url_reverse/', - { url_name: 'admin:filer-directory_listing-last' }, + 'url_name=canonical&args=0&args=1', function(data) { - + editor.canonical_url_prefix = data.substring(0, data.length - 5); }); var dialog = CKEDITOR.dialog.getCurrent(); diff --git a/ckeditor_filebrowser_filer/views.py b/ckeditor_filebrowser_filer/views.py index c97d6cc..d3783ee 100644 --- a/ckeditor_filebrowser_filer/views.py +++ b/ckeditor_filebrowser_filer/views.py @@ -4,7 +4,7 @@ from django import http from django.conf import settings -from django.core import urlresolvers +from django import urls from django.http import HttpResponseRedirect from filer.models import File @@ -49,10 +49,10 @@ def url_reverse(request): data = getattr(request, request.method) url_name = data.get('url_name') try: - path = urlresolvers.reverse(url_name, args=data.getlist('args')) - (view_func, args, kwargs) = urlresolvers.resolve(path) + path = urls.reverse(url_name, args=data.getlist('args')) + (view_func, args, kwargs) = urls.resolve(path) return http.HttpResponse(path, content_type='text/plain') - except urlresolvers.NoReverseMatch: + except urls.NoReverseMatch: return http.HttpResponse('Error', content_type='text/plain') return http.HttpResponseNotAllowed(('GET', 'POST')) @@ -135,4 +135,4 @@ def serve_image(request, image_id, thumb_options=None, width=None, height=None): if thumb: return server.serve(request, file_obj=thumb, save_as=False) else: - return HttpResponseRedirect(url) \ No newline at end of file + return HttpResponseRedirect(url)