Skip to content
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

extract filer_id from canonical url #38

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 <img> element in an internal property, for later use.
this.element = element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions ckeditor_filebrowser_filer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))

Expand Down Expand Up @@ -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)
return HttpResponseRedirect(url)