Make our DateTimeFieldRenderer
the default for datetime fields.
This commit is contained in:
parent
e10b956bf7
commit
a341acb4f0
|
@ -136,9 +136,7 @@ def make_pyramid_config(settings):
|
||||||
formalchemy.config.engine = TemplateEngine()
|
formalchemy.config.engine = TemplateEngine()
|
||||||
formalchemy.FieldSet.default_renderers[sa.Boolean] = renderers.YesNoFieldRenderer
|
formalchemy.FieldSet.default_renderers[sa.Boolean] = renderers.YesNoFieldRenderer
|
||||||
formalchemy.FieldSet.default_renderers[sa.Date] = renderers.DateFieldRenderer
|
formalchemy.FieldSet.default_renderers[sa.Date] = renderers.DateFieldRenderer
|
||||||
# TODO: Maybe implement our own some day, but for now we must include this
|
formalchemy.FieldSet.default_renderers[sa.DateTime] = renderers.DateTimeFieldRenderer
|
||||||
# DateTime fix to work around a bug in edbob code.
|
|
||||||
formalchemy.FieldSet.default_renderers[sa.DateTime] = formalchemy.DateTimeFieldRenderer
|
|
||||||
formalchemy.FieldSet.default_renderers[GPCType] = renderers.GPCFieldRenderer
|
formalchemy.FieldSet.default_renderers[GPCType] = renderers.GPCFieldRenderer
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -82,18 +82,11 @@ class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer):
|
||||||
read-only mode, leveraging config to show the correct timezone.
|
read-only mode, leveraging config to show the correct timezone.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config):
|
|
||||||
self.config = config
|
|
||||||
|
|
||||||
def __call__(self, field):
|
|
||||||
super(DateTimeFieldRenderer, self).__init__(field)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def render_readonly(self, **kwargs):
|
def render_readonly(self, **kwargs):
|
||||||
value = self.raw_value
|
value = self.raw_value
|
||||||
if not value:
|
if not value:
|
||||||
return ''
|
return ''
|
||||||
return pretty_datetime(self.config, value)
|
return pretty_datetime(self.request.rattail_config, value)
|
||||||
|
|
||||||
|
|
||||||
class EnumFieldRenderer(SelectFieldRenderer):
|
class EnumFieldRenderer(SelectFieldRenderer):
|
||||||
|
|
|
@ -31,7 +31,7 @@ from pyramid.renderers import render_to_response
|
||||||
|
|
||||||
from webhelpers.html import tags
|
from webhelpers.html import tags
|
||||||
|
|
||||||
from tailbone.forms import DateTimeFieldRenderer, EnumFieldRenderer
|
from tailbone.forms import EnumFieldRenderer
|
||||||
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
|
||||||
|
@ -92,7 +92,6 @@ class BatchesGrid(SearchableAlchemyGridView):
|
||||||
g.destination,
|
g.destination,
|
||||||
g.description,
|
g.description,
|
||||||
g.rowcount.label("Row Count"),
|
g.rowcount.label("Row Count"),
|
||||||
g.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)),
|
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
if self.request.has_perm('batches.read'):
|
if self.request.has_perm('batches.read'):
|
||||||
|
@ -127,7 +126,7 @@ class BatchCrud(CrudView):
|
||||||
fs.action_type,
|
fs.action_type,
|
||||||
fs.description,
|
fs.description,
|
||||||
fs.rowcount.label("Row Count").readonly(),
|
fs.rowcount.label("Row Count").readonly(),
|
||||||
fs.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)).readonly(),
|
fs.executed.readonly(),
|
||||||
])
|
])
|
||||||
return fs
|
return fs
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,6 @@ class EmailBouncesGrid(SearchableAlchemyGridView):
|
||||||
|
|
||||||
def grid(self):
|
def grid(self):
|
||||||
g = self.make_grid()
|
g = self.make_grid()
|
||||||
g.bounced.set(renderer=renderers.DateTimeFieldRenderer(self.rattail_config))
|
|
||||||
g.configure(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.config_key.label("Source"),
|
g.config_key.label("Source"),
|
||||||
|
@ -152,8 +151,6 @@ class EmailBounceCrud(CrudView):
|
||||||
assert isinstance(bounce, model.EmailBounce)
|
assert isinstance(bounce, model.EmailBounce)
|
||||||
handler = self.get_handler(bounce)
|
handler = self.get_handler(bounce)
|
||||||
fs = self.make_fieldset(bounce)
|
fs = self.make_fieldset(bounce)
|
||||||
fs.bounced.set(renderer=renderers.DateTimeFieldRenderer(self.rattail_config))
|
|
||||||
fs.processed.set(renderer=renderers.DateTimeFieldRenderer(self.rattail_config))
|
|
||||||
fs.append(formalchemy.Field('message',
|
fs.append(formalchemy.Field('message',
|
||||||
value=handler.msgpath(bounce),
|
value=handler.msgpath(bounce),
|
||||||
renderer=BounceMessageFieldRenderer.new(self.request, handler)))
|
renderer=BounceMessageFieldRenderer.new(self.request, handler)))
|
||||||
|
|
|
@ -37,7 +37,6 @@ from pyramid.httpexceptions import HTTPNotFound
|
||||||
|
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views import PagedAlchemyGridView, View
|
from tailbone.views import PagedAlchemyGridView, View
|
||||||
from tailbone.forms import DateTimeFieldRenderer
|
|
||||||
|
|
||||||
|
|
||||||
class VersionView(PagedAlchemyGridView):
|
class VersionView(PagedAlchemyGridView):
|
||||||
|
@ -125,7 +124,6 @@ class VersionView(PagedAlchemyGridView):
|
||||||
|
|
||||||
def grid(self):
|
def grid(self):
|
||||||
g = self.make_grid()
|
g = self.make_grid()
|
||||||
g.issued_at.set(renderer=DateTimeFieldRenderer(self.request.rattail_config))
|
|
||||||
g.configure(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.issued_at.label("When"),
|
g.issued_at.label("When"),
|
||||||
|
|
|
@ -32,7 +32,6 @@ import logging
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
from rattail.config import parse_list
|
from rattail.config import parse_list
|
||||||
|
|
||||||
from tailbone import forms
|
|
||||||
from tailbone.views import MasterView
|
from tailbone.views import MasterView
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,7 +54,6 @@ class DataSyncChangeView(MasterView):
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
g.default_sortkey = 'obtained'
|
g.default_sortkey = 'obtained'
|
||||||
g.obtained.set(renderer=forms.DateTimeFieldRenderer(self.rattail_config))
|
|
||||||
g.configure(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.source,
|
g.source,
|
||||||
|
|
|
@ -176,7 +176,7 @@ class MessagesView(MasterView):
|
||||||
g.subject.with_renderer(SubjectFieldRenderer),
|
g.subject.with_renderer(SubjectFieldRenderer),
|
||||||
g.sender.with_renderer(SenderFieldRenderer).label("From"),
|
g.sender.with_renderer(SenderFieldRenderer).label("From"),
|
||||||
g.recipients.with_renderer(TerseRecipientsFieldRenderer).label("To"),
|
g.recipients.with_renderer(TerseRecipientsFieldRenderer).label("To"),
|
||||||
g.sent.with_renderer(forms.renderers.DateTimeFieldRenderer(self.rattail_config)),
|
g.sent,
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ class MessagesView(MasterView):
|
||||||
fs.configure(include=[
|
fs.configure(include=[
|
||||||
fs.sender.with_renderer(SenderFieldRenderer).label("From"),
|
fs.sender.with_renderer(SenderFieldRenderer).label("From"),
|
||||||
fs.recipients.with_renderer(RecipientsFieldRenderer).label("To"),
|
fs.recipients.with_renderer(RecipientsFieldRenderer).label("To"),
|
||||||
fs.sent.with_renderer(forms.renderers.DateTimeFieldRenderer(self.rattail_config)),
|
fs.sent,
|
||||||
fs.subject,
|
fs.subject,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ from rattail.gpc import GPC
|
||||||
from rattail.threads import Thread
|
from rattail.threads import Thread
|
||||||
from rattail.exceptions import LabelPrintingError
|
from rattail.exceptions import LabelPrintingError
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy as fa
|
||||||
from pyramid import httpexceptions
|
from pyramid import httpexceptions
|
||||||
from pyramid.renderers import render_to_response
|
from pyramid.renderers import render_to_response
|
||||||
from webhelpers.html import tags
|
from webhelpers.html import tags
|
||||||
|
@ -227,11 +227,9 @@ class ProductsView(MasterView):
|
||||||
fs.unit_of_measure.set(renderer=forms.renderers.EnumFieldRenderer(enum.UNIT_OF_MEASURE))
|
fs.unit_of_measure.set(renderer=forms.renderers.EnumFieldRenderer(enum.UNIT_OF_MEASURE))
|
||||||
fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
||||||
fs.current_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
fs.current_price.set(renderer=forms.renderers.PriceFieldRenderer)
|
||||||
fs.last_sold.set(renderer=forms.renderers.DateTimeFieldRenderer(self.rattail_config))
|
|
||||||
|
|
||||||
fs.append(formalchemy.Field('current_price_ends',
|
fs.append(fa.Field('current_price_ends', type=fa.types.DateTime,
|
||||||
value=lambda p: p.current_price.ends if p.current_price else None,
|
value=lambda p: p.current_price.ends if p.current_price else None))
|
||||||
renderer=forms.renderers.DateTimeFieldRenderer(self.rattail_config)))
|
|
||||||
|
|
||||||
fs.configure(
|
fs.configure(
|
||||||
include=[
|
include=[
|
||||||
|
|
Loading…
Reference in a new issue