Giter Club home page Giter Club logo

Comments (8)

darklow avatar darklow commented on July 19, 2024 1

I created a pull request with a possibility to change avatar file path handler.
Now users can specify their own file paths based on different criteria.
For example i am usually sepearating in subdivisions by last 2 or 3 numbers from instance ID, to make sure files are +/- similarly distributed. For example this is how I extended current path handler:

# settings.py:
AVATAR_PATH_HANDLER = 'user.avatars.my_avatar_path_handler'

# user/avatars.py
from avatar.models import avatar_path_handler

def my_avatar_path_handler(instance=None, filename=None, size=None, ext=None):
    path = avatar_path_handler(instance, filename, size, ext)
    parts = path.split('/')
    parts[1] = str(instance.user_id)[-2:]
    return '/'.join(parts)

# Final path:
# avatars/21/file-name...
# avatars/02/file-name...
# avatars/73/file-name...

from django-avatar.

diox avatar diox commented on July 19, 2024

I wrote it with 2 levels of hashing because I didn't need more, but you're right, it can get out of control with enough users.

I think it would be better to make AVATAR_HASH_USERDIRNAMES an integer with the lebels of hash subdivisions needed. strftime based folder structures are not really practical to browse in my opinion. I'll try implement this if I get some time this week.

from django-avatar.

darklow avatar darklow commented on July 19, 2024

I agree. As a solution it would great if avatar_file_path method could be configurable.
https://github.com/grantmcconnaughey/django-avatar/blob/master/avatar/models.py#L26

There is no perfect solution for everyone. If users could define their own callback, they could customise path whatever way they want. What do you think?

from django-avatar.

grantmcconnaughey avatar grantmcconnaughey commented on July 19, 2024

I've merged @darklow's fix into master. I'll release 3.0 soon.

from django-avatar.

darklow avatar darklow commented on July 19, 2024

@grantmcconnaughey thanks!

from django-avatar.

jacopsd avatar jacopsd commented on July 19, 2024

Sorry if this is not the right place to ask but,
This AVATAR_PATH_HANDLER looks like a good solution for my multi-tenants + avatars problem:
http://stackoverflow.com/questions/41530171/django-tenant-schemas-avatars

Only issue now is: how to get access to the 'request' within that AVATAR_PATH_HANDLER?
If I can get access to the request, I can make a tenant specific path to store the avatar.

from django-avatar.

grantmcconnaughey avatar grantmcconnaughey commented on July 19, 2024

@jacopsd, the AVATAR_PATH_HANDLER function is not passed a request object, so the only way to get this would be through the current thread's request.

Try this blog post: http://nedbatchelder.com/blog/201008/global_django_requests.html

from django-avatar.

jacopsd avatar jacopsd commented on July 19, 2024

great, thx

from django-avatar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.