Skip to content

Commit

Permalink
add feature of customizing the attribute of avatar img
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsinfu committed Mar 22, 2016
1 parent f0c45af commit 9ab18a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion avatar/templates/avatar/avatar_tag.html
Original file line number Diff line number Diff line change
@@ -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 %}/>
5 changes: 3 additions & 2 deletions avatar/templatetags/avatar_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
9 changes: 7 additions & 2 deletions docs/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------

Expand All @@ -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
Expand Down

0 comments on commit 9ab18a7

Please sign in to comment.