Merge pull request #124 from Hsinfu/custom_avatar_img_attr

add feature of customizing the attribute of avatar img
This commit is contained in:
Grant McConnaughey 2016-03-23 13:51:30 -05:00
commit e3b1e69f16
3 changed files with 11 additions and 5 deletions

View file

@ -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 %}/>

View file

@ -70,12 +70,13 @@ def avatar(user, size=settings.AVATAR_DEFAULT_SIZE, **kwargs):
else:
alt = six.text_type(user)
url = avatar_url(user, size)
context = dict(kwargs, **{
context = {
'user': user,
'url': url,
'alt': alt,
'size': size,
})
'kwargs': kwargs,
}
return render_to_string('avatar/avatar_tag.html', context)

View file

@ -68,6 +68,10 @@ that are required. A minimal integration can work like this:
{% 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
------------------------
@ -80,10 +84,11 @@ template rendering system::
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.
``{% 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
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] %}``
Given an actual ``avatar.models.Avatar`` object instance, renders an HTML