sqlform.grid maxtextlengths shoots blanks

118 views
Skip to first unread message

jackso...@quantachrome.com

unread,
Jun 12, 2015, 12:27:27 AM6/12/15
to web...@googlegroups.com
I get the same truncated display for the log message text no matter what I set maxtextlengths...This app is rock+1 on the IQ simplicity scale and yet it does not work...BTW: I removed all layouts stuff so its not some css problem. The truncated fields are what the grid wants to display. Its like the grid is on autopilot, any suggestions???

MODEL:

db2 = DAL('sqlite://autoflowLog.sqlite')
db2.define_table('log_messages',
    Field('time_stamp', length=30),
    Field('log_message_text', length = 256))
db2.log_messages.id.readable = False

VIEW:

<p>AutoFlow Log</p>
<h2>Log Messages:</h2>
{{=form}}


CONTROLLER:

def display_log():
    grid = SQLFORM.grid(db2.log_messages, editable = False, searchable = False,formstyle = 'divs',maxtextlengths={'log_messages.log_message_text' : 80})
    return dict(form=grid)

Massimo Di Pierro

unread,
Jun 12, 2015, 11:43:51 AM6/12/15
to web...@googlegroups.com, jackso...@quantachrome.com
Can you help us debug? What if you use 

grid(....., maxtextlength=80)

Anthony

unread,
Jun 12, 2015, 12:07:20 PM6/12/15
to web...@googlegroups.com, jackso...@quantachrome.com
Which version of web2py? Also, have you set the "represent" attribute on the field in question?

And just to be clear, is the problem that the actual text truncation isn't happening where you expect, or is it just that the physical width of the table column is smaller than you'd like? Maybe show a screenshot.

Anthony

jackso...@quantachrome.com

unread,
Jun 12, 2015, 11:20:06 PM6/12/15
to web...@googlegroups.com
That dee


On Friday, June 12, 2015 at 12:27:27 AM UTC-4, jackso...@quantachrome.com wrote:

Seth J

unread,
Jul 25, 2017, 8:32:55 PM7/25/17
to web2py-users
I have a similar problem with maxtextlengths and I do have the "represent" attribute set like so:
                Field('f_last_change', type='text',
                      label=T('Latest Changes'),
                      default = '',
                      represent=lambda text, row: HTML(XML('' if text is None else text.replace('\n', '<br />')), sanitize=True, permitted_tags=['br/'])
                     )

Any suggestions how to keep the formatting, but still have field truncated?  Thanks!!!

Anthony

unread,
Jul 26, 2017, 11:05:58 AM7/26/17
to web2py-users
On Tuesday, July 25, 2017 at 8:32:55 PM UTC-4, Seth J wrote:
I have a similar problem with maxtextlengths and I do have the "represent" attribute set like so:
                Field('f_last_change', type='text',
                      label=T('Latest Changes'),
                      default = '',
                      represent=lambda text, row: HTML(XML('' if text is None else text.replace('\n', '<br />')), sanitize=True, permitted_tags=['br/'])
                     )

Any suggestions how to keep the formatting, but still have field truncated?  Thanks!!!

The built-in truncation works only with single strings -- it will not inspect your HTML and figure out how to do something intelligent with it (it is not even clear how you would want to handle truncation with multi-line HTML text). You should instead handle any truncation yourself in the represent function and set maxtextlength to a large value so the grid doesn't do any further truncation.

Anthony
Reply all
Reply to author
Forward
0 new messages