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