A fork of django-avatar, for GeoNode
Project description
Basics
To integrate geonode-avatar with your site, there are relatively few things that are required. A minimal integration can work like this:
List this application in the INSTALLED_APPS portion of your settings file. Your settings file will look something like:
INSTALLED_APPS = ( # ... 'avatar', )
Add the pagination urls to the end of your root urlconf. Your urlconf will look something like:
urlpatterns = patterns('', # ... (r'^admin/(.*)', admin.site.root), (r'^avatar/', include('avatar.urls')), )
Somewhere in your template navigation scheme, link to the change avatar page:
<a href="{% url avatar_change %}">Change your avatar</a>
Wherever you want to display an avatar for a user, first load the avatar template tags:
{% load avatar_tags %}
Then, use the avatar tag to display an avatar of a default size:
{% avatar user %}
Or specify a size (in pixels) explicitly:
{% avatar user 65 %}
Optionally customize avatar/change.html and avatar/confirm_delete.html to conform to your site’s look and feel.
Views
There are only two views for this application: one for changing a user’s avatar, and another for deleting a user’s avatar.
Changing an avatar
The actual view function is located at avatar.views.change, and this can be referenced by the url name avatar_change. It takes two keyword arguments: extra_context and next_override. If extra_context is provided, that context will be placed into the template’s context.
If next_override is provided, the user will be redirected to the specified URL after form submission. Otherwise the user will be redirected to the URL specified in the next parameter in request.POST. If request.POST has no next parameter, request.GET will be searched. If request.GET has no next parameter, the HTTP_REFERER header will be inspected. If that header does not exist, the user will be redirected back to the current URL.
Deleting an avatar
The actual view function is located at avatar.views.delete, and this can be referenced by the url name avatar_delete. It takes the same two keyword arguments as avatar.views.change and follows the same redirection rules as well.
Global Settings
There are a number of settings available to easily customize the avatars that appear on the site. Listed below are those settings:
- AUTO_GENERATE_AVATAR_SIZES
An iterable of integers representing the sizes of avatars to generate on upload. This can save rendering time later on if you pre-generate the resized versions. Defaults to (80,)
- AVATAR_RESIZE_METHOD
The method to use when resizing images, based on the options available in PIL. Defaults to Image.ANTIALIAS.
- AVATAR_STORAGE_DIR
The directory under MEDIA_ROOT to store the images. If using a non-filesystem storage device, this will simply be appended to the beginning of the file name.
- AVATAR_GRAVATAR_BACKUP
A boolean determining whether to default to the Gravatar service if no Avatar instance is found in the system for the given user. Defaults to True.
- AVATAR_DEFAULT_URL
The default URL to default to if AVATAR_GRAVATAR_BACKUP is set to False and there is no Avatar instance found in the system for the given user.
Management Commands
This application does include one management command: rebuild_avatars. It takes no arguments and, when run, re-renders all of the thumbnails for all of the avatars for the pixel sizes specified in the AUTO_GENERATE_AVATAR_SIZES setting.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file geonode_avatar-5.0.8-py2.py3-none-any.whl
.
File metadata
- Download URL: geonode_avatar-5.0.8-py2.py3-none-any.whl
- Upload date:
- Size: 60.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3697fba9b4fc3ee54baf2f8c2ebc86a8f02c50de14325e4e37e28a5fe1cff66d |
|
MD5 | 354ce25d4b0519b81f461fba6789a069 |
|
BLAKE2b-256 | cf36144adef733821d247de1393077bce61dfc27f3d30871e8875fb9d83d2f96 |