Convert all datetime values to localtime, for "download rows as CSV"

this probably will need to be more flexible at some point; this works for now
This commit is contained in:
Lance Edgar 2019-01-15 15:49:54 -06:00
parent 4413a61513
commit 8945dd75aa

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2019 Lance Edgar
#
# This file is part of Rattail.
#
@ -27,6 +27,7 @@ Model Master View
from __future__ import unicode_literals, absolute_import
import os
import datetime
import tempfile
import logging
@ -2345,6 +2346,9 @@ class MasterView(View):
csvrow = {}
for field in fields:
value = getattr(obj, field, None)
if isinstance(value, datetime.datetime):
# TODO: this assumes value is *always* naive UTC
value = localtime(self.rattail_config, value, from_utc=True)
csvrow[field] = '' if value is None else six.text_type(value)
return csvrow
@ -2355,6 +2359,9 @@ class MasterView(View):
csvrow = {}
for field in fields:
value = getattr(row, field, None)
if isinstance(value, datetime.datetime):
# TODO: this assumes value is *always* naive UTC
value = localtime(self.rattail_config, value, from_utc=True)
csvrow[field] = '' if value is None else six.text_type(value)
return csvrow