This commit is contained in:
Andrea Cesari 2024-10-30 15:58:53 +00:00 committed by GitHub
commit d0acaa1f8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,7 @@ from django.db.models import Q, QuerySet
from django.utils import formats
from django.utils import timezone as django_timezone
from django.utils.encoding import smart_str
from django.utils.text import Truncator
from django.utils.translation import gettext_lazy as _
from auditlog.diff import mask_str
@ -488,6 +489,19 @@ class LogEntry(models.Model):
except AttributeError:
# if the field is a relationship it has no internal type and exclude it
continue
if field_type == "ManyToManyField":
values_display = values
values_display["objects"] = [
f"{Truncator(i).chars(140,html=True)}..." if len(i) > 140 else i
for i in values["objects"]
]
verbose_name = model_fields["mapping_fields"].get(
field.name, getattr(field, "verbose_name", field.name)
)
changes_display_dict[verbose_name] = values_display
continue
for value in values:
# handle case where field is a datetime, date, or time type
if field_type in ["DateTimeField", "DateField", "TimeField"]:
@ -508,7 +522,8 @@ class LogEntry(models.Model):
# check if length is longer than 140 and truncate with ellipsis
if len(value) > 140:
value = f"{value[:140]}..."
# value = f"{value[:140]}..."
value = f"{Truncator(value).chars(140,html=True)}..."
values_display.append(value)