mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
New setting to specify path to a method for avatar file path
handling. Solves problems related to custom deployments and directory paths: #10 #9.
This commit is contained in:
parent
de25cfb8c6
commit
cdb7974054
3 changed files with 9 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ class AvatarConf(AppConf):
|
|||
DEFAULT_SIZE = 80
|
||||
RESIZE_METHOD = Image.ANTIALIAS
|
||||
STORAGE_DIR = 'avatars'
|
||||
PATH_HANDLER = 'avatar.models.avatar_path_handler'
|
||||
GRAVATAR_BASE_URL = 'https://www.gravatar.com/avatar/'
|
||||
GRAVATAR_FIELD = 'email'
|
||||
GRAVATAR_BACKUP = True
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from django.db import models
|
|||
from django.core.files import File
|
||||
from django.core.files.base import ContentFile
|
||||
from django.core.files.storage import get_storage_class
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils import six
|
||||
from django.db.models import signals
|
||||
|
|
@ -22,8 +23,7 @@ except ImportError:
|
|||
|
||||
avatar_storage = get_storage_class(settings.AVATAR_STORAGE)()
|
||||
|
||||
|
||||
def avatar_file_path(instance=None, filename=None, size=None, ext=None):
|
||||
def avatar_path_handler(instance=None, filename=None, size=None, ext=None):
|
||||
tmppath = [settings.AVATAR_STORAGE_DIR]
|
||||
if settings.AVATAR_HASH_USERDIRNAMES:
|
||||
tmp = hashlib.md5(get_username(instance.user)).hexdigest()
|
||||
|
|
@ -51,6 +51,8 @@ def avatar_file_path(instance=None, filename=None, size=None, ext=None):
|
|||
tmppath.append(os.path.basename(filename))
|
||||
return os.path.join(*tmppath)
|
||||
|
||||
avatar_file_path = import_string(settings.AVATAR_PATH_HANDLER)
|
||||
|
||||
|
||||
def find_extension(format):
|
||||
format = format.lower()
|
||||
|
|
|
|||
|
|
@ -135,6 +135,10 @@ AVATAR_GRAVATAR_FIELD
|
|||
AVATAR_MAX_SIZE
|
||||
File size limit for avatar upload. Default is ``1024 * 1024`` (1mb).
|
||||
|
||||
AVATAR_PATH_HANDLER
|
||||
Path to a method for avatar file path handling. Default is
|
||||
``avatar.models.avatar_path_handler``.
|
||||
|
||||
Management Commands
|
||||
-------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue