mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-07 23:20:59 +00:00
PEP8 and import tweaks.
This commit is contained in:
parent
302399d837
commit
6adadafc74
5 changed files with 27 additions and 27 deletions
|
|
@ -22,7 +22,7 @@ class AdminThumbnail(object):
|
|||
|
||||
def __call__(self, obj):
|
||||
thumbnail = getattr(obj, self.image_field, None)
|
||||
|
||||
|
||||
if not thumbnail:
|
||||
raise Exception('The property {0} is not defined on {1}.'.format(
|
||||
obj, self.image_field))
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
"""
|
||||
|
||||
from django.db.models.loading import cache
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from optparse import make_option
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from imagekit.utils import get_spec_files
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
import os
|
||||
import datetime
|
||||
from StringIO import StringIO
|
||||
from imagekit.lib import *
|
||||
from imagekit.utils import img_to_fobj, get_spec_files, open_image
|
||||
from imagekit.processors import ProcessorPipeline
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.files.base import ContentFile
|
||||
from django.utils.encoding import force_unicode, smart_str
|
||||
from django.db import models
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from django.db.models.fields.files import ImageFieldFile
|
||||
from django.db.models.signals import post_save, post_delete
|
||||
from django.utils.encoding import force_unicode, smart_str
|
||||
|
||||
from imagekit.lib import Image, ImageFile
|
||||
from imagekit.utils import img_to_fobj, get_spec_files, open_image
|
||||
from imagekit.processors import ProcessorPipeline
|
||||
|
||||
# Modify image file buffer size.
|
||||
ImageFile.MAXBLOCK = getattr(settings, 'PIL_IMAGEFILE_MAXBLOCK', 256 * 2 ** 10)
|
||||
|
|
@ -170,7 +171,7 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
|
|||
if lazy and (getattr(self, '_file', None) or self.storage.exists(self.name)):
|
||||
return
|
||||
|
||||
if self.source_file: # TODO: Should we error here or something if the source_file doesn't exist?
|
||||
if self.source_file: # TODO: Should we error here or something if the source_file doesn't exist?
|
||||
# Process the original image file
|
||||
try:
|
||||
fp = self.source_file.storage.open(self.source_file.name)
|
||||
|
|
@ -244,9 +245,9 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
|
|||
smart_str(cache_to(self.instance, self.source_file.name,
|
||||
self.attname, self._suggested_extension))))
|
||||
else:
|
||||
dir_name = os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(cache_to))))
|
||||
filename = os.path.normpath(os.path.basename(filename))
|
||||
new_filename = os.path.join(dir_name, filename)
|
||||
dir_name = os.path.normpath(force_unicode(datetime.datetime.now().strftime(smart_str(cache_to))))
|
||||
filename = os.path.normpath(os.path.basename(filename))
|
||||
new_filename = os.path.join(dir_name, filename)
|
||||
|
||||
return new_filename
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from imagekit.lib import *
|
||||
from imagekit.lib import Image
|
||||
|
||||
|
||||
class _Resize(object):
|
||||
|
||||
|
||||
width = None
|
||||
height = None
|
||||
|
||||
|
||||
def __init__(self, width=None, height=None):
|
||||
if width is not None:
|
||||
self.width = width
|
||||
|
|
@ -68,7 +68,7 @@ class Crop(_Resize):
|
|||
cur_width, cur_height = img.size
|
||||
horizontal_anchor, vertical_anchor = Crop._ANCHOR_PTS[self.anchor or \
|
||||
Crop.CENTER]
|
||||
ratio = max(float(self.width)/cur_width, float(self.height)/cur_height)
|
||||
ratio = max(float(self.width) / cur_width, float(self.height)/cur_height)
|
||||
resize_x, resize_y = ((cur_width * ratio), (cur_height * ratio))
|
||||
crop_x, crop_y = (abs(self.width - resize_x), abs(self.height - resize_y))
|
||||
x_diff, y_diff = (int(crop_x / 2), int(crop_y / 2))
|
||||
|
|
@ -91,7 +91,7 @@ class Fit(_Resize):
|
|||
"""Resizes an image to fit within the specified dimensions.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, width=None, height=None, upscale=None):
|
||||
"""
|
||||
:param width: The maximum width of the desired image.
|
||||
|
|
@ -107,15 +107,15 @@ class Fit(_Resize):
|
|||
def process(self, img):
|
||||
cur_width, cur_height = img.size
|
||||
if not self.width is None and not self.height is None:
|
||||
ratio = min(float(self.width)/cur_width,
|
||||
float(self.height)/cur_height)
|
||||
ratio = min(float(self.width) / cur_width,
|
||||
float(self.height) / cur_height)
|
||||
else:
|
||||
if self.width is None:
|
||||
ratio = float(self.height)/cur_height
|
||||
ratio = float(self.height) / cur_height
|
||||
else:
|
||||
ratio = float(self.width)/cur_width
|
||||
new_dimensions = (int(round(cur_width*ratio)),
|
||||
int(round(cur_height*ratio)))
|
||||
ratio = float(self.width) / cur_width
|
||||
new_dimensions = (int(round(cur_width * ratio)),
|
||||
int(round(cur_height * ratio)))
|
||||
if new_dimensions[0] > cur_width or \
|
||||
new_dimensions[1] > cur_height:
|
||||
if not self.upscale:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
""" ImageKit utility functions """
|
||||
import tempfile
|
||||
import types
|
||||
|
||||
import tempfile, types
|
||||
from django.utils.functional import wraps
|
||||
from lib import Image
|
||||
|
||||
from imagekit.lib import Image
|
||||
|
||||
|
||||
def img_to_fobj(img, format, **kwargs):
|
||||
|
|
@ -49,4 +49,3 @@ def _wrap_copy(f):
|
|||
pass
|
||||
return img
|
||||
return copy
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue