Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/swh_templatetags.py
# Copyright (C) 2017-2019 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 | ||||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | """Django template filter to get a value in a dictionary. | ||||
Returns: | Returns: | ||||
The requested value in the dictionary | The requested value in the dictionary | ||||
""" | """ | ||||
return dict[key] | return dict[key] | ||||
@register.filter | @register.filter | ||||
def visit_type_savable(visit_type): | def visit_type_savable(visit_type: str) -> bool: | ||||
"""Django template filter to check if a save request can be | """Django template filter to check if a save request can be | ||||
created for a given visit type. | created for a given visit type. | ||||
Args: | Args: | ||||
visit_type (str): the type of visit | visit_type: the type of visit | ||||
Returns: | Returns: | ||||
If the visit type is saveable or not | If the visit type is saveable or not | ||||
""" | """ | ||||
return visit_type in get_savable_visit_types() | return visit_type in get_savable_visit_types(privileged=True) | ||||
anlambert: This is only used for the "Take new snapshot" action so you can keep that function as it is. | |||||
@register.filter | @register.filter | ||||
def split(value, arg): | def split(value, arg): | ||||
"""Django template filter to split a string. | """Django template filter to split a string. | ||||
Args: | Args: | ||||
value (str): the string to split | value (str): the string to split | ||||
arg (str): the split separator | arg (str): the split separator | ||||
Returns: | Returns: | ||||
list: the split string parts | list: the split string parts | ||||
""" | """ | ||||
return value.split(arg) | return value.split(arg) |
This is only used for the "Take new snapshot" action so you can keep that function as it is.