From 280099f4557c60cba50d53c8f2936d5721c28c4e Mon Sep 17 00:00:00 2001 From: AstreaTSS <25420078+AstreaTSS@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:55:32 -0400 Subject: [PATCH] feat: make shortened item descriptions a bit better --- common/models.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/models.py b/common/models.py index f5e94bb..9ccf811 100644 --- a/common/models.py +++ b/common/models.py @@ -11,6 +11,7 @@ import datetime import os import re +import textwrap from collections import Counter from enum import IntEnum @@ -66,9 +67,10 @@ def code_template(value: str) -> str: def short_desc(description: str, length: int = 25) -> str: - if len(description) > length: - description = f"{description[:length-3]}..." - return description + new_description = textwrap.shorten(description, length, placeholder="...") + if new_description == "...": # word is too long, lets manually cut it + return f"{description[:length-3].strip()}..." + return new_description class TruthBullet(PrismaTruthBullet):