From 178b9f2bcbcfd92dcf6afee966a69ab2892a7b38 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 16 Aug 2017 18:32:17 -0500 Subject: [PATCH] Add `LocalDateTimeFieldRenderer` for formalchemy --- tailbone/forms/renderers/__init__.py | 4 ++-- tailbone/forms/renderers/common.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tailbone/forms/renderers/__init__.py b/tailbone/forms/renderers/__init__.py index 4fbcc68d..b0f30233 100644 --- a/tailbone/forms/renderers/__init__.py +++ b/tailbone/forms/renderers/__init__.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework @@ -30,7 +30,7 @@ from .core import CustomFieldRenderer, DateFieldRenderer from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer, DecimalFieldRenderer, CurrencyFieldRenderer, QuantityFieldRenderer, - DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer, + DateTimeFieldRenderer, DateTimePrettyFieldRenderer, LocalDateTimeFieldRenderer, TimeFieldRenderer, EmailFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer) from .files import FileFieldRenderer diff --git a/tailbone/forms/renderers/common.py b/tailbone/forms/renderers/common.py index 6c42a4ab..e1468e08 100644 --- a/tailbone/forms/renderers/common.py +++ b/tailbone/forms/renderers/common.py @@ -156,6 +156,19 @@ class DateTimePrettyFieldRenderer(fa.DateTimeFieldRenderer): return pretty_datetime(self.request.rattail_config, value) +class LocalDateTimeFieldRenderer(fa.DateTimeFieldRenderer): + """ + This renderer assumes the datetime field value is "naive" in local time zone. + """ + + def render_readonly(self, **kwargs): + value = self.raw_value + if not value: + return '' + value = localtime(self.request.rattail_config, value) + return raw_datetime(self.request.rattail_config, value) + + class TimeFieldRenderer(fa.TimeFieldRenderer): """ Custom renderer for time fields. In edit mode, renders a simple text