logs_extra.py 1.91 KB
Newer Older
Gabriel Detraz's avatar
Gabriel Detraz committed
1
# -*- mode: python; coding: utf-8 -*-
lhark's avatar
lhark committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017  Gabriel Détraz
# Copyright © 2017  Goulven Kermarec
# Copyright © 2017  Augustin Lemesle
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Maël Kervella's avatar
Maël Kervella committed
23 24 25
"""logs.templatetags.logs_extra
A templatetag to get the class name for a given object
"""
lhark's avatar
lhark committed
26

chirac's avatar
chirac committed
27 28 29 30
from django import template

register = template.Library()

Maël Kervella's avatar
Maël Kervella committed
31

chirac's avatar
chirac committed
32 33
@register.filter
def classname(obj):
Maël Kervella's avatar
Maël Kervella committed
34
    """ Returns the object class name """
chirac's avatar
chirac committed
35
    return obj.__class__.__name__
36 37 38


@register.inclusion_tag('buttons/history.html')
39 40 41 42 43 44 45 46 47 48
def history_button(instance, text=False, html_class=True):
    """Creates the correct history button for an instance.

    Args:
        instance: The instance of which you want to get history buttons.
        text: Flag stating if a 'History' text should be displayed.
        html_class: Flag stating if the link should have the html classes
            allowing it to be displayed as a button.

    """
49 50 51 52 53 54 55
    return {
        'application': instance._meta.app_label,
        'name': instance._meta.model_name,
        'id': instance.id,
        'text': text,
        'class': html_class,
    }