Grid FORMATTERS_BY_TYPE seems relatively useless thanks to get_default_represent?

33 views
Skip to first unread message

laundmo

unread,
Aug 15, 2025, 10:34:57 AMAug 15
to py4web
In Grid, FORMATTERS_BY_TYPE does some formatting like turning bools into unicode checkboxes. 
But this never actually happens because col.represent(value, row) is always called beforehand, and that, by default, just does str(value).
And then of Grid.FORMATTERS_BY_TYPE tries to rely on the python type, which is now 'str' instead of 'bool'.

I could work around this by setting represent: lambda value, row=None: value for each bool field, but at that point I could just put the unicode checkbox code there.

Unless i'm missing something, this obviates Grid.FORMATTERS_BY_TYPE entirely. 

A better and more global approach would be to have a way to influence what the default represent for a specific pydal type is. The issue is that this has to be set and finished before DAL definitions, otherwise it won't apply since the represent is set in Field.__init__

Does anyone (mainly Massimo) have any idea how to best resolve this? Setting the represent for each boolean field is technically plausible in my specific project since i already post-process the DAL definitions a lot, but its far from ideal.

Massimo

unread,
Aug 24, 2025, 5:04:00 PM (14 days ago) Aug 24
to py4web
Yes this broke when fields in pydal were given all a default represent function.
I think we should just deprecate FORMATTERS_BY_TYPE.
Do we really want need the checkboxes?

United Ranker

unread,
Aug 25, 2025, 5:29:46 PM (13 days ago) Aug 25
to py4web
Reply all
Reply to author
Forward
0 new messages