def avatar(user, size=settings.AVATAR_DEFAULT_SIZE, **kwargs): if not isinstance(user, get_user_model()): try: user = get_user(user) alt = six.text_type(user) url = avatar_url(user, size) except get_user_model().DoesNotExist: url = get_default_avatar_url() alt = _("Default Avatar") else: alt = six.text_type(user) url = avatar_url(user, size) try: alt = user.first_name[:1] + user.last_name[:1] except AttributeError: alt = "" context = { 'user': user, 'alt': alt, 'size': size, 'kwargs': kwargs, } template_name = 'avatar/avatar_tag.html' ext_context = None try: template_name, ext_context = url except ValueError: context['url'] = url if ext_context: context = dict(context, **ext_context) return render_to_string(template_name, context)
def avatar(user, size=settings.AVATAR_DEFAULT_SIZE, **kwargs): if not isinstance(user, get_user_model()): try: user = get_user(user) alt = six.text_type(user) url = avatar_url(user, size) except get_user_model().DoesNotExist: url = get_default_avatar_url() alt = _("Default Avatar") else: alt = six.text_type(user) url = avatar_url(user, size) context = dict(kwargs, **{ 'user': user, 'url': url, 'alt': alt, 'size': size, }) return render_to_string('avatar/avatar_tag.html', context)