def post(self, request, **kwargs): """ Uploads a file and send back its URL to CKEditor. """ uploaded_file = request.FILES['upload'] backend = image_processing.get_backend() ck_func_num = escape(request.GET['CKEditorFuncNum']) # Throws an error when an non-image file are uploaded. if not getattr(settings, 'CKEDITOR_ALLOW_NONIMAGE_FILES', True): try: backend.image_verify(uploaded_file) except utils.NotAnImageException: return HttpResponse(""" <script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction({0}, '', 'Invalid file type.'); </script>""".format(ck_func_num)) saved_path = self._save_file(request, uploaded_file) self._create_thumbnail_if_needed(backend, 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(ck_func_num, url))
def post(self, request, **kwargs): """ Uploads a file and send back its URL to CKEditor. """ uploaded_file = request.FILES['upload'] backend = image_processing.get_backend() ck_func_num = escape(request.GET['CKEditorFuncNum']) # Throws an error when an non-image file are uploaded. if not getattr(settings, 'CKEDITOR_ALLOW_NONIMAGE_FILES', True): try: backend.image_verify(uploaded_file) except utils.NotAnImageException: return HttpResponse(""" <script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction({0}, '', 'Invalid file type.'); </script>""".format(ck_func_num)) saved_path = self._save_file(request, uploaded_file) self._create_thumbnail_if_needed(backend, 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(ck_func_num, url))
def handle_noargs(self, **options): if getattr(settings, "CKEDITOR_IMAGE_BACKEND", None): backend = get_backend() for image in get_image_files(): if not self._thumbnail_exists(image): self.stdout.write("Creating thumbnail for %s" % image) try: backend.create_thumbnail(image) except Exception as e: self.stdout.write("Couldn't create thumbnail for %s: %s" % (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 self._thumbnail_exists(image): self.stdout.write("Creating thumbnail for %s" % image) try: backend.create_thumbnail(image) except Exception as e: self.stdout.write( "Couldn't create thumbnail for %s: %s" % (image, e)) self.stdout.write("Finished") else: self.stdout.write("No thumbnail backend is enabled")