I thnk in some places you use request.vars.id and in other places you
use request.args(0) and that is the confusion. Try this:
def edit_journal():
opskrif = T('Editing journal record no. %d') %
int(request.vars.id)
vorm = crud.update(db.akb_journal, request.args(0),
deletable = False,
next = 'articles/[id]') # << shortcut
return dict(vorm=vorm, opskrif=opskrif)
def show_journal():
opskrif = H1(T('Journal record no. %d') % int(request.args(0)))
vorm = crud.read(db.akb_journal, request.args(0))
link =
A('Edit',_href=URL('default','edit_journal',args=request.args(0)))
return dict(vorm=vorm, opskrif = opskrif, link=link)
On Aug 23, 8:17 am, Johann Spies <[email protected]> wrote:
> The following scenario illustrated to me that I do not understand enough of
> what web2py is doing in the background.
>
> I want a crud.read form and a link to edit the same form (see the two
> functions below). At first I wanted to use the link
> like this:
>
> link = A('Edit', _href=URL(c='default', f='edit_journal',
> vars=request.vars(0))) but web2py would not accept that.
> I have then changed it to what is shown below.
>
> def edit_journal():
>
> opskrif = T('Editing journal record no. %d') % int(request.vars.id)
> vorm = crud.update(db.akb_journal, request.vars.id,
> deletable = False,
> next = URL(r = request,
> c = 'default' ,
> f = 'articles',
> args=request.args))
> return dict(vorm=vorm, opskrif=opskrif)
>
> def show_journal():
> opskrif = H1(T('Journal record no. %d') % int(request.args(0)))
> vorm = crud.read(db.akb_journal, request.args(0))
> link =
> A('Edit',_href=URL(c='default',f='edit_journal',vars=dict(id=request.args(0
> ))))
> return dict(vorm=vorm, opskrif = opskrif,
> link=link
> )
>
> When I first click on the link in the second function the crud.update
> runs as expected in the first function.
> I would expect that after submitting the form I would be redirected to
> default/articles, but it does not happen.
> In stead the program returns to edit journal and while the content of
> request.vars was
> <Storage {'id': '8995'}> the first time now it is
> <Storage {'publisher': '', 'title': 'South African Journal of
> Continuing Medical Education', 'issn': '1016-6742', '_formname\
> ': 'akb_journal/8995', 'standard_name': '', '_next':
> '/akb/default/articles', '_formkey':
> 'f9ed441dd56941349a6e9b31fa29eff7'\
> , 'abbrev_iso': '', 'id': ['8995', '8995'], 'subject': ''}>
> Please take note what happened to the id field.
>
> Now my questions:
>
> Why does the above code not cause web2py to redirect to the 'articles'
> function after submitting the form?
> Why is not possible for me to use request.args in the link in the
> second function?
> What is the correct way to do this?
>
> Regards
> Johann
>
> --
> May grace and peace be yours in abundance through the full knowledge of God
> and of Jesus our Lord! His divine power has given us everything we need for
> life and godliness through the full knowledge of the one who called us by
> his own glory and excellence.
> 2 Pet. 1:2b,3a