Add 'duration_hours' type for grid column display

This commit is contained in:
Lance Edgar 2019-07-01 11:46:21 -05:00
parent b14e8daa1a
commit ff3ee351d1

View file

@ -225,6 +225,8 @@ class Grid(object):
self.set_renderer(key, self.render_quantity)
elif type_ == 'duration':
self.set_renderer(key, self.render_duration)
elif type_ == 'duration_hours':
self.set_renderer(key, self.render_duration_hours)
else:
raise ValueError("Unsupported type for column '{}': {}".format(key, type_))
@ -302,6 +304,12 @@ class Grid(object):
return ""
return pretty_hours(datetime.timedelta(seconds=value))
def render_duration_hours(self, obj, field):
value = self.obtain_value(obj, field)
if value is None:
return ""
return pretty_hours(hours=value)
def set_url(self, url):
self.url = url