djblets.avatars.services.fallback¶
An avatar service used as a fallback to show something basic for a user.
- class FallbackService(settings_manager_class)¶
Bases:
AvatarService
An avatar service used as a fallback.
This will display a simple avatar showing the first two characters of the user’s username, displayed on top of a background with a color based on the username.
This will automatically be used as a fallback if no other avatar backends are usable for the user.
- avatar_service_id = 'fallback'¶
The avatar service’s ID.
This must be unique for every avatar service subclass.
- name = 'Fallback'¶
The avatar service’s human-readable name.
- template_name = 'avatars/fallback.html'¶
The template for rendering the avatar as HTML.
Whether or not the avatar service is hidden from users.
Hidden avatar services are not exposed to users and are intended to be used only internally, such as with extensions providing bots.
- render(request, user, size, template_name=None)¶
Render a user’s avatar to HTML.
- Parameters:
request (
django.http.HttpRequest
) – The HTTP request.user (
django.contrib.auth.models.User
) – The user for whom the avatar is to be rendered.size (
int
) – The requested avatar size (height and width) in pixels.template_name (
unicode
, optional) – The name of the template to use for rendering.
- Returns:
The rendered avatar HTML.
- Return type:
django.utils.safestring.SafeText
- get_bg_color(user)¶
Return a background color for the avatar.
This will compute a basic HSL color for the avatar, based on the username.
- Parameters:
user (
django.contrib.auth.models.User
) – The user to generate the color for.- Returns:
The resulting HSL color definition.
- Return type:
- get_avatar_urls_uncached(user, size)¶
Return the Gravatar URLs for the requested user.
- Parameters:
user (
django.contrib.auth.models.User
) – The user whose avatar URLs are to be fetched.size (
int
) – The size (in pixels) the avatar is to be rendered at.
- Returns
dict: A dictionary containing the URLs of the user’s avatars at normal- and high-DPI.
- get_etag_data(user)¶
Return the ETag data for the user’s avatar.
- Parameters:
user (
django.contrib.auth.models.User
) – The user.- Returns:
The uniquely identifying information for the user’s avatar.
- Return type:
- __annotations__ = {}¶