def test_get_thumb_filename(self): # Thumnbnail filename is the same as original # with _thumb inserted before the extension. self.failUnless(views.get_thumb_filename(self.test_path) == self.test_path.replace(".ext", "_thumb.ext")) # Without an extension thumnbnail filename is the same as original # with _thumb appened. no_ext_path = self.test_path.replace(".ext", "") self.failUnless(views.get_thumb_filename(no_ext_path) == no_ext_path + "_thumb")
def test_get_thumb_filename(self): # Thumnbnail filename is the same as original with _thumb inserted before the extension. self.failUnless( views.get_thumb_filename(self.test_path) == self.test_path.replace( '.ext', '_thumb.ext')) # Without an extension thumnbnail filename is the same as original with _thumb appened. no_ext_path = self.test_path.replace('.ext', '') self.failUnless( views.get_thumb_filename(no_ext_path) == no_ext_path + '_thumb')
def handle_noargs(self, **options): for image in get_image_files(): if not os.path.isfile(get_thumb_filename(image)): print "Creating thumbnail for %s" % image try: create_thumbnail(image) except Exception, e: print "Couldn't create thumbnail for %s: %s" % (image, e)
def handle_noargs(self, **options): 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: create_thumbnail(image) except Exception as e: self.stdout.write("Couldn't create thumbnail for {0}: {1}".format(image, e)) self.stdout.write("Finished")
def ckupload(request): """ run normal upload for ckeditor, move the file over to storage, then delete it. """ #callback = upload(request) #return callback # Get the uploaded file from request. upload = request.FILES['upload'] upload_ext = os.path.splitext(upload.name)[1] # If CKEDITOR_RESTRICT_BY_USER is True upload file to user specific path. if getattr(settings, 'CKEDITOR_RESTRICT_BY_USER', False): user_path = user.username else: user_path = '' # Generate date based path to put uploaded file. date_path = datetime.now().strftime('%Y/%m/%d') # Complete upload path (upload_path + date_path). upload_path = os.path.join(settings.CKEDITOR_UPLOAD_PATH, user_path, \ date_path) # Open output file in which to store upload. saved_path = default_storage.save(upload_path + '/' + upload.name, ContentFile(upload.read())) ###make thumbnail### tmp_filename = 'tmp' + os.path.splitext(upload.name)[1] out = open(tmp_filename, 'wb+') # Iterate through chunks and write to destination. for chunk in upload.chunks(): out.write(chunk) out.close() image = Image.open(tmp_filename) if image.mode not in ('L', 'RGB'): image = image.convert('RGB') # scale and crop to thumbnail imagefit = ImageOps.fit(image, THUMBNAIL_SIZE, Image.ANTIALIAS) default_storage.save(upload_path + '/' + get_thumb_filename(upload.name), ContentFile(imagefit)) # Respond with Javascript sending ckeditor upload url. #url = get_media_url(upload_filename) url = settings.MEDIA_URL + saved_path return HttpResponse(""" <script type='text/javascript'> window.parent.CKEDITOR.tools.callFunction(%s, '%s'); </script>""" % (request.GET['CKEditorFuncNum'], url))