Tweak how "duration" fields are rendered for grids, forms
This commit is contained in:
parent
a6d97538af
commit
4e3aa1af83
|
@ -27,7 +27,6 @@ Forms Core
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import datetime
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -36,7 +35,7 @@ from sqlalchemy import orm
|
||||||
from sqlalchemy.ext.associationproxy import AssociationProxy, ASSOCIATION_PROXY
|
from sqlalchemy.ext.associationproxy import AssociationProxy, ASSOCIATION_PROXY
|
||||||
|
|
||||||
from rattail.time import localtime
|
from rattail.time import localtime
|
||||||
from rattail.util import prettify, pretty_boolean, pretty_hours, pretty_quantity
|
from rattail.util import prettify, pretty_boolean, pretty_quantity
|
||||||
from rattail.core import UNSPECIFIED
|
from rattail.core import UNSPECIFIED
|
||||||
|
|
||||||
import colander
|
import colander
|
||||||
|
@ -902,10 +901,11 @@ class Form(object):
|
||||||
return raw_datetime(self.request.rattail_config, value)
|
return raw_datetime(self.request.rattail_config, value)
|
||||||
|
|
||||||
def render_duration(self, record, field_name):
|
def render_duration(self, record, field_name):
|
||||||
value = self.obtain_value(record, field_name)
|
seconds = self.obtain_value(record, field_name)
|
||||||
if value is None:
|
if seconds is None:
|
||||||
return ""
|
return ""
|
||||||
return pretty_hours(datetime.timedelta(seconds=value))
|
app = self.request.rattail_config.get_app()
|
||||||
|
return app.render_duration(seconds=seconds)
|
||||||
|
|
||||||
def render_boolean(self, record, field_name):
|
def render_boolean(self, record, field_name):
|
||||||
value = self.obtain_value(record, field_name)
|
value = self.obtain_value(record, field_name)
|
||||||
|
|
|
@ -26,7 +26,6 @@ Core Grid Classes
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import datetime
|
|
||||||
import warnings
|
import warnings
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -358,10 +357,11 @@ class Grid(object):
|
||||||
return pretty_quantity(value)
|
return pretty_quantity(value)
|
||||||
|
|
||||||
def render_duration(self, obj, column_name):
|
def render_duration(self, obj, column_name):
|
||||||
value = self.obtain_value(obj, column_name)
|
seconds = self.obtain_value(obj, column_name)
|
||||||
if value is None:
|
if seconds is None:
|
||||||
return ""
|
return ""
|
||||||
return pretty_hours(datetime.timedelta(seconds=value))
|
app = self.request.rattail_config.get_app()
|
||||||
|
return app.render_duration(seconds=seconds)
|
||||||
|
|
||||||
def render_duration_hours(self, obj, field):
|
def render_duration_hours(self, obj, field):
|
||||||
value = self.obtain_value(obj, field)
|
value = self.obtain_value(obj, field)
|
||||||
|
|
Loading…
Reference in a new issue