http://web2py.com/books/default/chapter/29/6

{{extend 'layout.html'}}
<h1>Records</h1>
{{=SQLTABLE(rows,
     headers='fieldname:capitalize',
     truncate=100,
     upload=URL('download'))
}}


Richard

On Fri, Apr 20, 2012 at 11:42 AM, Richard Vézina <
ml.richard.vez...@gmail.com> wrote:

> Also, you could maybe search the book with "truncate" keyword, there is
> already a utility if you just want to control the lenght of free text field
> or other string field.
>
> Richard
>
>
> On Fri, Apr 20, 2012 at 11:35 AM, Richard Vézina <
> ml.richard.vez...@gmail.com> wrote:
>
>> I think you can't use compute since you modify a field where the user as
>> to enter something base on the len of user input, so I think you should
>> transform the code below into function and use onvalidation=function
>>
>>
>> x=len(form.vars.description)
>> if x>128:
>>     i=128
>>     dots="..."
>> else:
>>     i=x-1
>>     dots=""
>> s=form.vars.description[0:i] + dots
>>
>> Richard
>>
>>
>>
>>
>> On Fri, Apr 20, 2012 at 11:26 AM, Annet <anneve...@googlemail.com> wrote:
>>
>>> I defined a table eventList:
>>>
>>> db.define_table('EventList',
>>>    ...
>>>     Field('description',type='text'),
>>>     Field('shortdescr',length=128,writable=False,readable=False),
>>>     ....
>>>     migrate=False)
>>>
>>> db.EventList.description.requires=IS_LENGTH(1536,error_message='length
>>> exceeds 1536 characters')
>>> db.EventList.shortdescr.requires=IS_LENGTH(128,error_message='length
>>> exceeds 128 characters')
>>>
>>> shortdescr should be the first 128 characters of description followed by
>>> three dots. In a function this works:
>>>
>>> x=len(form.vars.description)
>>> if x>128:
>>>     i=128
>>>     dots="..."
>>> else:
>>>     i=x-1
>>>     dots=""
>>> s=form.vars.description[0:i] + dots
>>>
>>> ... but I'd like to add it to the model file. I had a look at the
>>> compute option but wasn't able to figure out how to get it syntactically
>>> correct.
>>>
>>>
>>> Kind regards,
>>>
>>> Annet.
>>>
>>
>>
>

Reply via email to