-# coding: utf-8
+# -*- coding: utf-8
+
+import os
+import re
+import decimal
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from time import gmtime, strftime, localtime, mktime, time
from django.core.files import File
from django.core.files.storage import default_storage
-import os, re, decimal
+
from urlparse import urlparse
# filebrowser imports
"""
Change URL to PATH.
Value has to be an URL relative to MEDIA URL or a full URL (including MEDIA_URL).
-
+
Returns a PATH relative to MEDIA_ROOT.
"""
print "URL2PATH", repr(value)
"""
Change PATH to URL.
Value has to be a PATH relative to MEDIA_ROOT.
-
+
Return an URL relative to MEDIA_ROOT.
"""
mediaroot_re = re.compile(r'^(%s)' % (MEDIA_ROOT))
"""
Construct the PATH to an Image version.
Value has to be server-path, relative to MEDIA_ROOT.
-
+
version_filename = filename + version_prefix + ext
Returns a path relative to MEDIA_ROOT.
"""
Get filterdate.
"""
- returnvalue = ''
dateYear = strftime("%Y", gmtime(dateTime))
dateMonth = strftime("%m", gmtime(dateTime))
dateDay = strftime("%d", gmtime(dateTime))
- if filterDate == 'today' and int(dateYear) == int(localtime()[0]) and int(dateMonth) == int(localtime()[1]) and int(dateDay) == int(localtime()[2]): returnvalue = 'true'
- elif filterDate == 'thismonth' and dateTime >= time() - 2592000: returnvalue = 'true'
- elif filterDate == 'thisyear' and int(dateYear) == int(localtime()[0]): returnvalue = 'true'
- elif filterDate == 'past7days' and dateTime >= time() - 604800: returnvalue = 'true'
- elif filterDate == '': returnvalue = 'true'
- return returnvalue
+
+ if filterDate == 'today' and int(dateYear) == int(localtime()[0]) and int(dateMonth) == int(localtime()[1]) and int(dateDay) == int(localtime()[2]):
+ return 'true'
+
+ if filterDate == 'thismonth' and dateTime >= time() - 2592000:
+ return 'true'
+
+ if filterDate == 'thisyear' and int(dateYear) == int(localtime()[0]):
+ return 'true'
+
+ if filterDate == 'past7days' and dateTime >= time() - 604800:
+ return 'true'
+
+ return 'true' if filterDate == '' else ''
def _get_settings_var():
return select_types
-def _version_generator(value, version_prefix, force = None):
+def _version_generator(value, version_prefix, force=None):
"""
Generate Version for an Image.
value has to be a serverpath relative to MEDIA_ROOT.
from PIL import ImageFile
except ImportError:
import ImageFile
- ImageFile.MAXBLOCK = IMAGE_MAXBLOCK # default is 64k
+ ImageFile.MAXBLOCK = IMAGE_MAXBLOCK # default is 64k
try:
im = Image.open(os.path.join(MEDIA_ROOT, value))
os.chmod(version_dir, 0775)
version = scale_and_crop(im, VERSIONS[version_prefix]['width'], VERSIONS[version_prefix]['height'], VERSIONS[version_prefix]['opts'])
try:
- version.save(absolute_version_path, quality = 90, optimize = 1)
+ version.save(absolute_version_path, quality=90, optimize=1)
except IOError:
- version.save(absolute_version_path, quality = 90)
+ version.save(absolute_version_path, quality=90)
return version_path
except:
return None
r = min(xr / x, yr / y)
if r < 1.0 or (r > 1.0 and 'upscale' in opts):
- im = im.resize((int(x * r), int(y * r)), resample = Image.ANTIALIAS)
+ im = im.resize((int(x * r), int(y * r)), resample=Image.ANTIALIAS)
if 'crop' in opts:
x, y = [float(v) for v in im.size]
return value.replace(" ", "_").lower()
else:
return value
-
-
-