Add 'executed' to old batches grid view, make timestamps show "raw" by default.
This commit is contained in:
parent
a7b73021ac
commit
a22f50850f
|
@ -30,7 +30,7 @@ from .core import CustomFieldRenderer, DateFieldRenderer
|
||||||
|
|
||||||
from .common import (AutocompleteFieldRenderer,
|
from .common import (AutocompleteFieldRenderer,
|
||||||
DecimalFieldRenderer, CurrencyFieldRenderer,
|
DecimalFieldRenderer, CurrencyFieldRenderer,
|
||||||
DateTimeFieldRenderer,
|
DateTimeFieldRenderer, DateTimePrettyFieldRenderer,
|
||||||
EnumFieldRenderer, YesNoFieldRenderer)
|
EnumFieldRenderer, YesNoFieldRenderer)
|
||||||
|
|
||||||
from .people import (PersonFieldRenderer, PersonFieldLinkRenderer,
|
from .people import (PersonFieldRenderer, PersonFieldLinkRenderer,
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2014 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,13 +24,13 @@
|
||||||
Common Field Renderers
|
Common Field Renderers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy
|
||||||
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
|
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
|
||||||
from pyramid.renderers import render
|
from pyramid.renderers import render
|
||||||
|
|
||||||
from tailbone.util import pretty_datetime
|
from tailbone.util import pretty_datetime, raw_datetime
|
||||||
|
|
||||||
|
|
||||||
class AutocompleteFieldRenderer(FieldRenderer):
|
class AutocompleteFieldRenderer(FieldRenderer):
|
||||||
|
@ -77,6 +77,19 @@ class AutocompleteFieldRenderer(FieldRenderer):
|
||||||
|
|
||||||
|
|
||||||
class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer):
|
class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer):
|
||||||
|
"""
|
||||||
|
This renderer assumes the datetime field value is in UTC, and will convert
|
||||||
|
it to the local time zone before rendering it in the standard "raw" format.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def render_readonly(self, **kwargs):
|
||||||
|
value = self.raw_value
|
||||||
|
if not value:
|
||||||
|
return ''
|
||||||
|
return raw_datetime(self.request.rattail_config, value)
|
||||||
|
|
||||||
|
|
||||||
|
class DateTimePrettyFieldRenderer(formalchemy.DateTimeFieldRenderer):
|
||||||
"""
|
"""
|
||||||
Custom date/time field renderer, which displays a "pretty" value in
|
Custom date/time field renderer, which displays a "pretty" value in
|
||||||
read-only mode, leveraging config to show the correct timezone.
|
read-only mode, leveraging config to show the correct timezone.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2014 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
Utilities
|
Utilities
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
@ -64,3 +64,33 @@ def pretty_datetime(config, value):
|
||||||
return HTML.tag('span',
|
return HTML.tag('span',
|
||||||
title=value.strftime('%Y-%m-%d %H:%M:%S %Z%z'),
|
title=value.strftime('%Y-%m-%d %H:%M:%S %Z%z'),
|
||||||
c=humanize.naturaltime(time_ago))
|
c=humanize.naturaltime(time_ago))
|
||||||
|
|
||||||
|
|
||||||
|
def raw_datetime(config, value):
|
||||||
|
"""
|
||||||
|
Formats a datetime as a "raw" human-readable string, with a tooltip
|
||||||
|
showing the more human-friendly "time since" equivalent.
|
||||||
|
|
||||||
|
:param config: Reference to a config object.
|
||||||
|
|
||||||
|
:param value: A ``datetime.datetime`` instance. Note that if this instance
|
||||||
|
is not timezone-aware, its timezone is assumed to be UTC.
|
||||||
|
"""
|
||||||
|
if not value:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
# Make sure we're dealing with a tz-aware value. If we're given a naive
|
||||||
|
# value, we assume it to be local to the UTC timezone.
|
||||||
|
if not value.tzinfo:
|
||||||
|
value = pytz.utc.localize(value)
|
||||||
|
|
||||||
|
# Calculate time diff using UTC.
|
||||||
|
time_ago = datetime.datetime.utcnow() - make_utc(value)
|
||||||
|
|
||||||
|
# Convert value to local timezone.
|
||||||
|
local = timezone(config)
|
||||||
|
value = local.normalize(value.astimezone(local))
|
||||||
|
|
||||||
|
return HTML.tag('span',
|
||||||
|
title=humanize.naturaltime(time_ago),
|
||||||
|
c=value.strftime('%Y-%m-%d %I:%M:%S %p').lower())
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2014 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,14 +24,14 @@
|
||||||
Core Batch Views
|
Core Batch Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from pyramid.httpexceptions import HTTPFound
|
from pyramid.httpexceptions import HTTPFound
|
||||||
from pyramid.renderers import render_to_response
|
from pyramid.renderers import render_to_response
|
||||||
|
|
||||||
from webhelpers.html import tags
|
from webhelpers.html import tags
|
||||||
|
|
||||||
from tailbone.forms import EnumFieldRenderer
|
from tailbone import forms
|
||||||
from ...grids.search import BooleanSearchFilter
|
from ...grids.search import BooleanSearchFilter
|
||||||
from .. import SearchableAlchemyGridView, CrudView, View
|
from .. import SearchableAlchemyGridView, CrudView, View
|
||||||
from ...progress import SessionProgress
|
from ...progress import SessionProgress
|
||||||
|
@ -91,6 +91,7 @@ class BatchesGrid(SearchableAlchemyGridView):
|
||||||
g.id.label("ID"),
|
g.id.label("ID"),
|
||||||
g.destination,
|
g.destination,
|
||||||
g.description,
|
g.description,
|
||||||
|
g.executed,
|
||||||
g.rowcount.label("Row Count"),
|
g.rowcount.label("Row Count"),
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
@ -117,7 +118,7 @@ class BatchCrud(CrudView):
|
||||||
|
|
||||||
def fieldset(self, model):
|
def fieldset(self, model):
|
||||||
fs = self.make_fieldset(model)
|
fs = self.make_fieldset(model)
|
||||||
fs.action_type.set(renderer=EnumFieldRenderer(enum.BATCH_ACTION))
|
fs.action_type.set(renderer=forms.renderers.EnumFieldRenderer(enum.BATCH_ACTION))
|
||||||
fs.configure(
|
fs.configure(
|
||||||
include=[
|
include=[
|
||||||
fs.source,
|
fs.source,
|
||||||
|
|
Loading…
Reference in a new issue