[Oi-commits] r1330 - trunk/sanat
oi-commits at pardus.org.tr
oi-commits at pardus.org.tr
Sat May 3 17:23:37 EEST 2008
Author: jnmbk
Date: Sat May 3 17:23:37 2008
New Revision: 1330
Modified:
trunk/sanat/forms.py
trunk/sanat/utils.py
Log:
small changes and a small fix
Modified: trunk/sanat/forms.py
=================================================================
--- trunk/sanat/forms.py (original)
+++ trunk/sanat/forms.py Sat May 3 17:23:37 2008
@@ -32,10 +32,6 @@
class ScreenField(forms.Field):
"""That one will validate the screen upload things"""
- def __init__(self,*args,**kwargs):
- """Calling the upper function"""
- super(ScreenField,self).__init__(*args,**kwargs)
-
def clean(self,value):
"""The validator part"""
#bos musun ?
@@ -126,18 +122,15 @@
#file upload kısımları
screen=ScreenField(widget=forms.FileInput(),required=True, label="Photo",
help_text="Yüklenecek resim (en fazla %s kilobayt), izin verilenler (jpeg,png,gif)"% (settings.MAX_PHOTO_UPLOAD_SIZE))
-
file_up=FileUploadField(widget=forms.FileInput(),required=True, label="Dosya",
help_text="Yüklenecek dosya (en fazla %s kilobayt), izin verilenler (zip)"% (settings.MAX_FILE_UPLOAD))
-
def __init__(self,*args,**kwargs):
""" Collect licenses and categories"""
+ super(TemaUploadForm, self).__init__(*args, **kwargs)
self.fields['license'].choices=[(int(l.id), l.name) for l in License.objects.all()]
self.fields['parent_category'].choices=[(int(cat.id), cat.cat_name) for cat in Category.objects.all()]
- super(TemaUploadForm, self).__init__(*args, **kwargs)
-
def save(self):
""" That part is adding the thning to the system"""
Modified: trunk/sanat/utils.py
=================================================================
--- trunk/sanat/utils.py (original)
+++ trunk/sanat/utils.py Sat May 3 17:23:37 2008
@@ -1,4 +1,3 @@
-
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
@@ -17,7 +16,7 @@
image_cache = get_cache('locmem:///')
#is it alot ?
-_FILE_CACHE_TIMEOUT = 60 * 60 * 60 * 24 # 1 day
+_FILE_CACHE_TIMEOUT = 5184000 # 1 day
_THUMBNAIL_GLOB = '%s_t*%s'
#some value not important for now
@@ -25,9 +24,11 @@
DEFAULT_WIDTH=100
def _get_thumbnail_path(path, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
- """ create thumbnail path from path and required width and/or height.
+ """
+ create thumbnail path from path and required width and/or height.
thumbnail file name is constructed like this:
- <basename>_t_[w<width>][_h<height>].<extension>"""
+ <basename>_t_[w<width>][_h<height>].<extension>
+ """
basedir = os.path.dirname(path) + '/'
base, ext = os.path.splitext(os.path.basename(path))
@@ -47,7 +48,6 @@
th_name += ext
return urlparse.urljoin(basedir, th_name)
-#
def _get_path_from_url(url, root=MEDIA_ROOT, url_root=MEDIA_URL):
""" make filesystem path from url """
@@ -56,7 +56,6 @@
url = url[len(url_root):] # strip media root url
return os.path.normpath(os.path.join(root, url))
-#
def _get_url_from_path(path, root=MEDIA_ROOT, url_root=MEDIA_URL):
""" make url from filesystem path """
@@ -65,7 +64,6 @@
path = path[len(root):] # strip media root
return urlparse.urljoin(root, path.replace('\\', '/'))
-#
def _has_thumbnail(photo_url, width=None, height=None, root=MEDIA_ROOT, url_root=MEDIA_URL):
# one of width/height is required
@@ -123,7 +121,6 @@
return th_url
# make thumbnail
-
# get original image size
orig_w, orig_h = get_image_size(photo_url, root, url_root)
if (orig_w is None) and (orig_h) is None:
@@ -158,7 +155,6 @@
return photo_url
return th_url
-#
def _remove_thumbnails(photo_url, root=MEDIA_ROOT, url_root=MEDIA_URL):
if not photo_url: return # empty url
@@ -167,29 +163,24 @@
base, ext = os.path.splitext(os.path.basename(file_name))
basedir = os.path.dirname(file_name)
-
for file in fnmatch.filter(os.listdir(basedir), _THUMBNAIL_GLOB % (base, ext)):
path = os.path.join(basedir, file)
os.remove(path)
- image_cache.delete(path) # delete from cache
-
+ # delete from cache
+ image_cache.delete(path)
def remove_model_thumbnails(model):
-
""" remove all thumbnails for all ImageFields (and subclasses) in the model """
for obj in model._meta.fields:
#print obj
if isinstance(obj, FileField):
url = getattr(model,'file')
_remove_thumbnails(url)
- #
-#
def _make_admin_thumbnail(url):
""" make thumbnails for admin interface """
make_thumbnail(url, width=120)
-#
def make_admin_thumbnails(model):
""" create thumbnails for admin interface for all ImageFields (and subclasses) in the model """
@@ -198,13 +189,11 @@
if isinstance(obj, FileField):
url = getattr(model,'file')
make_thumbnail(url, width=120)
- #
-#
def _get_thumbnail_url(photo_url, width=DEFAULT_HEIGHT, height=DEFAULT_WIDTH, root=MEDIA_ROOT, url_root=MEDIA_URL):
- """ return thumbnail URL for requested photo_url and required width and/or height
-
- if thumbnail file do not exists returns original URL
+ """
+ return thumbnail URL for requested photo_url and required width and/or height
+ if thumbnail file do not exists returns original URL
"""
# one of width/height is required
@@ -214,21 +203,21 @@
return _get_thumbnail_path(photo_url, width, height)
else:
return photo_url
-#
def _set_cached_file(path, value):
- """ Store file dependent data in cache.
- Timeout is set to _FILE_CACHE_TIMEOUT (1month).
+ """
+ Store file dependent data in cache.
+ Timeout is set to _FILE_CACHE_TIMEOUT (1month).
"""
mtime = os.path.getmtime(path)
image_cache.set(path, (mtime, value,), _FILE_CACHE_TIMEOUT)
-#
def _get_cached_file(path, default=None):
- """ Get file content from cache.
- If modification time differ return None and delete
- data from cache.
+ """
+ Get file content from cache.
+ If modification time differ return None and delete
+ data from cache.
"""
cached = image_cache.get(path, default)
@@ -249,9 +238,10 @@
#
def get_image_size(photo_url, root=MEDIA_ROOT, url_root=MEDIA_URL):
- """ returns image size.
+ """
+ returns image size.
- image sizes are cached (using separate locmem:/// cache instance)
+ image sizes are cached (using separate locmem:/// cache instance)
"""
path = os.path.join(root, _get_path_from_url(photo_url, root, url_root))
@@ -265,11 +255,8 @@
#import sys
#print >>sys.stderr, '[GET IMAGE SIZE] error %s for file %r' % (err, photo_url)
return None, None
- #
if size is not None:
_set_cached_file(path, size)
else:
return None, None
- #
return size
-#
More information about the Oi-commits
mailing list