elif deletable and len(request.args)>2 and request.args[-3]=='delete': table = db[request.args[-2]] if ondelete: ondelete(table,request.args[-1]) ret = db(table[table._id.name]==request.args[-1]).delete() db.commit() # If I add this, the record is deleted from DB too return ret
def my_ondelete_function(table, record_id): print "Deleting %s from %s" % (record_id, table) db(table[table._id.name]==record_id).delete() db.commit()
did you open an issue?
I can't reproduce the issue.
Can you post a packed application showing the problem ?
from gluon import current
import datetime
def modify_grid(grid, hide_adv_search=False,
bootstrap_pagination=False, rename_view_btn=False,
non_web2py_table=False):
T = current.T
if hide_adv_search:
# Remove Advanced Query Slideout
if len(grid.elements('input[id=web2py_keywords]')):
grid.elements('input[id=web2py_keywords]')[0]['_onfocus'] = ""
if bootstrap_pagination:
if len(grid.elements('.web2py_paginator')):
grid.elements('.web2py_paginator')[0]['_class'] = 'pagination'
if non_web2py_table:
if len(grid.elements('.web2py_table')):
grid.elements('.web2py_table')[0]['_class'] = \
'table table-striped'
if rename_view_btn:
# Change from "View" to "Details"
# When using Buttons
for btn in grid.elements('span'):
if btn['_title'] == "View":
btn['_title'] = T('Details')
for y in btn.elements():
y[0] = T("Details")
# When NOT using Buttons
for a in grid.elements('a[title=View]'):
a.elements()[0]['_title'] = T('Details')
def delete_record(table, record_id):
record = db(table[table._id.name] == record_id).select().first()
if 'name' in record:
print "User [%s] is Deleting [%s] from [%s]" % (auth.user.first_name,
record['name'], table)
else:
print "User [%s] is Deleting [%s] from [%s]" % (auth.user.first_name,
record_id, table)
db(table[table._id.name] == record_id).delete()
db.commit()
@auth.requires_login()
@auth.requires_membership('some_role')
def my_method():
textlengths = {'table.column1': 100, 'table.column2': 60,
'table.column2': 60}
grid = SQLFORM.grid(db.table, user_signature=False, csv=False,
ondelete=delete_record,
maxtextlengths=textlengths, showbuttontext=False)
modify_grid(grid, hide_adv_search=True, bootstrap_pagination=True,
rename_view_btn=True, non_web2py_table=True)
return dict(grid=grid)
Can't. Anyway, I'm pasting some relevant code below. BTW, if it matters, I started the development with 2.0.x and upgrade just the web2py code to current stable release i.e. After I upgrade web2py I do not go by to my application and make any changes (like web2py.css or any other)
As I mentioned in the bug report, the table has "db.table.id.readble=False" in models
Really not relevant all the modify_grid() part. That doesn't belong to web2py, which you are addressing the bug to.
Without the table model, all code is quite useless. We don't need your app. Just an app showing the problem.
Can you please open a ticket about this?
--
This Problem is currently active in 2.3.2
There is something with the link for delete action at generation of grid code:
With 2.2.1
View->http://127.0.0.1:8000/webapp/admin/users/view/auth_user/6?_signature=d408cbb7bcbce4ec22a9089465dcefc7f1f2a5db Edit->http://127.0.0.1:8000/webapp/admin/users/edit/auth_user/6?_signature=a688c63924538f53fdf0da2630790d780204403d Delete->http://127.0.0.1:8000/webapp/admin/users?_signature=ca13c286893cff85c6916ff7723d3f0cd8e24c56#null
With 2.3.2
View->http://127.0.0.1:8000/webapp/admin/users/view/auth_user/6?_signature=d408cbb7bcbce4ec22a9089465dcefc7f1f2a5db
Edit->http://127.0.0.1:8000/webapp/admin/users/edit/auth_user/6?_signature=a688c63924538f53fdf0da2630790d780204403d
Delete->http://127.0.0.1:8000/avl/admin/users#null
As you can see the Delete option link doesn't point to any function at both versions
Christian.