diff --git a/ChatServiceApp/funcs.py b/ChatServiceApp/funcs.py index ea5c475..40f578f 100644 --- a/ChatServiceApp/funcs.py +++ b/ChatServiceApp/funcs.py @@ -288,6 +288,9 @@ def send_msg(data): def get_chat_page_content_html(request, receiver_id=None): from AuthApp.models import User + from django.utils import timezone + + now = timezone.now() msgs = [] try: diff --git a/GeneralApp/tz_middelware.py b/GeneralApp/tz_middelware.py new file mode 100644 index 0000000..0f6c539 --- /dev/null +++ b/GeneralApp/tz_middelware.py @@ -0,0 +1,15 @@ +import pytz + +from django.utils import timezone + +class TimezoneMiddleware: + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + tzname = request.session.get('django_timezone') + if tzname: + timezone.activate(pytz.timezone(tzname)) + else: + timezone.deactivate() + return self.get_response(request) \ No newline at end of file diff --git a/TWB/settings.py b/TWB/settings.py index 5e3738b..fb86856 100644 --- a/TWB/settings.py +++ b/TWB/settings.py @@ -126,6 +126,7 @@ MIDDLEWARE = [ 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'AuthApp.middleware.ResponseInterceptionMiddleware', + 'GeneralApp.tz_middelware.TimezoneMiddleware', "allauth.account.middleware.AccountMiddleware", ] @@ -220,11 +221,11 @@ TIME_ZONE = 'Europe/Minsk' USE_I18N = True -# USE_TZ = True +USE_TZ = True USE_L10N = True -USE_TZ = False +# USE_TZ = False # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/4.2/howto/static-files/