|
|
@@ -252,3 +252,16 @@ def isodatetime(value, spec='seconds'):
|
|
|
else:
|
|
|
return ''
|
|
|
return mark_safe(f'<span title="{naturaltime(value)}">{text}</span>')
|
|
|
+
|
|
|
+
|
|
|
+@register.filter
|
|
|
+def truncate_middle(value, length):
|
|
|
+ if len(value) <= length:
|
|
|
+ return value
|
|
|
+
|
|
|
+ # Calculate split points for the two parts
|
|
|
+ half_len = (length - 1) // 2 # 1 for the ellipsis
|
|
|
+ first_part = value[:half_len]
|
|
|
+ second_part = value[len(value) - (length - 1 - half_len):]
|
|
|
+
|
|
|
+ return mark_safe(f"{first_part}…{second_part}")
|