Make our DateTimeFieldRenderer the default for datetime fields.

This commit is contained in:
Lance Edgar 2016-02-14 16:34:39 -06:00
parent e10b956bf7
commit a341acb4f0
8 changed files with 9 additions and 28 deletions

View file

@ -136,9 +136,7 @@ def make_pyramid_config(settings):
formalchemy.config.engine = TemplateEngine()
formalchemy.FieldSet.default_renderers[sa.Boolean] = renderers.YesNoFieldRenderer
formalchemy.FieldSet.default_renderers[sa.Date] = renderers.DateFieldRenderer
# TODO: Maybe implement our own some day, but for now we must include this
# DateTime fix to work around a bug in edbob code.
formalchemy.FieldSet.default_renderers[sa.DateTime] = formalchemy.DateTimeFieldRenderer
formalchemy.FieldSet.default_renderers[sa.DateTime] = renderers.DateTimeFieldRenderer
formalchemy.FieldSet.default_renderers[GPCType] = renderers.GPCFieldRenderer
return config

View file

@ -82,18 +82,11 @@ class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer):
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):
value = self.raw_value
if not value:
return ''
return pretty_datetime(self.config, value)
return pretty_datetime(self.request.rattail_config, value)
class EnumFieldRenderer(SelectFieldRenderer):

View file

@ -31,7 +31,7 @@ from pyramid.renderers import render_to_response
from webhelpers.html import tags
from tailbone.forms import DateTimeFieldRenderer, EnumFieldRenderer
from tailbone.forms import EnumFieldRenderer
from ...grids.search import BooleanSearchFilter
from .. import SearchableAlchemyGridView, CrudView, View
from ...progress import SessionProgress
@ -92,7 +92,6 @@ class BatchesGrid(SearchableAlchemyGridView):
g.destination,
g.description,
g.rowcount.label("Row Count"),
g.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)),
],
readonly=True)
if self.request.has_perm('batches.read'):
@ -127,7 +126,7 @@ class BatchCrud(CrudView):
fs.action_type,
fs.description,
fs.rowcount.label("Row Count").readonly(),
fs.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)).readonly(),
fs.executed.readonly(),
])
return fs

View file

@ -104,7 +104,6 @@ class EmailBouncesGrid(SearchableAlchemyGridView):
def grid(self):
g = self.make_grid()
g.bounced.set(renderer=renderers.DateTimeFieldRenderer(self.rattail_config))
g.configure(
include=[
g.config_key.label("Source"),
@ -152,8 +151,6 @@ class EmailBounceCrud(CrudView):
assert isinstance(bounce, model.EmailBounce)
handler = self.get_handler(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',
value=handler.msgpath(bounce),
renderer=BounceMessageFieldRenderer.new(self.request, handler)))

View file

@ -37,7 +37,6 @@ from pyramid.httpexceptions import HTTPNotFound
from tailbone.db import Session
from tailbone.views import PagedAlchemyGridView, View
from tailbone.forms import DateTimeFieldRenderer
class VersionView(PagedAlchemyGridView):
@ -125,7 +124,6 @@ class VersionView(PagedAlchemyGridView):
def grid(self):
g = self.make_grid()
g.issued_at.set(renderer=DateTimeFieldRenderer(self.request.rattail_config))
g.configure(
include=[
g.issued_at.label("When"),

View file

@ -32,7 +32,6 @@ import logging
from rattail.db import model
from rattail.config import parse_list
from tailbone import forms
from tailbone.views import MasterView
@ -55,7 +54,6 @@ class DataSyncChangeView(MasterView):
def configure_grid(self, g):
g.default_sortkey = 'obtained'
g.obtained.set(renderer=forms.DateTimeFieldRenderer(self.rattail_config))
g.configure(
include=[
g.source,

View file

@ -176,7 +176,7 @@ class MessagesView(MasterView):
g.subject.with_renderer(SubjectFieldRenderer),
g.sender.with_renderer(SenderFieldRenderer).label("From"),
g.recipients.with_renderer(TerseRecipientsFieldRenderer).label("To"),
g.sent.with_renderer(forms.renderers.DateTimeFieldRenderer(self.rattail_config)),
g.sent,
],
readonly=True)
@ -256,7 +256,7 @@ class MessagesView(MasterView):
fs.configure(include=[
fs.sender.with_renderer(SenderFieldRenderer).label("From"),
fs.recipients.with_renderer(RecipientsFieldRenderer).label("To"),
fs.sent.with_renderer(forms.renderers.DateTimeFieldRenderer(self.rattail_config)),
fs.sent,
fs.subject,
])

View file

@ -38,7 +38,7 @@ from rattail.gpc import GPC
from rattail.threads import Thread
from rattail.exceptions import LabelPrintingError
import formalchemy
import formalchemy as fa
from pyramid import httpexceptions
from pyramid.renderers import render_to_response
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.regular_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',
value=lambda p: p.current_price.ends if p.current_price else None,
renderer=forms.renderers.DateTimeFieldRenderer(self.rattail_config)))
fs.append(fa.Field('current_price_ends', type=fa.types.DateTime,
value=lambda p: p.current_price.ends if p.current_price else None))
fs.configure(
include=[