Add "local" datetime renderer for new grids, forms
This commit is contained in:
parent
791f3beffc
commit
6281593084
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue