Source

genmap / profile / templatetags / marktag.py

Full commit
# -*- coding: utf-8
from django.utils.translation import ugettext_lazy as _
from django import template
from django.conf import settings
from genmap.profile.models import Profile

if settings.GRAVATAR:
    from gravatar.templatetags.gravatar_tags import gravatar_for_user


register = template.Library()

@register.inclusion_tag('marks/ttags/latestmarks.html')
def latestmarks():

    latest = Profile.objects.all().order_by('-date_created')[:10]
    #save some sql queries and request items only if count>0

    return {
            'latest':latest,
            }


@register.inclusion_tag('search/paginate_url_part.html',takes_context=True)
def paginate_url(context,page_num):
    import urllib
    request = context['request']
    get_copy = request.GET.copy()
    get_copy['page'] = page_num

    new_url = urllib.urlencode(get_copy)

    return {
            'url':new_url,
            }

@register.inclusion_tag('various/obfuscate_email_tag.html')
def obfuscate_email(email):
    import random
    code_list = []
    for c in email:
        d = ord(c)
        x = random.randint(0,d)
        code_list.append( "%d+%d" %(x,d-x) )
    charlist = ','.join(code_list)
    return {'charlist':charlist}

@register.inclusion_tag('marks/ttags/avatar.html')
def avatar(mark, large = False):
    if large: size = 80
    else: size = 50

    if mark.avatar:
        if large: src = mark.avatar.extra_thumbnails['large']
        else: src = mark.avatar.thumbnail
    elif settings.GRAVATAR:
        src = gravatar_for_user(mark.user, size)
    else:
        src = settings.DEFAULT_AVATAR

    return {
        'mark': mark,
        'src': src,
    }