From f961110a7cad2f0df7a9f73613e0173dde20370a Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Wed, 12 Jun 2019 16:57:09 +0200 Subject: [PATCH] FIX: some localtime issues. --- dav_events/models/eventflag.py | 2 +- dav_events/models/oneclickaction.py | 2 +- dav_registration/models.py | 4 ++-- dav_registration/tests/test_emails.py | 13 +++++++++---- dav_submission/views.py | 7 ++++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/dav_events/models/eventflag.py b/dav_events/models/eventflag.py index bbb842a..2fe4976 100644 --- a/dav_events/models/eventflag.py +++ b/dav_events/models/eventflag.py @@ -30,5 +30,5 @@ class EventFlag(models.Model): s = '{status} - {timestamp}' if self.user: s += ' by user {user}' - return s.format(status=self.status, timestamp=self.timestamp.strftime('%d.%m.%Y %H:%M:%S'), + return s.format(status=self.status, timestamp=self.timestamp.strftime('%d.%m.%Y %H:%M:%S %Z'), user=self.user) diff --git a/dav_events/models/oneclickaction.py b/dav_events/models/oneclickaction.py index f7b883a..336babc 100644 --- a/dav_events/models/oneclickaction.py +++ b/dav_events/models/oneclickaction.py @@ -85,7 +85,7 @@ class OneClickAction(models.Model): ' von %(user)s' ' auf \'%(status)s\' gesetzt.') % { 'status': flag.status.label, - 'date': flag.timestamp.strftime('%d.%m.%Y %H:%M:%S'), + 'date': timezone.localtime(flag.timestamp).strftime('%d.%m.%Y %H:%M:%S'), 'user': flag.user.get_full_name(), }) else: diff --git a/dav_registration/models.py b/dav_registration/models.py index 6ddd8c5..a1c7e64 100644 --- a/dav_registration/models.py +++ b/dav_registration/models.py @@ -95,8 +95,8 @@ class Registration(models.Model): eventnumber=self.event.get_number(), name=self.get_full_name(), registration_id=self.hexstr, - created=self.created_at.strftime('%d.%m.%Y %H:%M'), - purge=self.purge_at.strftime('%d.%m.%Y %H:%M') + created=self.created_at.strftime('%d.%m.%Y %H:%M %Z'), + purge=self.purge_at.strftime('%d.%m.%Y %H:%M %Z') ) def get_absolute_url(self): diff --git a/dav_registration/tests/test_emails.py b/dav_registration/tests/test_emails.py index f8b7eed..75012f3 100644 --- a/dav_registration/tests/test_emails.py +++ b/dav_registration/tests/test_emails.py @@ -4,6 +4,7 @@ from babel.dates import format_datetime from django.apps import apps from django.core import mail as django_mail from django.test import TestCase +from django.utils import timezone from django.utils.translation import get_language from dav_base.tests.generic import EmailTestMixin @@ -131,8 +132,10 @@ class EmailsTestCase(EmailTestMixin, EventMixin, RegistrationMixin, TestCase): trainer_full_name=trainer.get_full_name(), trainer_first_name=trainer.first_name, registration_hexstr=registration.hexstr, - registration_at=format_datetime(registration.created_at, 'EEEE, dd. MMMM yyyy, H:mm', locale=locale), - purge_at=format_datetime(registration.purge_at, 'EEEE, dd. MMMM yyyy', locale=locale), + registration_at=format_datetime(timezone.localtime(registration.created_at), + 'EEEE, dd. MMMM yyyy, H:mm', locale=locale), + purge_at=format_datetime(timezone.localtime(registration.purge_at), + 'EEEE, dd. MMMM yyyy', locale=locale), ) self.assertBody(mail, body) @@ -226,8 +229,10 @@ class EmailsTestCase(EmailTestMixin, EventMixin, RegistrationMixin, TestCase): event_formated_date=event.get_formated_date(), trainer_first_name=trainer.first_name, registration_hexstr=registration.hexstr, - registration_at=format_datetime(registration.created_at, 'EEEE, dd. MMMM yyyy, H:mm', locale=locale), - purge_at=format_datetime(registration.purge_at, 'EEEE, dd. MMMM yyyy', locale=locale), + registration_at=format_datetime(timezone.localtime(registration.created_at), + 'EEEE, dd. MMMM yyyy, H:mm', locale=locale), + purge_at=format_datetime(timezone.localtime(registration.purge_at), + 'EEEE, dd. MMMM yyyy', locale=locale), ) self.assertBody(mail, body) diff --git a/dav_submission/views.py b/dav_submission/views.py index d74077b..9cef100 100644 --- a/dav_submission/views.py +++ b/dav_submission/views.py @@ -7,6 +7,7 @@ from django.apps import apps from django.contrib import messages from django.core.exceptions import PermissionDenied from django.urls import reverse_lazy +from django.utils import timezone from django.utils.translation import ugettext as _ from django.views import generic @@ -68,7 +69,7 @@ class UploadView(generic.edit.FormView): base_path = app_config.settings.upload_path subdir_format_str = u'{datetime}--{title}' - now = datetime.datetime.now() + now = timezone.now() subdir_format_kwargs = {'datetime': now.strftime('%Y-%m-%d--%H%M%S'), 'date': now.strftime('%Y-%m-%d'), 'time': now.strftime('%H-%M-%S'), @@ -95,8 +96,8 @@ Beschreibung: {description} """ metadata_format_kwargs = { - 'date': now.strftime('%d.%m.%Y'), - 'time': now.strftime('%H:%M:%S'), + 'date': timezone.localtime(now).strftime('%d.%m.%Y'), + 'time': timezone.localtime(now).strftime('%H:%M:%S %Z'), 'name': form.cleaned_data['name'], 'email_address': form.cleaned_data['email_address'], 'group': form.cleaned_data['group'],