Closed Bouke closed 12 years ago
Hey Bouke, thanks for your patch, I'm glad to see that this library has been useful for someone. I can see how wanting to pass in a user object instead of a raw email would be useful, however, I would rather see that logic moved into the gravatar template tag in gravatar.py.
We'd also need to write a test to ensure things work properly in either case.
Something like this maybe:
def gravatar(user_or_email, size=GRAVATAR_DEFAULT_SIZE, alt_text='', css_class='gravatar'):
if (hasattr(user_or_email, 'email')):
email = user_or_email.email
else:
email = user_or_email
""" Builds an gravatar <img> tag from an email """
url = get_gravatar_url(email=email, size=size)
return '<img class="{css_class}" src="{src}" width="{width}" height="{height}" alt="{alt}" />'.format(\
css_class=css_class, src=url, width=size, height=size, alt=alt_text)
If you wanted to submit an updated pull request I'd love to take a look at it. Otherwise, I can see about patching the library myself over the weekend.
See PR2.
I got tired of writing
{% gravatar user.email %}
so I made this patch to also allow{% gravatar user %}
.