Handle naive vs utc aware datetime
All checks were successful
ci/woodpecker/manual/woodpecker Pipeline was successful

This commit is contained in:
Madis Mägi 2023-08-14 00:44:37 +03:00
parent e4358590c3
commit a2af2162f9
2 changed files with 13 additions and 5 deletions

View File

@ -8,6 +8,7 @@ from pymongo import MongoClient
from wtforms import StringField, IntegerField, SelectField, BooleanField, DateTimeField, validators from wtforms import StringField, IntegerField, SelectField, BooleanField, DateTimeField, validators
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
import pytz
import const import const
from common import spam, users_lookup, users, User from common import spam, users_lookup, users, User
from oidc import login_required, read_user from oidc import login_required, read_user
@ -226,17 +227,23 @@ def view_doorboy_admin():
def datetime_handle(item): def datetime_handle(item):
if not item: if not item:
return datetime.min dt = datetime.min
elif type(item) is str: elif type(item) is str:
try: try:
return parse(item) dt = parse(item)
except ParserError as e: except ParserError as e:
print(e) print(e)
return datetime.min dt = datetime.min
elif type(item) is datetime: elif type(item) is datetime:
return item dt = item
else: else:
return datetime.min dt = datetime.min
try:
dt = pytz.UTC.localize(dt)
except ValueError:
pass
return dt
@page_doorboy.route("/m/doorboy/swipes") @page_doorboy.route("/m/doorboy/swipes")
@login_required @login_required

View File

@ -7,6 +7,7 @@ Flask
jinja2 jinja2
jpegtran-cffi jpegtran-cffi
markdown markdown
pytz
requests requests
safe safe
sepa sepa