Hi all,

I am still a newbie to web2py so could be that this is my fault.
I am making a warehouse stock registry app. At present I try to make a
procedure where the worker can input the new received gadgets. The
form have quantity field. If it is greater than 1, I need to do
additional inserts to the db with the same data (the id will be
different of course).

The current situation that the form and the controller works, but not
always and I can't find the reasons. In the most of the cases when I
visit the page for the first time, fill in the fields and submit,
usually I get back the page without any errors, but no insert made on
the database. I see that the form.accept is false, but form.errors is
empty. If I fill in the form again it usually accepts and makes the
inserts, but also not always sometimes it never accepts does not
matter how many times I try.
On the other hand, if I make a validation error at will, and I get the
error messages of the validation, and then I input the correct datas
it usually accepts (sometimes not but that is rare).
I suppose that this behavor comes from a web2py feature, e.g caching
or the preventing of booking the same form times due to user error. It
is also could happen that I misunderstood something related to forms.

Can somebody help me to solve this issue?

Here is the related function in the controller (konyveles.py). I
insert several  objects to the returned dict to check their content in
the view for debug purposes:
def beerkeztetes():
    form=SQLFORM(db.eszkozok,
 
fields=["eszkozszam","aleszkozszam","darab","koltseghely","megnevezes","egyediazon","aktivalas","tipus_id"],
                col3={'darab':'Ennyi új eszköz fog
létrejönni!','egyediazon':'Pl. gyári szám, sorozatszám'})
    faccept=None
    if len(request.vars)>0:
        darab=int(request.vars.darab)
        if darab>1:
            request.vars.darab='1'
        faccept=form.accepts(request.vars)
        if faccept:
            response.flash = '%s db új eszköz felvéve' % darab
 
db.naplo.insert(datum=datetime.date.today().isoformat(),eszkoz_id=form.vars.id,mozgas_id=1,user_id=auth.user_id)
            if darab>1:
                for i in range(1,darab):
 
id=db.eszkozok.insert(eszkozszam=request.vars.eszkozszam,aleszkozszam=request.vars.aleszkozszam,darab=1,koltseghely=request.vars.koltseghely,megnevezes=request.vars.megnevezes,egyediazon=request.vars.egyediazon,aktivalas=datetime.datetime.strptime(request.vars.aktivalas,"%Y.
%m.%d.").date().isoformat(),tipus_id=int(request.vars.tipus_id))
 
db.naplo.insert(datum=datetime.date.today().isoformat(),eszkoz_id=id,mozgas_id=1,user_id=auth.user_id)
                db.commit()

        elif form.errors:
            response.flash = 'Kitöltési hiba'
    beerkalattlista=db((db.eszkozok.allapot_id==1) &
(db.eszkozok.tipus_id==db.eszkoztipus.id) &
(db.eszkozok.allapot_id==db.eszkozallapot.id) &
(db.eszkozok.hely_id==db.eszkozhelyek.id)).select(db.eszkozok.ALL,db.eszkoztipus.nev,db.eszkozallapot.nev,db.eszkozhelyek.nev,orderby=db.eszkozok.eszkozszam)
    return
dict(beerkalattlista=beerkalattlista,form=form,rvars=request.vars,lastid=form.vars.id,sess=session,faccept=faccept)

This is the view:
{{extend 'layout.html'}}
<h1>Eszköz beérkeztetése</h1>
<hr />
<p>User ID: {{=auth.user_id}}</p>
<p>rvars: {{=rvars}}</p>
<p>len rvars >1: {{=(len(rvars)>1)}}</p>
<p>darab: {{=rvars.darab}}</p>
<p>faccept: {{=faccept}}</p>
{{if rvars.darab<>None:}}
<p>darab>1: {{=(int(rvars.darab)>1)}}</p>
{{pass}}
<p>lastid: {{=lastid}}</p>
<p>session: {{=sess}}</p>
<p>errors: {{=form.errors}}</p>
<h3>Új beérkezés</h3>
{{=form}}
<hr />
<h3>Beérkezés alatt lévő eszközök</h3>
<table>
<tr>
    <th>{{=db.eszkozok.id.label}}</th>
    <th>{{=db.eszkozok.eszkozszam.label}}</th>
    <th>{{=db.eszkozok.aleszkozszam.label}}</th>
    <th>{{=db.eszkozok.darab.label}}</th>
    <th>{{=db.eszkozok.koltseghely.label}}</th>
    <th>{{=db.eszkozok.megnevezes.label}}</th>
    <th>{{=db.eszkozok.egyediazon.label}}</th>
    <th>{{=db.eszkozok.aktivalas.label}}</th>
    <th>{{=db.eszkozok.tipus_id.label}}</th>
    <th>{{=db.eszkozok.allapot_id.label}}</th>
    <th>{{=db.eszkozok.hely_id.label}}</th>
    <th>Művelet</th>
</tr>
{{for row in beerkalattlista:}}
<tr>
    <td>{{=row.eszkozok.id}}</td>
    <td>{{=row.eszkozok.eszkozszam}}</td>
    <td>{{=row.eszkozok.aleszkozszam}}</td>
    <td>{{=row.eszkozok.darab}}</td>
    <td>{{=row.eszkozok.koltseghely}}</td>
    <td>{{=row.eszkozok.megnevezes}}</td>
    <td>{{=row.eszkozok.egyediazon}}</td>
    <td>{{=row.eszkozok.aktivalas}}</td>
    <td>{{=row.eszkoztipus.nev}}</td>
    <td>{{=row.eszkozallapot.nev}}</td>
    <td>{{=row.eszkozhelyek.nev}}</td>
    <td>{{=A('raktárra
vétel',_href=URL('raktarra',args=row.eszkozok.id))}}</td>
</tr>
{{pass}}
<table>

Reply via email to