Remove /by-md5/ prefix from image paths

Use forked django-images for now, until we can communicate with the
upstream about it. Fixes #4
This commit is contained in:
Krzysztof Klimonda
2013-03-19 14:41:14 +01:00
parent 20359b886d
commit e0e0ac1679
4 changed files with 24 additions and 7 deletions

16
pinry/core/utils.py Normal file
View File

@@ -0,0 +1,16 @@
import hashlib
import os
def upload_path(instance, filename, **kwargs):
hasher = hashlib.md5()
for chunk in instance.image.chunks():
hasher.update(chunk)
hash = hasher.hexdigest()
base, ext = os.path.splitext(filename)
return '%(first)s/%(second)s/%(hash)s/%(base)s%(ext)s' % {
'first': hash[0],
'second': hash[1],
'hash': hash,
'base': base,
'ext': ext,
}