# -*- coding: utf-8 -*- # # Copyright (C) 2013 Branko Majic # # This file is part of Django Conntrackt. # # Django Conntrackt is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) any # later version. # # Django Conntrackt is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # Django Conntrackt. If not, see . # # Django imports. from django import template from django import urls from django.utils.html import format_html from django.urls import reverse # Get an instance of Django's template library. register = template.Library() @register.simple_tag(takes_context=False) def html_link(text, view, *args, **kwargs): """ A small wrapper for showing HTML links. Positional arguments: text - Text that should be used as a link. view - View name for which the URL should be shown args - Additional positional arguments that will be passed to resolver for creating the URL. Keyword arguments: id - Identifier for the HTML element. class - Class(es) for the HTML element. title - Title for the HTML element. get - Additional GET parameter that should be appended to the URL. """ # Verify the passed-in keyword arguments first. for key in kwargs.keys(): if key not in ("get", "class", "title", "id"): raise template.TemplateSyntaxError("Unknown argument for 'html_link' tag: %r" % key) # Generate the URL by using the supplied view name and arguments that should # be passed to the view. url = urls.reverse(view, args=args) # Set-up the base pattern (url, parameters, text). if 'get' in kwargs: pattern = '