[web2py] Re: web2py Issues

2011-03-21 Thread Neveen Adel
Hello Kevin ,

 Thanks a lot for your reply.

what i want to do is :

def items():
wo =  db(db.WO.id == request.vars.wo_id).select()[0]
checkList_items = db(db.checklist_item.cl_id ==
request.vars.cl_id).select(orderby=checklist_item.id DESC)
form = SQLFORM(SQLDB(None).define_table('myform',
   db.WO.project_title,
   db.WO.project_manager
   ),submit_button=T(save))
form.vars.project_title = wo.project_title
form.vars.project_manager = wo.project_manager
count = 4
for item in checkList_items:
 
form[0].insert(count,TR(TD(item.id),TD(item.item),TD(INPUT(_type='radio',_value=NA
 ,
_name=item.id 
,_class=answer_class,_id=answer_options+str(item.id)),_colspan=1),TD(INPUT(_type='radio',_value='YES'
 ,
_name=item.id 
,_class=answer_class,_id=answer_options)),TD(INPUT(_type='radio',_value='NO'
 ,
_name=item.id 
,_class=answer_class,_id=answer_options),TD(INPUT(_type='text',_id='comment',_name=comment+str(item.id))
if form.accepts(request.vars, session):
for item in checkList_items:
try:
if request.vars[str(item.id)]:
if request.vars[str(item.id)] == NO and
request.vars[comment+str(item.id)] == :
session.flash = Error
#return dict(form=request.vars)
form.vars = request.vars
 
#redirect(URL(r=request,f='items',vars=request.vars)) ## Here
redirected to empty from How can i fix this
return dict(form=form)
else:
 
db.answers.insert(field_clI_id=request.vars.fCL_id,clI_id=item.id,answer=request.vars[str(item.id)],comment=request.vars[comment+str(item.id)])
redirect(URL(r=request,f='view'))
except KeyError:
print Error KeyValue
 
db.answers.insert(field_clI_id=request.vars.fCL_id,clI_id=item.id,answer='None')
redirect(URL(r=request,f='view'))
return dict(form=form)





On Mar 20, 6:08 pm, Kevin Ivarsen kivar...@gmail.com wrote:
 Hi Neveen,

 Without a bit more context I'm having trouble determining the problem. In
 principle you should be able to pass vars=request.vars to URL and have them
 show up in the redirected URL. For example:

 def func1():
     if request.vars.value == hello:
         return you submitted hello
     else:
         redirect(URL('func2', vars=request.vars))

 def func2():
     return BEAUTIFY(request.vars)

 If you go to /app/controller/func1?name=Bob you will be redirected
 to /app/controller/func1?name=Bob, and request.vars will include a
 .name='Bob' attribute.

 If you go to /app/controller/func2?name=Bobvalue=hello you'll stay at
 func1 and see you submitted hello.

 Try starting with that example, verifying that it works for you, and then
 extending it to do what you need.

 If you could describe a little more about what you are trying to do, and/or
 include a bit more of the code you're working with, I might be able to
 provide more help. There may be a better way to do this already built in to
 web2py.

 Cheers,
 Kevin


[web2py] Re: web2py Issues

2011-03-21 Thread Neveen Adel
Hello DenesL,

 Thanks for your reply.

 For Issue#2:

 inside get_CIs function the request.vars.WO_cpp_id is None which
represent the selected id from first dropdown.

 could you please advice me what the problem?

On Mar 20, 6:24 pm, DenesL denes1...@yahoo.ca wrote:
 On Mar 20, 11:32 am, Neveen Adel nevo.a...@gmail.com wrote:

  Hello,

   Issue#1:

    I want make server validation, but when return the page again i want
  to be had the entered values:
    e.x:
     if request.vars[str(item.id)] == NO and
  request.vars[comment+str(item.id)] == :
                          session.flash = Invalid Value

  redirect(URL(r=request,f='items',vars=request.vars))

 Hard to tell without the action code but assuming that you are using
 form.accepts you should not redirect on form errors.

   // The previous code return an empty values.

  Issue#2:
  Is there a problem in function ajax() with version 1.91.6 .

  because when i used
  ajax('get_CIs', ['WO_cpp_id'], 'WO_ci_id');
  The function get_CIs has been called fine but the
  request.vars.WO_cpp_id is None.

 Probably the action is returning an empty selection.

  Please, How i can fix the previous two issues?

  Thanks in Advance


[web2py] Re: web2py Issues

2011-03-21 Thread pbreit
This is hard to follow. Can you isolate the parts that don't work? Are you able 
to radically simplify the logic?


[web2py] Re: web2py Issues

2011-03-21 Thread Kevin Ivarsen
Why do you need to redirect back to the same view to display the error? The 
normal way of doing this is basically what you currently have: if there is 
an error in the form in the POST, immediately redisplay the form.

I think the reason this is failing is because of the formkey technique used 
by web2py. When you auto-generate a form (as with SQLFORM), a random form 
key is generated and inserted into the form. The same key is also saved in 
the web2py server. When the form is submitted and web2py checks it with 
form.accepts, it first verifies that the submitted formkey is one that was 
previously generated by web2py. If the key is found, it is removed from the 
list of pending formkeys. If the key is not found, the form is reset. 

The point of this is to prevent people from accidentally submitting the same 
form twice (imagine accidentally clicking the submit button twice when 
submitting a credit card purchase). But I bet you're running into a case 
where you redirect and send the form vars, but the formkey is no longer 
valid (since it has already been generated and accepted once), so the form 
is reset after the redirect.

Long story short, regenerate the form in the same request if there is an 
error - don't redirect unless there's some reason for this that I'm not 
realizing.

Cheers,
Kevin


[web2py] Re: web2py Issues

2011-03-21 Thread Kevin Ivarsen
One other thought - if web2py wasn't rejecting the form based on the formkey 
after redirect, I think you would actually be running into an infinite 
redirect loop here the way things are currently structured!

Cheers,
Kevin


[web2py] Re: web2py Issues

2011-03-21 Thread Neveen Adel
Thanks a lot Kevin for your time  explanation :)


On Mar 21, 3:44 pm, Kevin Ivarsen kivar...@gmail.com wrote:
 One other thought - if web2py wasn't rejecting the form based on the formkey
 after redirect, I think you would actually be running into an infinite
 redirect loop here the way things are currently structured!

 Cheers,
 Kevin


[web2py] Re: web2py Issues

2011-03-20 Thread Kevin Ivarsen
Hi Neveen,

Without a bit more context I'm having trouble determining the problem. In 
principle you should be able to pass vars=request.vars to URL and have them 
show up in the redirected URL. For example:

def func1():
if request.vars.value == hello:
return you submitted hello
else:
redirect(URL('func2', vars=request.vars))

def func2():
return BEAUTIFY(request.vars)

If you go to /app/controller/func1?name=Bob you will be redirected 
to /app/controller/func1?name=Bob, and request.vars will include a 
.name='Bob' attribute.

If you go to /app/controller/func2?name=Bobvalue=hello you'll stay at 
func1 and see you submitted hello.

Try starting with that example, verifying that it works for you, and then 
extending it to do what you need.

If you could describe a little more about what you are trying to do, and/or 
include a bit more of the code you're working with, I might be able to 
provide more help. There may be a better way to do this already built in to 
web2py.

Cheers,
Kevin




[web2py] Re: web2py Issues

2011-03-20 Thread DenesL


On Mar 20, 11:32 am, Neveen Adel nevo.a...@gmail.com wrote:
 Hello,

  Issue#1:

   I want make server validation, but when return the page again i want
 to be had the entered values:
   e.x:
    if request.vars[str(item.id)] == NO and
 request.vars[comment+str(item.id)] == :
                         session.flash = Invalid Value

 redirect(URL(r=request,f='items',vars=request.vars))

Hard to tell without the action code but assuming that you are using
form.accepts you should not redirect on form errors.

  // The previous code return an empty values.

 Issue#2:
 Is there a problem in function ajax() with version 1.91.6 .

 because when i used
 ajax('get_CIs', ['WO_cpp_id'], 'WO_ci_id');
 The function get_CIs has been called fine but the
 request.vars.WO_cpp_id is None.

Probably the action is returning an empty selection.

 Please, How i can fix the previous two issues?

 Thanks in Advance