Sfoglia il codice sorgente

Introduced 'startswith' template filter

Jeremy Stretch 9 anni fa
parent
commit
1a4e8999c5
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      netbox/utilities/templatetags/helpers.py

+ 8 - 0
netbox/utilities/templatetags/helpers.py

@@ -36,6 +36,14 @@ def gfm(value):
     return mark_safe(html)
     return mark_safe(html)
 
 
 
 
+@register.filter()
+def startswith(value, arg):
+    """
+    Test whether a string starts with the given argument
+    """
+    return str(value).startswith(arg)
+
+
 @register.filter()
 @register.filter()
 def user_can_add(model, user):
 def user_can_add(model, user):
     perm_name = '{}:add_{}'.format(model._meta.app_label, model.__class__.__name__.lower())
     perm_name = '{}:add_{}'.format(model._meta.app_label, model.__class__.__name__.lower())