diff --git a/src/documents/models.py b/src/documents/models.py index a1a787325..8f531e401 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -11,7 +11,6 @@ from django.conf import settings from django.contrib.auth.models import User from django.db import models from django.utils import timezone -from django.utils.timezone import is_aware from django.utils.translation import gettext_lazy as _ from documents.parsers import get_default_file_extension @@ -210,10 +209,8 @@ class Document(models.Model): verbose_name_plural = _("documents") def __str__(self): - if is_aware(self.created): - created = timezone.localdate(self.created).isoformat() - else: - created = datetime.date.isoformat(self.created) + created = datetime.date.isoformat(self.created) + if self.correspondent and self.title: return f"{created} {self.correspondent} {self.title}" else: diff --git a/src/documents/tests/test_document_model.py b/src/documents/tests/test_document_model.py index a99d6dd18..41e3d9337 100644 --- a/src/documents/tests/test_document_model.py +++ b/src/documents/tests/test_document_model.py @@ -3,6 +3,11 @@ import tempfile from pathlib import Path from unittest import mock +try: + import zoneinfo +except ImportError: + import backports.zoneinfo as zoneinfo + from django.test import override_settings from django.test import TestCase from django.utils import timezone @@ -55,6 +60,24 @@ class TestDocument(TestCase): ) self.assertEqual(doc.get_public_filename(), "2020-12-25 test.pdf") + def test_file_name_with_timezone(self): + + doc = Document( + mime_type="application/pdf", + title="test", + created=timezone.datetime( + 2020, + 12, + 25, + 0, + 0, + 0, + 0, + zoneinfo.ZoneInfo("Europe/Berlin"), + ), + ) + self.assertEqual(doc.get_public_filename(), "2020-12-25 test.pdf") + def test_file_name_jpg(self): doc = Document(