Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/swh_templatetags.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import json | import json | ||||
import re | import re | ||||
from django import template | from django import template | ||||
from django.core.serializers.json import DjangoJSONEncoder | |||||
from django.utils.safestring import mark_safe | from django.utils.safestring import mark_safe | ||||
from swh.web.common.converters import SWHDjangoJSONEncoder | |||||
from swh.web.common.origin_save import get_savable_visit_types | from swh.web.common.origin_save import get_savable_visit_types | ||||
from swh.web.common.utils import rst_to_html | from swh.web.common.utils import rst_to_html | ||||
register = template.Library() | register = template.Library() | ||||
@register.filter | @register.filter | ||||
def docstring_display(docstring): | def docstring_display(docstring): | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def jsonify(obj): | ||||
Args | Args | ||||
obj: Any django template context variable | obj: Any django template context variable | ||||
Returns: | Returns: | ||||
JSON representation of the variable. | JSON representation of the variable. | ||||
""" | """ | ||||
return mark_safe(json.dumps(obj, cls=DjangoJSONEncoder)) | return mark_safe(json.dumps(obj, cls=SWHDjangoJSONEncoder)) | ||||
@register.filter | @register.filter | ||||
def sub(value, arg): | def sub(value, arg): | ||||
"""Django template filter for subtracting two numbers | """Django template filter for subtracting two numbers | ||||
Args: | Args: | ||||
value (int/float): the value to subtract from | value (int/float): the value to subtract from | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |