Exemple #1
0
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))
Exemple #2
0
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 handle_noargs(self, **options):
     if getattr(settings, 'CKEDITOR_IMAGE_BACKEND', None):
         backend = get_backend()
         for image in get_image_files():
             if not os.path.isfile(get_thumb_filename(image)):
                 self.stdout.write("Creating thumbnail for {0}".format(image))
                 try:
                     backend.create_thumbnail(image)
                 except Exception as e:
                     self.stdout.write("Couldn't create thumbnail for {0}: {1}".format(image, e))
         self.stdout.write("Finished")
     else:
         self.stdout.write("No thumbnail backend is enabled")
 def handle_noargs(self, **options):
     if getattr(settings, 'CKEDITOR_IMAGE_BACKEND', None):
         backend = get_backend()
         for image in get_image_files():
             if not os.path.isfile(get_thumb_filename(image)):
                 self.stdout.write(
                     "Creating thumbnail for {0}".format(image))
                 try:
                     backend.create_thumbnail(image)
                 except Exception as e:
                     self.stdout.write(
                         "Couldn't create thumbnail for {0}: {1}".format(
                             image, e))
         self.stdout.write("Finished")
     else:
         self.stdout.write("No thumbnail backend is enabled")