Procházet zdrojové kódy

add startswith helper

checktheroads před 5 roky
rodič
revize
b0d634a89e
1 změnil soubory, kde provedl 10 přidání a 0 odebrání
  1. 10 0
      netbox/utilities/templatetags/helpers.py

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

@@ -228,6 +228,16 @@ def meters_to_feet(n):
     return float(n) * 3.28084
 
 
+@register.filter("startswith")
+def startswith(text: str, starts: str) -> bool:
+    """
+    Template implementation of `str.startswith()`.
+    """
+    if isinstance(text, str):
+        return text.startswith(starts)
+    return False
+
+
 #
 # Tags
 #