base: apply make_aware only to naive datetimes (#57649)

This commit is contained in:
Benjamin Dauvergne 2021-10-06 16:21:57 +02:00
parent 7109698192
commit 169231c3aa
2 changed files with 7 additions and 2 deletions

View File

@ -36,7 +36,7 @@ from django.shortcuts import resolve_url
from django.urls import reverse
from django.utils.encoding import force_bytes, force_text
from django.utils.six.moves.urllib.parse import quote
from django.utils.timezone import make_aware
from django.utils.timezone import is_naive, make_aware
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import (
@ -269,7 +269,8 @@ class GenericViewLogsConnectorView(GenericConnectorMixin, ListView):
if query_uuid is None or query_uuid is not None and not qs.exists():
qs = qs.filter(Q(message__icontains=query) | Q(extra__icontains=query))
else:
date = make_aware(date)
if is_naive(date):
date = make_aware(date)
if date.hour == 0 and date.minute == 0 and date.second == 0:
# just a date: display all events for that date
qs = qs.filter(timestamp__gte=date, timestamp__lte=date + datetime.timedelta(days=1))

View File

@ -195,6 +195,10 @@ def test_logs(app, admin_user):
resp = resp.form.submit()
assert resp.text.count('<td class="timestamp">') == 0
resp.form['q'] = 'Wed, 29 Sep 2021 00:40:48 +0200'
resp = resp.form.submit()
assert resp.text.count('<td class="timestamp">') == 0
resp.form['q'] = ''
resp = resp.form.submit()
assert resp.text.count('<td class="timestamp">') == 4