From 84ed3cfb40a64e64ddc32cc0df943cb12e198717 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 27 Mar 2025 14:47:12 +0100 Subject: ♻️ django: fix warnings for v5 - migrate to timezone aware dates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 5dcfc119c..baaa25c95 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -70,6 +70,7 @@ from django.db.models import Q from django.db.models.functions import Length from django.http import HttpResponseRedirect from django.urls import re_path, reverse, NoReverseMatch +from django.utils import timezone from django.utils.crypto import get_random_string from django.utils.datastructures import MultiValueDict as BaseMultiValueDict from django.utils.formats import date_format @@ -937,7 +938,7 @@ def get_file_from_link(file_link): def get_current_year(): - return datetime.datetime.now().year + return datetime.date.today().year def get_cache(cls, extra_args=tuple(), app_label=None): @@ -2378,7 +2379,7 @@ def m2m_historization_changed(sender, **kwargs): if q.count(): hist = q.all()[0] hist.history_m2m = hist_values - hist.history_date = hist.last_modified = datetime.datetime.now() + hist.history_date = hist.last_modified = timezone.now() hist.save() obj.skip_history_when_saving = True elif not obj.history_modifier: @@ -2959,7 +2960,7 @@ def duplicate_item(item, user=None, data=None): def get_image_path(instance, filename): # when using migrations instance is not a real ImageModel instance if not hasattr(instance, "_get_image_path"): - n = datetime.datetime.now() + n = datetime.date.today() return "upload/{}/{:02d}/{:02d}/{}".format(n.year, n.month, n.day, filename) return instance._get_image_path(filename) -- cgit v1.2.3