Merge pull request #47 from stockr-labs/feature#hashlib

Replaces Django Hashcompat with Hashlib
This commit is contained in:
Jannis Leidel 2013-05-26 06:22:58 -07:00
commit 0117368218
3 changed files with 8 additions and 7 deletions

View file

@ -1,11 +1,11 @@
import datetime
import os
import hashlib
from django.db import models
from django.core.files.base import ContentFile
from django.core.files.storage import get_storage_class
from django.utils.translation import ugettext as _
from django.utils.hashcompat import md5_constructor
from django.utils.encoding import smart_str
from django.db.models import signals
@ -40,7 +40,7 @@ avatar_storage = get_storage_class(AVATAR_STORAGE)()
def avatar_file_path(instance=None, filename=None, size=None, ext=None):
tmppath = [AVATAR_STORAGE_DIR]
if AVATAR_HASH_USERDIRNAMES:
tmp = md5_constructor(instance.user.username).hexdigest()
tmp = hashlib.md5(instance.user.username).hexdigest()
tmppath.extend([tmp[0], tmp[1], instance.user.username])
else:
tmppath.append(instance.user.username)
@ -58,7 +58,7 @@ def avatar_file_path(instance=None, filename=None, size=None, ext=None):
# File doesn't exist yet
if AVATAR_HASH_FILENAMES:
(root, ext) = os.path.splitext(filename)
filename = md5_constructor(smart_str(filename)).hexdigest()
filename = hashlib.md5(smart_str(filename)).hexdigest()
filename = filename + ext
if size:
tmppath.extend(['resized', str(size)])

View file

@ -1,10 +1,10 @@
import urllib
import urlparse
import hashlib
from django import template
from django.template.loader import render_to_string
from django.utils.translation import ugettext as _
from django.utils.hashcompat import md5_constructor
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
@ -28,7 +28,7 @@ def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
params = {'s': str(size)}
if AVATAR_GRAVATAR_DEFAULT:
params['d'] = AVATAR_GRAVATAR_DEFAULT
path = "%s/?%s" % (md5_constructor(user.email).hexdigest(),
path = "%s/?%s" % (hashlib.md5(user.email).hexdigest(),
urllib.urlencode(params))
return urlparse.urljoin(AVATAR_GRAVATAR_BASE_URL, path)

View file

@ -1,6 +1,7 @@
import hashlib
from django.conf import settings
from django.core.cache import cache
from django.utils.hashcompat import md5_constructor
from django.utils.encoding import smart_str
from django.template.defaultfilters import slugify
@ -20,7 +21,7 @@ def get_cache_key(user_or_username, size, prefix):
user_or_username = user_or_username.username
key = u'%s_%s_%s' % (prefix, user_or_username, size)
return u'%s_%s' % (slugify(key)[:100],
md5_constructor(smart_str(key)).hexdigest())
hashlib.md5(smart_str(key)).hexdigest())
def cache_result(func):