smartgrid and auth.archive() ugly code; how to improve?

64 views
Skip to first unread message

Cliff

unread,
Dec 27, 2011, 7:22:34 AM12/27/11
to web2py-users
This is some ugly code that makes auth.archive() work with smartgrid:

if len(request.args) > 3 and request.args[-4] == 'owner' and\
request.args[-3] == 'edit' and request.args[-2]=='owner'\
and form[2].process(onsuccess=auth.archive).accepted:
pass


Surely there must be a better way. Any and all hints gratefully
accepted.

Anthony

unread,
Dec 27, 2011, 9:38:52 AM12/27/11
to web...@googlegroups.com
Have you tried:

form = SQLFORM.smartgrid(..., onupdate=auth.archive)

Also, note there is also crud.archive, which is the same as auth.archive.

Anthony

Cliff

unread,
Dec 27, 2011, 10:54:35 AM12/27/11
to web2py-users
This also works SQLFORM.smartgrid(..., onvalidation=crud.archive...

But, I now discover archive never saves the original record. You can
edit the record and it saves the edits, but it never gets the first
version of it.

This statement from the Official Book"on updating, it stores a copy of
the record (as it was before the update)" is incorrect, at least as
far as smartgrid is concerned. I haven't tried it with SQLFORM by
itself or with CRUD.

Anthony

unread,
Dec 27, 2011, 11:09:22 AM12/27/11
to web...@googlegroups.com
What if you do:

SQLFORM.smartgrid(..., oncreate=crud.archive, onupdate=crud.archive)

or

SQLFORM.smartgrid(..., onupdate=lambda form: crud.archive(form, archive_current=False))

Note, archive_current=False tells it to archive the previous record (the one being updated) rather than the current record (the updated version).

Anthony


On Tuesday, December 27, 2011 10:54:35 AM UTC-5, Cliff wrote:
This also works SQLFORM.smartgrid(..., onvalidation=crud.archive...

But, I now discover archive never saves the original record.  You can
edit the record and it saves the edits, but it never gets the first
version of it.

This statement from the Official Book"on updating, it stores a copy of
the record (as it was before the update)" is incorrect, at least as
far as smartgrid is concerned.  I haven't tried it with SQLFORM by
itself or with CRUD.

Cliff

unread,
Dec 27, 2011, 11:43:38 AM12/27/11
to web2py-users
Setting archive_current=False works.

Thank you.
Reply all
Reply to author
Forward
0 new messages