2010-02-12 21:46:44 +03:00
|
|
|
import random
|
|
|
|
|
2009-10-23 02:37:15 +04:00
|
|
|
import jinja2
|
|
|
|
|
2010-02-12 21:46:44 +03:00
|
|
|
from jingo import register, env
|
2009-10-23 02:37:15 +04:00
|
|
|
|
|
|
|
|
2010-02-13 14:44:24 +03:00
|
|
|
@register.filter
|
|
|
|
def emaillink(email):
|
|
|
|
if not email:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
fallback = email[::-1] # reverse
|
|
|
|
# inject junk somewhere
|
|
|
|
i = random.randint(0, len(email)-1)
|
|
|
|
fallback = u"%s%s%s" % (jinja2.escape(fallback[:i]),
|
|
|
|
u'<span class="i">null</span>',
|
|
|
|
jinja2.escape(fallback[i:]))
|
|
|
|
# replace @ and .
|
|
|
|
fallback = fallback.replace('@', '@').replace('.', '.')
|
|
|
|
|
|
|
|
node = u'<span class="emaillink">%s</span>' % fallback
|
|
|
|
return jinja2.Markup(node)
|
|
|
|
|
|
|
|
|
2009-10-23 02:37:15 +04:00
|
|
|
@register.filter
|
|
|
|
def user_link(user):
|
2010-03-24 22:21:27 +03:00
|
|
|
if not user:
|
|
|
|
return ''
|
2010-02-12 21:46:44 +03:00
|
|
|
return jinja2.Markup(_user_link(user))
|
|
|
|
|
|
|
|
|
2010-03-02 02:56:52 +03:00
|
|
|
@register.function
|
2010-02-12 21:46:44 +03:00
|
|
|
def users_list(users):
|
2010-03-24 22:21:27 +03:00
|
|
|
if not users:
|
|
|
|
return ''
|
2010-02-12 21:46:44 +03:00
|
|
|
return jinja2.Markup(', '.join(map(_user_link, users)))
|
|
|
|
|
|
|
|
|
|
|
|
def _user_link(user):
|
2010-07-26 21:28:14 +04:00
|
|
|
if isinstance(user, basestring):
|
|
|
|
return user
|
2010-02-12 21:46:44 +03:00
|
|
|
return u'<a href="%s">%s</a>' % (
|
2010-08-30 23:15:25 +04:00
|
|
|
user.get_url_path(), unicode(jinja2.escape(user.name)))
|
2010-02-12 21:46:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
@register.filter
|
|
|
|
def user_vcard(user, table_class='person-info',
|
|
|
|
about_addons=True):
|
|
|
|
c = {'profile': user, 'table_class': table_class,
|
|
|
|
'about_addons': about_addons}
|
|
|
|
t = env.get_template('users/vcard.html').render(**c)
|
|
|
|
return jinja2.Markup(t)
|