Example #1
0
def avatar(request, codename, id, template_name="avatar/avatar.html"):
    try:
        contact = get_contact(codename)
    except Contact.DoesNotExist:
        raise Http404
    avatars = contact.avatar_set.order_by("-date_uploaded")
    index = None
    avatar = None
    if avatars:
        avatar = avatars.get(pk=id)
        if not avatar:
            return Http404

        index = avatars.filter(date_uploaded__gt=avatar.date_uploaded).count()
        count = avatars.count()

        if index == 0:
            prev = avatars.reverse()[0]
            if count <= 1:
                next = avatars[0]
            else:
                next = avatars[1]
        else:
            prev = avatars[index - 1]

        if (index + 1) >= count:
            next = avatars[0]
            prev_index = index - 1
            if prev_index < 0:
                prev_index = 0
            prev = avatars[prev_index]
        else:
            next = avatars[index + 1]

    return render(
        request, template_name, {
            "other_user": contact,
            "avatar": avatar,
            "index": index + 1,
            "avatars": avatars,
            "next": next,
            "prev": prev,
            "count": count,
        })
Example #2
0
def avatar(request, codename, id, template_name="avatar/avatar.html"):
    try:
        contact = get_contact(codename)
    except Contact.DoesNotExist:
        raise Http404
    avatars = contact.avatar_set.order_by("-date_uploaded")
    index = None
    avatar = None
    if avatars:
        avatar = avatars.get(pk=id)
        if not avatar:
            return Http404

        index = avatars.filter(date_uploaded__gt=avatar.date_uploaded).count()
        count = avatars.count()

        if index == 0:
            prev = avatars.reverse()[0]
            if count <= 1:
                next = avatars[0]
            else:
                next = avatars[1]
        else:
            prev = avatars[index - 1]

        if (index + 1) >= count:
            next = avatars[0]
            prev_index = index - 1
            if prev_index < 0:
                prev_index = 0
            prev = avatars[prev_index]
        else:
            next = avatars[index + 1]

    return render(request, template_name, {
        "other_user": contact,
        "avatar": avatar,
        "index": index + 1,
        "avatars": avatars,
        "next": next,
        "prev": prev,
        "count": count,
    })
def avatar(contact, size=settings.AVATAR_DEFAULT_SIZE, **kwargs):

    if not isinstance(contact, Contact):
        try:
            contact = get_contact(contact)
            alt = six.text_type(contact)
            url = avatar_url(contact, size)
        except Contact.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(contact)
        url = avatar_url(contact, size)
    context = dict(kwargs, **{
        'contact': contact,
        'url': url,
        'alt': alt,
        'size': size,
    })
    return render_to_string('avatar/avatar_tag.html', context)
Example #4
0
def avatar(contact, size=settings.AVATAR_DEFAULT_SIZE, **kwargs):

    if not isinstance(contact, Contact):
        try:
            contact = get_contact(contact)
            alt = six.text_type(contact)
            url = avatar_url(contact, size)
        except Contact.DoesNotExist:
            url = get_default_avatar_url()
            alt = _("Default Avatar")
    else:
        alt = six.text_type(contact)
        url = avatar_url(contact, size)
    context = dict(
        kwargs, **{
            'contact': contact,
            'url': url,
            'alt': alt,
            'size': size,
        })
    return render_to_string('avatar/avatar_tag.html', context)