def get_image_browse_urls(user=None): """ Recursively walks all dirs under upload dir and generates a list of thumbnail and full image URL's for each file found. """ images = [] for filename in get_image_files(user=user): src = utils.get_media_url(filename) if getattr(settings, 'CKEDITOR_IMAGE_BACKEND', None): thumb = utils.get_media_url(utils.get_thumb_filename(filename)) else: thumb = src images.append({'thumb': thumb, 'src': src}) return images
def upload(request): """ Uploads a file and send back its URL to CKEditor. TODO: Validate uploads """ # Get the uploaded file from request. upload = request.FILES['upload'] # Open output file in which to store upload. upload_filename = get_upload_filename(upload.name, request.user) saved_path = default_storage.save(upload_filename, upload) backend = image_processing.get_backend() if backend.should_create_thumbnail(saved_path): backend.create_thumbnail(saved_path) url = utils.get_media_url(saved_path) # Respond with Javascript sending ckeditor upload url. return HttpResponse(""" <script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction({0}, '{1}'); </script>""".format(request.GET['CKEditorFuncNum'], url))
def get_image_browse_urls(user=None): """ Recursively walks all dirs under upload dir and generates a list of thumbnail and full image URL's for each file found. """ images = [] for filename in get_image_files(user=user): src = utils.get_media_url(filename) if getattr(settings, 'CKEDITOR_IMAGE_BACKEND', None): thumb = utils.get_media_url(utils.get_thumb_filename(filename)) else: thumb = src images.append({ 'thumb': thumb, 'src': src }) return images