Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Replace calls to django.utils.hashcompat by hashlib #2

Merged
merged 1 commit into from

2 participants

@Fantomas42
Owner

No description provided.

@twidi twidi merged commit 67a4a50 into liberation:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2013
  1. @Fantomas42
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 14 deletions.
  1. +10 −11 avatar/models.py
  2. +3 −3 avatar/templatetags/avatar_tags.py
View
21 avatar/models.py
@@ -1,10 +1,9 @@
-import datetime
import os
+from hashlib import md5
from django.db import models
from django.core.files.base import ContentFile
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
@@ -33,7 +32,7 @@
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 = md5(instance.user.username).hexdigest()
tmppath.extend([tmp[0], tmp[1], instance.user.username])
else:
tmppath.append(instance.user.username)
@@ -51,7 +50,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 = md5(smart_str(filename)).hexdigest()
filename = filename + ext
if size:
tmppath.extend(['resized', str(size)])
@@ -71,10 +70,10 @@ class Avatar(models.Model):
primary = models.BooleanField(default=False)
avatar = models.ImageField(max_length=1024, upload_to=avatar_file_path, blank=True)
date_uploaded = models.DateTimeField(auto_now=True)
-
+
def __unicode__(self):
return _(u'Avatar for %s') % self.user
-
+
def save(self, *args, **kwargs):
avatars = Avatar.objects.filter(user=self.user)
if self.pk:
@@ -87,14 +86,14 @@ def save(self, *args, **kwargs):
avatars.delete()
invalidate_cache(self.user)
super(Avatar, self).save(*args, **kwargs)
-
+
def delete(self, *args, **kwargs):
invalidate_cache(self.user)
super(Avatar, self).delete(*args, **kwargs)
-
+
def thumbnail_exists(self, size):
return self.avatar.storage.exists(self.avatar_name(size))
-
+
def create_thumbnail(self, size, quality=None):
# invalidate the cache of the thumbnail with the given size first
invalidate_cache(self.user, size)
@@ -124,10 +123,10 @@ def create_thumbnail(self, size, quality=None):
def avatar_url(self, size):
return self.avatar.storage.url(self.avatar_name(size))
-
+
def get_absolute_url(self):
return self.avatar_url(AVATAR_DEFAULT_SIZE)
-
+
def avatar_name(self, size):
ext = find_extension(AVATAR_THUMB_FORMAT)
return avatar_file_path(
View
6 avatar/templatetags/avatar_tags.py
@@ -1,8 +1,8 @@
import urllib
+from hashlib import md5
from django import template
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
@@ -26,7 +26,7 @@ def avatar_url(user, size=AVATAR_DEFAULT_SIZE):
if AVATAR_GRAVATAR_DEFAULT:
params['d'] = AVATAR_GRAVATAR_DEFAULT
return "http://www.gravatar.com/avatar/%s/?%s" % (
- md5_constructor(user.email).hexdigest(),
+ md5(user.email).hexdigest(),
urllib.urlencode(params))
else:
return get_default_avatar_url()
@@ -53,7 +53,7 @@ def avatar(user, size=AVATAR_DEFAULT_SIZE):
def primary_avatar(user, size=AVATAR_DEFAULT_SIZE):
"""
This tag tries to get the default avatar for a user without doing any db
- requests. It achieve this by linking to a special view that will do all the
+ requests. It achieve this by linking to a special view that will do all the
work for us. If that special view is then cached by a CDN for instance,
we will avoid many db calls.
"""
Something went wrong with that request. Please try again.