Add LocalDateTimeFieldRenderer for formalchemy

This commit is contained in:
Lance Edgar 2017-08-16 18:32:17 -05:00
parent d83990bb58
commit 178b9f2bcb
2 changed files with 15 additions and 2 deletions

View file

@ -1,4 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8; -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
@ -30,7 +30,7 @@ from .core import CustomFieldRenderer, DateFieldRenderer
from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer, from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, AutocompleteFieldRenderer,
DecimalFieldRenderer, CurrencyFieldRenderer, QuantityFieldRenderer, DecimalFieldRenderer, CurrencyFieldRenderer, QuantityFieldRenderer,
DateTimeFieldRenderer, DateTimePrettyFieldRenderer, TimeFieldRenderer, DateTimeFieldRenderer, DateTimePrettyFieldRenderer, LocalDateTimeFieldRenderer, TimeFieldRenderer,
EmailFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer) EmailFieldRenderer, EnumFieldRenderer, YesNoFieldRenderer)
from .files import FileFieldRenderer from .files import FileFieldRenderer

View file

@ -156,6 +156,19 @@ class DateTimePrettyFieldRenderer(fa.DateTimeFieldRenderer):
return pretty_datetime(self.request.rattail_config, value) 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): class TimeFieldRenderer(fa.TimeFieldRenderer):
""" """
Custom renderer for time fields. In edit mode, renders a simple text Custom renderer for time fields. In edit mode, renders a simple text