Hello,
I am new to Web2Py so please guide me on this. I have a file modules/xyz.py
where I've created a custom button on SQLFORM.grid as -
def list_all(self):
links = [lambda row: TAG.a('+', _class="btn",
_href=URL(self.allow_delete(), vars=dict(id=row.id)))]
self.context.grid = SQLFORM.grid(self.db.tbl1, user_signature=True,
deletable = False, sortable=True, links = links)
#something else
The function allow_delete in the same file is -
def allow_delete(self):
if(self.db(self.db.tbl1.id > 0).count() == 1):
self.response.flash = 'Cannot Delete last record'
else:
print "In else"
self.response.flash = 'Proceed to Delete'
# delete
*The problem is* - The tbl1 as of now has 4 records & as soon as the grid
loads, the else part gets executed. Hence, the print statement is shown on
the console &
'Proceed to Delete' flashes despite not clicking '+'. I tried print & flash
messages just to get the initial feel of it, but if this is the case how
can I expect the actual functionality to work ONLY when the custom button
is clicked.
What am I doing wrong here? Thanks for your help.
Regards,
Ashish
www.genpro.co.in
--