db.invoice_header.is_authorized is a Field. it's not a record fetched from 
the db... you'd likely want to check if any record of the table has an 
is_authorized field thjat carries True as a value, not the field definition 
^_^

tl;dr: if you have a bunch of rows in that table and users should be 
allowed to edit only the ones with the is_authorized column to True, you 
should pass a function to the editable and deletable argument.
Those functions are evaluated record-by-record and take the record as an 
input, so it should be something like
deletable = lambda row : row.is_authorized == True
editable  = lambda row : row.is_autorized == True

However, those will only be evaluated when the specific button is pressed 
(e.g. you click on the edit button on a row that has is_authorized == 
False, you get redirected to the main grid) . If you're seeking for a grid 
that shows the proper buttons only for the is_authorized == True records, 
you should code your own using the links argument.

On Thursday, September 12, 2013 6:07:32 PM UTC+2, 黄祥 wrote:
>
> hi,
>
> is it possible to have conditional in smartgrid that refer to the boolean 
> type of field?
>
> e.g.
> *default.py*
> def invoice():
> is_authorized = db.invoice_header.is_authorized==True # for testing, print 
> the value in the html output
> if db.invoice_header.is_authorized==True:
> grid = SQLFORM.smartgrid(db.invoice_header, deletable=False, 
> editable=False)
> else:
> grid = SQLFORM.smartgrid(db.invoice_header, deletable=True, editable=True) 
> return locals()
>
> *default/invoice.html*
> {{extend 'layout.html'}}
> {{=grid}}
> {{=is_authorized}}
> {{=response.toolbar()}}
>
> whatever the value of is_authorized (True or False) it will return True in 
> the output, i mean the deletable and editable is set to False in the grid.
> when i print the value of is_authorized in the view it return :
> (invoice_header.is_authorized = 'T')
> then i try to change the codition from 
> if db.invoice_header.is_authorized==True:
> into 
> if db.invoice_header.is_authorized=='T':
> but have the same result.
>
> my goal is each invoice that have not authorized can be delete and edit, 
> and the invoice that have been authorized can not be delete and edit.
> any idea how to handle this situation?
>
> thanks and best regards,
> stifan
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to