With your suggested changes, it looks like any time an ondelete is
specified, the grid code would no longer actually do the delete. I don't
think we want that. If your ondelete determines that no delete should take
place, then it can do a redirect or raise HTTP() in order to abandon the
delete.
Anthony
On Thursday, February 20, 2014 4:00:49 PM UTC-5, ksotiris wrote:
>
> >deletable = False
> >if 'edit' in request.args:
> > record = db[table](request.args[-1])
> > if some condition of record:
> > deletable = True
> >grid = SQLFORM.grid(db[table], deletable = deletable)
>
>
> Plus to above
> Idea:
> We have smartgrid with "orders" link table "products_in_order" and we want
> not delete the order if we have products_in_order ( ..if we are not using
>
> ON DELETE CASCADE ..)
> How to prevent deletion ? In "edit" we can use the above solution, in
> "view"
> we can do the followings.
>
> PS.: Can add this to github for the sqlhtml.py?
>
> ---
>
> if in sqlhtml.py line 2110 up to 2122
>
> --------------------------
> from
> --------------------------
> if not callable(deletable):
> if ondelete:
> ondelete(table, request.args[-1])
> db(table[table._id.name] == request.args[-1]).delete()
> else:
> record = table(request.args[-1]) or redirect(URL('error'))
> if deletable(record):
> if ondelete:
> ondelete(table, request.args[-1])
> record.delete_record()
> --------------------------
> to
> --------------------------
> if not callable(deletable):
> if ondelete:
> ondelete(table, request.args[-1])
> else:
> db(table[table._id.name] ==
> request.args[-1]).delete()
>
> else:
> record = table(request.args[-1]) or redirect(URL('error'))
> if deletable(record):
> if ondelete:
> ondelete(table, request.args[-1])
> else:
> record.delete_record()
>
> -----------------------
>
> controler :
>
> def order_delete(table,record_id):
> #count prodcuts_in order
> records = db(db.products_in_order.orders_id==record_id).count()
> if request.args[-3]=='delete':
> if records>0:
> session.flash=T('%s product(s) in order. Delete not
> perimitted.' % records)
> redirect(URL('default/orders/orders'))
> elif records==0:
> db(db.orders.id == record_id).delete()
> db.commit()
> pass
>
> def orders():
> deletable = True
> if 'edit' in request.args:
> record_id=request.args[-1]
> records = db(db.orders_products.orders_id==record_id).count()
> if records>0:
> deletable = False
>
> grid=SQLFORM.smartgrid(db.orders,linked_tables=linked_tables,
> fields=showFields,orderby=orderFields, deletable=dict(orders=deletable),
> ondelete=order_delete)
>
> response.view='default/index.html'
> return dict(grid=grid, form_name=T('Orders'))
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.