From bb0d24809e07c3d240b12ebd9e7556a85cc67cdd Mon Sep 17 00:00:00 2001 From: Lukas Kucharczyk Date: Sun, 11 Aug 2024 17:13:31 +0200 Subject: [PATCH] make sure titles are truncated --- games/static/base.css | 4 ++++ games/templates/components/table_row.html | 11 +++++++++-- games/templatetags/randomid.py | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 games/templatetags/randomid.py diff --git a/games/static/base.css b/games/static/base.css index 0900968..ba26cd9 100644 --- a/games/static/base.css +++ b/games/static/base.css @@ -2249,6 +2249,10 @@ input:checked + .toggle-bg { max-width: 20ch; } +.min-w-30char { + min-width: 30ch; +} + .max-w-30char { max-width: 30ch; } diff --git a/games/templates/components/table_row.html b/games/templates/components/table_row.html index b5ae622..35d01af 100644 --- a/games/templates/components/table_row.html +++ b/games/templates/components/table_row.html @@ -1,9 +1,16 @@ {% fragment as default_content %} +{% load randomid %} {% for td in data %} {% if forloop.first %} - {{ td }} + class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white min-w-30char"> + {% randomid td as th_popover_id %} + {{ td|truncatechars:30 }} + {% if td|length > 30 %} + {% #popover id=th_popover_id %} + {{ td }} + {% /popover %} + {% endif %} {% else %} {% #table_td %} diff --git a/games/templatetags/randomid.py b/games/templatetags/randomid.py new file mode 100644 index 0000000..86beaa3 --- /dev/null +++ b/games/templatetags/randomid.py @@ -0,0 +1,11 @@ +import random +import string + +from django import template + +register = template.Library() + + +@register.simple_tag +def randomid(seed: str = "") -> str: + return str(hash(seed + "".join(random.choices(string.ascii_lowercase, k=10))))