1. Gregory Petukhov
  2. trustlink

Source

trustlink / trustlink / django / templatetags / trustlink_tags.py

import traceback

from django import template
from django.conf import settings

from trustlink.client import TrustlinkClient

register = template.Library()

@register.inclusion_tag('trustlink/link_block.html', takes_context=True)
def trustlink_links(context):
    try:
        request = context['request']
        url = 'http://%s%s' % (settings.TRUSTLINK_HOST, request.get_full_path())
        tl = TrustlinkClient(
            trustlink_user=settings.TRUSTLINK_USER,
            url=url,
            data_dir=settings.TRUSTLINK_DATA_DIR,
            test=settings.TRUSTLINK_TEST,
            remote_ip=request.META['REMOTE_ADDR'],
            request_headers=request.META,
            request_params=request.GET)
        context['trustlink'] = tl.build_links()
    except Exception, ex:
        info = {
            'error': unicode(ex),
            'traceback': traceback.format_exc(),
        }
        context['trustlink'] = info
    return context