form.accept problem

2 views
Skip to first unread message

jldistefano

unread,
May 28, 2008, 9:08:31 PM5/28/08
to web2py Web Framework
Hi Massimo, Hi all.

I am new to web2py and I really like it.
can anyone tell me what is wrong with this code, there is no
validation at all, it display page2 directly without showing the
form.

def index():

form=FORM('your name:',
INPUT(_name="name"),
INPUT(_type="submit"))
if form.accepts(request.vars,formname=None):
session.name=form.vars.name
session.flash='you have been redirected'
redirect(URL(r=request,f='page2'))
elif form.error:
response.flash='there are errors in your form'
return dict(form=form)

def page2():
return dict(message='hello %s'%session.name)

In default/index.html there is only a {{=form}}

Thanks in advance.

mdipierro

unread,
May 29, 2008, 3:00:44 AM5/29/08
to web2py Web Framework
I only see one problem:

>  elif form.error:

should be

> elif form.errors:

mdipierro

unread,
May 29, 2008, 3:01:13 AM5/29/08
to web2py Web Framework
make sure sessions are on by commenting the line

session.forget()

jldistefano

unread,
May 29, 2008, 12:56:30 PM5/29/08
to web2py Web Framework
Massimo,

The line session.forget() is deleted, and now the elif form.error:
block too, and things don't change.
when the code is run there is no validation and page2 is shown
directly without showing index page with the form.
What other things can I check?

Thanks for your attention.

Massimo Di Pierro

unread,
May 29, 2008, 1:06:22 PM5/29/08
to web...@googlegroups.com
You must give a name to the form else web2py thinks the form has been
submitted but it is empty.

Massimo

jldistefano

unread,
May 29, 2008, 2:35:49 PM5/29/08
to web2py Web Framework
Yes thats it!! now is working.
if form.accepts(request.var,formname="myform")
.....
.....

and without the elif form.error: block



---------OFF
TOPIC----------------------------------------------------------------------------------------------------------------------------------------------

Massimo, I spend lots of hours traying to figure what was wrong, I saw
a lot of code in diferent places (cookbook, examples, vids, draft
manual here in the group) and in all I found diferent code that
suppouse to do the same.
for example why - if form.accepts(session.var,session) - do not work.
Like I said I'm very new with web2py and also may be not so smart
like others in this group.
I realy belive that you have developed a very very good piece of
software , but also belive that DOCUMENTATION is not well presented
and this is, if not the most important, a big issue if you want to be
compared with the others frameworks (Zope, Django, TG), you as a
teacher understand what I am talking about.

Sorry for my poor english.
Congratulations, and thanks for your excelent work !!
And keep going this way

Jorge Di Stefano
39 years old.
Italian Ascendent.
"Ue paisano como va?"

Massimo Di Pierro

unread,
May 29, 2008, 3:18:45 PM5/29/08
to web...@googlegroups.com
Did you get the draft book form the web site? I am trying to finish
that.

jldistefano

unread,
May 29, 2008, 3:31:00 PM5/29/08
to web2py Web Framework
If you refer Draft Book to the Draft Manual, yes I get it !!, is my
principal guide, and for example I didn' t found there the syntax "if
form.accepts(request.var,formname="myform") "

Bye

Massimo Di Pierro

unread,
May 29, 2008, 3:35:02 PM5/29/08
to web...@googlegroups.com
No but form.accepts(request.var,session) is in there and that is the preferred way since it prevents double submission.
I don't think I ever suggested using formname=None. I may have on the list in response to a very specific question.


On May 29, 2008, at 2:31 PM, jldistefano wrote:

form.accepts(request.var,formname="myform") "


jldistefano

unread,
May 30, 2008, 5:06:14 PM5/30/08
to web2py Web Framework
Continuing with the chat, what I found in the example said,
form.accepts(session.var,session) and this throw this ticket in my
code.

Traceback (most recent call last): File "gluon\restricted.pyc", line
62, in restricted
File "C:\Python25\misproyectos\web2py\applications\init/controllers/
default.py", line 130, in <module>
File "C:\Python25\misproyectos\web2py\applications\init/controllers/
default.py", line 91, in edita
File "gluon\html.pyc", line 131, in acceptsAttributeError: 'NoneType'
object has no attribute '_formname'

form.acceps(request.var,session) works

Massimo Di Pierro

unread,
May 30, 2008, 6:28:29 PM5/30/08
to web...@googlegroups.com
> form.accepts(session.vars,session)

not

> form.accepts(session.var,session)

could this be the problem?

jldistefano

unread,
May 30, 2008, 10:36:32 PM5/30/08
to web2py Web Framework
I don't know .
I didn't put the S in session.var

mdipierro

unread,
May 30, 2008, 11:10:16 PM5/30/08
to web2py Web Framework
Than that's it. accepts expects a dictionary-like object as first
argument. If you pass var instead of vars, since var it is undefined,
it stores None. This propagates and causes an error.

jldistefano

unread,
May 31, 2008, 8:27:56 AM5/31/08
to web2py Web Framework
CORRECTION !! The ticket above was produced with
form.accepts(session.vars,session) with the S on var.
Sorry.

Massimo Di Pierro

unread,
May 31, 2008, 9:38:51 AM5/31/08
to web...@googlegroups.com
can you send me the ticket and possibly the code?

Massimo Di Pierro

unread,
May 31, 2008, 9:49:58 AM5/31/08
to web...@googlegroups.com
please send me your code and I will look it at (privately if you want).

Massimo

On May 31, 2008, at 7:27 AM, jldistefano wrote:

jldistefano

unread,
Jun 1, 2008, 12:00:13 AM6/1/08
to web2py Web Framework



---------------------------Here is the code--------------------
import datetime
def index():


session.s=datetime.date.today().month
session.anio=datetime.date.today().year


session.maq="Husky-2"

return dict(message="Panel de Control "+str(session.anio),
s=session.s, maq=session.maq,y=session.anio)



def edita():
di=int(request.args[0])
tip=request.args[1]
an=int(request.args[2])
me=int(request.args[3])
ma=request.args[4]
fecha=datetime.date(an,me,di).isoformat()
if tip=="1":
sector="Produccion"
elif tip=="2":
sector="Procesos"
elif tip=="3":
sector="Mantenimiento"
else:
sector="Calidad"

if tip=="1":
try:

busq=pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).select()
[0]
data=busq.Produccion
datacav=busq.Cavidades
datacic=busq.Ciclo
except:
pancon.tb1.insert(Produccion="",Fecha=fecha,
Maquina=ma,Ciclo=0, Cavidades=0, Mantenimiento="", Procesos="",
Calidad="")
data="no hay nada"
datacav=0
datacic=0
form=CENTER(FORM(TABLE(TR(B(sector+":")),
TR(TEXTAREA(_name="sector",value=data)),

TR("Cavidades:"),TR(INPUT(_name="Cavidades",value=datacav)),

TR("Ciclo:"),TR(INPUT(_name="Ciclo",value=datacic)),
TR(INPUT(_type="submit")))))


if tip=="2":
try:

busq=pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).select()
[0]
data=busq.Procesos

except:
pancon.tb1.insert(Produccion="",Fecha=fecha,
Maquina=ma,Ciclo=0, Cavidades=0, Mantenimiento="", Procesos="",
Calidad="")
data=""


form=CENTER(FORM(TABLE(TR(B(sector+":")),
TR(TEXTAREA(_name="sector",value=data),
TR(INPUT(_type="submit"))))))
if tip=="3":
try:

busq=pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).select()
[0]
data=busq.Mantenimiento

except:
pancon.tb1.insert(Produccion="",Fecha=fecha,
Maquina=ma,Ciclo=0, Cavidades=0, Mantenimiento="", Procesos="",
Calidad="")
data=""


form=CENTER(FORM(TABLE(TR(B(sector+":")),
TR(TEXTAREA(_name="sector",value=data),
TR(INPUT(_type="submit"))))))
if tip=="4":
try:

busq=pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).select()
[0]
data=busq.Calidad

except:
pancon.tb1.insert(Produccion="",Fecha=fecha,
Maquina=ma,Ciclo=0, Cavidades=0, Mantenimiento="", Procesos="",
Calidad="")
data=""


form=CENTER(FORM(TABLE(TR(B(sector+":")),
TR(TEXTAREA(_name="sector",value=data),
TR(INPUT(_type="submit"))))))
if form.accepts(session.vars,session):
if tip=="1":
session.produccion=form.vars.sector
acavidades=int(form.vars.Cavidades)
aciclo=float(form.vars.Ciclo)


pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).update(Produccion=session.produccion,
Ciclo=aciclo, Cavidades=acavidades)

response.view="default/index.html"
return dict(message="Panel de Control
"+str(session.anio), s=session.s,
maq=session.maq,y=session.anio)
if tip=="2":
session.procesos=form.vars.sector

pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).update(Procesos=session.procesos)
response.view="default/index.html"
return dict(message="Panel de Control
"+str(session.anio), s=session.s,
maq=session.maq,y=session.anio)
if tip=="3":
session.mantenimiento=form.vars.sector

pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).update(Mantenimiento=session.mantenimiento)
response.view="default/index.html"
return dict(message="Panel de Control
"+str(session.anio), s=session.s, maq=session.maq,y=session.anio)
if tip=="4":
session.calidad=form.vars.sector

pancon((pancon.tb1.Fecha==fecha)&(pancon.tb1.Maquina==ma)).update(Calidad=session.calidad)
response.view="default/index.html"
return dict(message="Panel de Control
"+str(session.anio), s=session.s, maq=session.maq,y=session.anio)


return dict (fecha=fecha, ma=ma,form=form)

def selmes():
session.s=int(request.args[0])
response.view="default/index.html"
return dict(message="Panel de Control "+str(session.anio),
s=session.s, maq=session.maq,y=session.anio)

def sel():
session.maq=request.args[0]
response.view="default/index.html"
return dict(message="Panel de Control "+str(session.anio),
s=session.s, maq=session.maq,y=session.anio)

------------------------End of code---------------------------------

Here the ticket

Ticket 127.0.0.1.1212232629.131947808026



Error traceback
1.2.3.4.5.6.7. Traceback (most recent call last): File "gluon
\restricted.pyc", line 62, in restricted File "C:
\Python25\misproyectos\web2py\applications\init/controllers/
default.py", line 130, in <module> File "C:\Python25\misproyectos
\web2py\applications\init/controllers/default.py", line 91, in edita
Reply all
Reply to author
Forward
0 new messages