mirror of
https://github.com/jazzband/django-avatar.git
synced 2026-03-16 22:20:30 +00:00
Merge pull request #124 from Hsinfu/custom_avatar_img_attr
add feature of customizing the attribute of avatar img
This commit is contained in:
commit
e3b1e69f16
3 changed files with 11 additions and 5 deletions
|
|
@ -1 +1 @@
|
||||||
<img src="{{ url }}" alt="{{ alt }}" width="{{ size }}" height="{{ size }}" />
|
<img src="{{ url }}" alt="{{ alt }}" width="{{ size }}" height="{{ size }}" {% for key, value in kwargs.items %}{{key}}="{{value}}" {% endfor %}/>
|
||||||
|
|
@ -70,12 +70,13 @@ def avatar(user, size=settings.AVATAR_DEFAULT_SIZE, **kwargs):
|
||||||
else:
|
else:
|
||||||
alt = six.text_type(user)
|
alt = six.text_type(user)
|
||||||
url = avatar_url(user, size)
|
url = avatar_url(user, size)
|
||||||
context = dict(kwargs, **{
|
context = {
|
||||||
'user': user,
|
'user': user,
|
||||||
'url': url,
|
'url': url,
|
||||||
'alt': alt,
|
'alt': alt,
|
||||||
'size': size,
|
'size': size,
|
||||||
})
|
'kwargs': kwargs,
|
||||||
|
}
|
||||||
return render_to_string('avatar/avatar_tag.html', context)
|
return render_to_string('avatar/avatar_tag.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,10 @@ that are required. A minimal integration can work like this:
|
||||||
|
|
||||||
{% avatar user 65 %}
|
{% avatar user 65 %}
|
||||||
|
|
||||||
|
Example for customize the attribute of the HTML ``img`` tag::
|
||||||
|
|
||||||
|
{% avatar user 65 class="img-circle img-responsive" id="user_avatar" %}
|
||||||
|
|
||||||
Template tags and filter
|
Template tags and filter
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
@ -80,10 +84,11 @@ template rendering system::
|
||||||
Renders the URL of the avatar for the given user. User can be either a
|
Renders the URL of the avatar for the given user. User can be either a
|
||||||
``django.contrib.auth.models.User`` object instance or a username.
|
``django.contrib.auth.models.User`` object instance or a username.
|
||||||
|
|
||||||
``{% avatar user [size in pixels] %}``
|
``{% avatar user [size in pixels] **kwargs %}``
|
||||||
Renders an HTML ``img`` tag for the given user for the specified size. User
|
Renders an HTML ``img`` tag for the given user for the specified size. User
|
||||||
can be either a ``django.contrib.auth.models.User`` object instance or a
|
can be either a ``django.contrib.auth.models.User`` object instance or a
|
||||||
username.
|
username. The (key, value) pairs in kwargs will be added to ``img`` tag
|
||||||
|
as its attributes.
|
||||||
|
|
||||||
``{% render_avatar avatar [size in pixels] %}``
|
``{% render_avatar avatar [size in pixels] %}``
|
||||||
Given an actual ``avatar.models.Avatar`` object instance, renders an HTML
|
Given an actual ``avatar.models.Avatar`` object instance, renders an HTML
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue