Edit or delete not committing in sqlform.grid for custom query

Showing 1-18 of 18 messages
Edit or delete not committing in sqlform.grid for custom query rahulserver 6/12/12 5:44 AM
I have the following sqlform.grid:
COMMITMENTS=SQLFORM.grid((db.Commitments.Account==session.id),user_signature=False)

When I try to edit any row of the form, the edit is not committing. Is it that the sqlform.grid does not allow edits for query arguments?
Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 9/13/12 11:16 AM
I'm using version 2.0.7 and seeing the same problem. 
I looked at the gluon/sqlhtml.py and it doesn't look like problem is specific to custom query (Although I too have custom query passed to the sqlform.grid)

     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 

I confirmed this by adding "db.commit()" just prior to returning. Without this line, the record is removed from the table - but not form DB. So next time we refresh and re-render the table, the deleted record re-appears

BTW, I have another function for bulk_delete (User selects from checkbox, and deleted selected records in one go) I am not calling db.commit() there explicitly but the records are indeed deleted from DB.

What is going on ?

-Mandar
unk...@googlegroups.com 9/13/12 11:14 AM <This message has been deleted.>
Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 9/13/12 11:24 AM
For now, I'm calling db.commit on my own ondelete function 

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()

so technically same delete() gets called twice - first in my ondelete function (listed above) and then immediately in gluon/sqlhtml.py
I know it is wrong/incorrect, but seems to be working for me.

Waiting for suggestions/comments from the group.

-Mandar
Re: Edit or delete not committing in sqlform.grid for custom query Gerd 9/30/12 7:16 AM
Hi!

I'm actually using V2.0.9 and the error is still active. Is it fixed in 2.1.0?

Thanks,
Gerd
Re: Edit or delete not committing in sqlform.grid for custom query Gerd 10/6/12 11:28 AM
Hi!

Any updates on this?
Re: Edit or delete not committing in sqlform.grid for custom query Derek 10/8/12 5:35 PM
Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 12/19/12 1:40 AM
Problem still persists in 2.3.2


On Tuesday, October 9, 2012 6:05:08 AM UTC+5:30, Derek wrote:
did you open an issue?


-Mandar 
Re: Edit or delete not committing in sqlform.grid for custom query Niphlod 12/19/12 1:54 AM
I can't reproduce the issue. Can you post a packed application showing the problem ? Both edit and deleteare working fine for me, either with a custom query or a table name.
Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 12/19/12 6:06 AM


On Wednesday, December 19, 2012 3:24:31 PM UTC+5:30, Niphlod wrote:
I can't reproduce the issue.

I know it is a bit tough one. Even I too wasn't able to pinpoint the exact problem. I debugged till the dal.py as well. Not sure when does the db.commit() get called.
 
Can you post a packed application showing the problem ?

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)

In a file under modules :

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')



Following are in same file under controllers:

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)

I hope this helps. As I mentioned in the bug report, the table has "db.table.id.readble=False" in models. But that conclusively did not tell me anything. But might help you.

-Mandar

Re: Edit or delete not committing in sqlform.grid for custom query Niphlod 12/19/12 7:02 AM

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)
 
 
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.


As I mentioned in the bug report, the table has "db.table.id.readble=False" in models

Setting table.id.readable = False works with grid (that fetches the id from the arguments)
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 12/19/12 8:23 AM
I know it is a tough one, but can you guess what "could" be the problem ? As I mentioned, "explicitly" adding db.commit() helps "resolve" the problem (Whether in gluon/sqlhtml.py or separately in my custom ondelete)

Does that give you any hints ? I debugged but (obviously) couldn't find the culprit.

Any pointers on how to troubleshoot/debug this ? I think at least one more person has similar problem (One that started this thread)
 
Really not relevant all the modify_grid() part. That doesn't belong to web2py, which you are addressing the bug to.

I know. But it was something different - so I thought it may be relevant.
 
Without the table model, all code is quite useless. We don't need your app. Just an app showing the problem.

Ahh, I see. Let me try to create that (app) 

-Mandar
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Boris 12/26/12 11:40 AM
The problem is in sqlhtml.py

In latest version from line 2293-2297 is following content:

if deletable and (not callable(deletable) or deletable(row)):
                        row_buttons.append(gridbutton(
                            'buttondelete', 'Delete',
                            callback=url(args=['delete', tablename, id]),
                            delete='tr'))

but it should be:

if deletable and (not callable(deletable) or deletable(row)):
                        row_buttons.append(gridbutton(
                            'buttondelete', 'Delete',
                            buttonurl=url(args=['delete', tablename, id]), <--- Missing line to define URL for Delete button
                            callback=url(args=['delete', tablename, id]), <--- We need this for warning message (I believe so?)
                            delete='tr'))

But we also need to update gridbutton function (line 1806) because we need button URL and warning. I have tried to add "buttonurl" but now the record is deleted even if I select "Cancel".

I don't know how to fix this because I don't how to handle callback.

Boris


Dne sreda, 19. december 2012 17:23:18 UTC+1 je oseba Mandar Vaze napisala:
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Massimo Di Pierro 12/26/12 3:48 PM
Can you please open a ticket about this?
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Mandar Vaze 12/26/12 8:41 PM


On Thu, Dec 27, 2012 at 5:18 AM, Massimo Di Pierro <massimo....@gmail.com> wrote:
Can you please open a ticket about this?

There is already one opened for this : http://code.google.com/p/web2py/issues/detail?id=1234
Unless your email was meant for Boris and his buttonurl code change. (It it addresses same problem, so same issue can be used ?)

-Mandar 
 
--
 
 
 

Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Christian Espinoza L. 1/11/13 5:24 AM
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.
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Niphlod 1/11/13 5:45 AM
the problem has been fixed in trunk. The issue was kinda non-existant for javascript enabled browsers, because there was an onclick attribute on the delete button that called the delete url correctly.

Now there are both the full link to the delete url and the onclick attribute, so behaviour is consistent both in javascript-enabled and javascript-disabled browsers.
Re: [web2py] Re: Edit or delete not committing in sqlform.grid for custom query Christian Espinoza L. 1/11/13 11:02 AM
Thanks Niphlod, I get the trunk with this feature working done now!

Christian.