From 62815930846b183d82e46ea577157e570ca766d5 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 10 Oct 2017 13:58:52 -0700 Subject: [PATCH] Add "local" datetime renderer for new grids, forms --- tailbone/forms2/core.py | 10 ++++++++++ tailbone/grids/core.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/tailbone/forms2/core.py b/tailbone/forms2/core.py index 48e36ad6..c1cf9782 100644 --- a/tailbone/forms2/core.py +++ b/tailbone/forms2/core.py @@ -34,6 +34,7 @@ import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.ext.associationproxy import AssociationProxy, ASSOCIATION_PROXY +from rattail.time import localtime from rattail.util import prettify, pretty_boolean, pretty_hours import colander @@ -287,6 +288,8 @@ class Form(object): def set_type(self, key, type_): if type_ == 'datetime': self.set_renderer(key, self.render_datetime) + elif type_ == 'datetime_local': + self.set_renderer(key, self.render_datetime_local) elif type_ == 'duration': self.set_renderer(key, self.render_duration) elif type_ == 'boolean': @@ -401,6 +404,13 @@ class Form(object): return "" return raw_datetime(self.request.rattail_config, value) + def render_datetime_local(self, record, field_name): + value = self.obtain_value(record, field_name) + if value is None: + return "" + value = localtime(self.request.rattail_config, value) + return raw_datetime(self.request.rattail_config, value) + def render_duration(self, record, field_name): value = self.obtain_value(record, field_name) if value is None: diff --git a/tailbone/grids/core.py b/tailbone/grids/core.py index 00aab543..63ea83bd 100644 --- a/tailbone/grids/core.py +++ b/tailbone/grids/core.py @@ -36,6 +36,7 @@ from sqlalchemy import orm from rattail.db import api from rattail.db.types import GPCType from rattail.util import prettify, pretty_boolean, pretty_quantity, pretty_hours +from rattail.time import localtime import webhelpers2_grid from pyramid.renderers import render @@ -142,6 +143,8 @@ class Grid(object): self.set_renderer(key, self.render_currency) elif type_ == 'datetime': self.set_renderer(key, self.render_datetime) + elif type_ == 'datetime_local': + self.set_renderer(key, self.render_datetime_local) elif type_ == 'enum': self.set_renderer(key, self.render_enum) elif type_ == 'gpc': @@ -189,6 +192,13 @@ class Grid(object): return "" return raw_datetime(self.request.rattail_config, value) + def render_datetime_local(self, obj, column_name): + value = self.obtain_value(obj, column_name) + if value is None: + return "" + value = localtime(self.request.rattail_config, value) + return raw_datetime(self.request.rattail_config, value) + def render_enum(self, obj, column_name): value = self.obtain_value(obj, column_name) if value is None: