Bugfix document exporter document dates are off by one day #267
This commit is contained in:
Quinn Casey 2022-05-05 09:59:11 -07:00 committed by GitHub
commit 7909b30b4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -11,7 +11,6 @@ from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.timezone import is_aware
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from documents.parsers import get_default_file_extension from documents.parsers import get_default_file_extension
@ -210,10 +209,8 @@ class Document(models.Model):
verbose_name_plural = _("documents") verbose_name_plural = _("documents")
def __str__(self): def __str__(self):
if is_aware(self.created): created = datetime.date.isoformat(self.created)
created = timezone.localdate(self.created).isoformat()
else:
created = datetime.date.isoformat(self.created)
if self.correspondent and self.title: if self.correspondent and self.title:
return f"{created} {self.correspondent} {self.title}" return f"{created} {self.correspondent} {self.title}"
else: else:

View File

@ -3,6 +3,11 @@ import tempfile
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
try:
import zoneinfo
except ImportError:
import backports.zoneinfo as zoneinfo
from django.test import override_settings from django.test import override_settings
from django.test import TestCase from django.test import TestCase
from django.utils import timezone from django.utils import timezone
@ -55,6 +60,24 @@ class TestDocument(TestCase):
) )
self.assertEqual(doc.get_public_filename(), "2020-12-25 test.pdf") 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): def test_file_name_jpg(self):
doc = Document( doc = Document(