From a2af2162f9df2bd61d562307293559262638287a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madis=20M=C3=A4gi?= Date: Mon, 14 Aug 2023 00:44:37 +0300 Subject: [PATCH] Handle naive vs utc aware datetime --- inventory-app/doorboy.py | 17 ++++++++++++----- requirements.txt | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/inventory-app/doorboy.py b/inventory-app/doorboy.py index 56a38bd..ce54717 100644 --- a/inventory-app/doorboy.py +++ b/inventory-app/doorboy.py @@ -8,6 +8,7 @@ from pymongo import MongoClient from wtforms import StringField, IntegerField, SelectField, BooleanField, DateTimeField, validators from wtforms.validators import DataRequired +import pytz import const from common import spam, users_lookup, users, User from oidc import login_required, read_user @@ -226,17 +227,23 @@ def view_doorboy_admin(): def datetime_handle(item): if not item: - return datetime.min + dt = datetime.min elif type(item) is str: try: - return parse(item) + dt = parse(item) except ParserError as e: print(e) - return datetime.min + dt = datetime.min elif type(item) is datetime: - return item + dt = item else: - return datetime.min + dt = datetime.min + + try: + dt = pytz.UTC.localize(dt) + except ValueError: + pass + return dt @page_doorboy.route("/m/doorboy/swipes") @login_required diff --git a/requirements.txt b/requirements.txt index 2bd3f1b..bfcb846 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Flask jinja2 jpegtran-cffi markdown +pytz requests safe sepa