[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-11 Thread Anthony
Probably you are running web2py from source with your own Python 
installation and have not installed the pywin32 
http://sourceforge.net/projects/pywin32/ extension (which is required for 
file locking).

Anthony

On Monday, August 10, 2015 at 8:06:12 PM UTC-4, Val K wrote:

 As I see, the problem is that ajax request (may be not ajax only) didn't 
 wait for closing session file by another one and read/save data from/to it 
 at any time! Lock did not work on my Win7 because , as I think, for Win 
 it's one  process.
 Request processing may be not pure parallel but fully asynchronous  - I 
 placed some print statement in ajax controller and got full chaos - among 
 print from one request were one from another.
 Here is my littlle test. 3 ajax calls start at once but finish 
  asynchronously (time.sleep()).   By change time.sleep() it's possible to 
 get any order (I did start first - finish last). At the end of all 
 session contains only vars/changes of ajax which finish last.



 import time

 # it's a funny AJAX test
 #just create new app and paste it in the default controller
 # call   .../default/many_ajx_form

 def ajx_bug():
 if request.args(0)=='0':
 time.sleep(10) # well, now wait until fish fall asleep in the pond
 session.req_0='Only req_0 ... nothing else!!! Where are req_1, 
 req_2 and other kids? It seems, that guys ignored my session lock?'
 elif request.args(0)=='1':
 time.sleep(5) 
 session.req_1='I killed req_2 and created req_1 which will be 
 killed by req_0 !'
 else:
 session.req_2='I created req_2'
 response.flash=click 'Print Session' !
 if request.args(0)=='0':
 return dict(ret='Better late than never')
 else:
 return dict(ret='completed req_%s'%request.args(0))

 def print_session():
 lst=[]
 for k,v in session.items():
 lst.append(DIV(
 DIV(k,_class='col-xs-2', _style=font-weight:bold; 
  text-align:right; min-height:50px),
 DIV(':',_class='col-xs-1'),
 DIV(v,_class='col-xs-9'),
 _class='row'
)
   )
 return dict(r=DIV(*lst, _class=container, _style=max-width:800px))



 # CALL THIS 
 def many_ajx_form():
 session.clear() #  - for clear test
 session.dummy_data = 'dummy data'   # make some action for sure init 
 session 
 ret={}
 for i in xrange(3):
 ret['ajx_frm_%s'%i]= \
 DIV(
 LOAD('default','ajx_bug.load',
  args=[i],
  ajax=True,
  target='cont_%s'%i
  ),
 _id='cont_%s'%i
)
 
 btn_prnt=DIV(BUTTON(Print Session, _type=button,_class=btn 
 btn-default,
_onclick=myLOAD_any(default,print_session, 
 target=lst)),
  DIV(_id=lst) 
 )
 
 ret['z']=btn_prnt
 
 return ret

 #return string, no SCRIPT tag!
 def myLOAD_any(contrl, fun, target, args=None, vars=None, ):

 if vars:
 vars_str='?'
 for k,v  in vars.items():
 vars_str+=('%s=%s'%(k,v))
 vars_str= vars_str[:-1] # remove last ''
 else:
 vars_str=''
 if args:
 args_str='/'.join([str(it) for it  in args])
 else:
 args_str=''
 data=dict(
rmt= /%s/%s/%s.load/%s%s%(request.application, contrl, fun, 
 args_str, vars_str ),
trg=target
 )
 load_str=$.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
 $(#%(trg)s));
 return load_str%data







 On Monday, August 10, 2015 at 4:05:57 AM UTC+3, Anthony wrote:

 All responses within the same session are supposed to have the same 
 session_id. The fact that all three Ajax requests can access the session 
 doesn't necessarily mean they are being processed in parallel (the requests 
 might still be completing one after another).

 It would be helpful if you could attach a minimal app that demonstrates 
 the problem.

 Anthony

 On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:

 I realize your advice - no effect!
 I analyzed *session.connect* and found  strange  place at the biginig 
 of *connect *definition:
 ...
 self._unlock(response)   # -  *unconditional unlock *session file witch 
 have a name == response.session_id
 ...

 Then I  changed definition of ajx_bug(): form=SQLFORM.factory(Field('
 any', *comment=response.session_id* ), table_name=form_name)
 and here is I got:

 Many Ajx Form
 ajx_frm_0:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_1:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_2:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350






 All ajax responses have the same response_id! i.e. each ajax-process can 
 unlock session file locked by another!
 In other words, requests parallel processing works properly across 
 sessions, but  not 

[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-11 Thread Val K
Yes! you're right,  after installation pywin32 my test works properly!  
Thank you!

P.S. I think that would be better to copy/paste that Attention from 
Overview  to Session chapter and make it more *impressive*
I suppose there are many people (like me) who have read an Overview once 
and never again. 






On Tuesday, August 11, 2015 at 5:25:34 PM UTC+3, Anthony wrote:

 Probably you are running web2py from source with your own Python 
 installation and have not installed the pywin32 
 http://sourceforge.net/projects/pywin32/ extension (which is required 
 for file locking). This is mentioned in the book: 
 http://web2py.com/books/default/chapter/29/03/overview?search=win32.

 For more details, see 
 https://docs.python.org/2.7/using/windows.html#pywin32

 Anthony

 On Monday, August 10, 2015 at 8:06:12 PM UTC-4, Val K wrote:

 As I see, the problem is that ajax request (may be not ajax only) didn't 
 wait for closing session file by another one and read/save data from/to it 
 at any time! Lock did not work on my Win7 because , as I think, for Win 
 it's one  process.
 Request processing may be not pure parallel but fully asynchronous  - I 
 placed some print statement in ajax controller and got full chaos - among 
 print from one request were one from another.
 Here is my littlle test. 3 ajax calls start at once but finish 
  asynchronously (time.sleep()).   By change time.sleep() it's possible to 
 get any order (I did start first - finish last). At the end of all 
 session contains only vars/changes of ajax which finish last.



 import time

 # it's a funny AJAX test
 #just create new app and paste it in the default controller
 # call   .../default/many_ajx_form

 def ajx_bug():
 if request.args(0)=='0':
 time.sleep(10) # well, now wait until fish fall asleep in the pond
 session.req_0='Only req_0 ... nothing else!!! Where are req_1, 
 req_2 and other kids? It seems, that guys ignored my session lock?'
 elif request.args(0)=='1':
 time.sleep(5) 
 session.req_1='I killed req_2 and created req_1 which will be 
 killed by req_0 !'
 else:
 session.req_2='I created req_2'
 response.flash=click 'Print Session' !
 if request.args(0)=='0':
 return dict(ret='Better late than never')
 else:
 return dict(ret='completed req_%s'%request.args(0))

 def print_session():
 lst=[]
 for k,v in session.items():
 lst.append(DIV(
 DIV(k,_class='col-xs-2', 
 _style=font-weight:bold;  text-align:right; min-height:50px),
 DIV(':',_class='col-xs-1'),
 DIV(v,_class='col-xs-9'),
 _class='row'
)
   )
 return dict(r=DIV(*lst, _class=container, _style=max-width:800px))



 # CALL THIS 
 def many_ajx_form():
 session.clear() #  - for clear test
 session.dummy_data = 'dummy data'   # make some action for sure init 
 session 
 ret={}
 for i in xrange(3):
 ret['ajx_frm_%s'%i]= \
 DIV(
 LOAD('default','ajx_bug.load',
  args=[i],
  ajax=True,
  target='cont_%s'%i
  ),
 _id='cont_%s'%i
)
 
 btn_prnt=DIV(BUTTON(Print Session, _type=button,_class=btn 
 btn-default,
_onclick=myLOAD_any(default,print_session, 
 target=lst)),
  DIV(_id=lst) 
 )
 
 ret['z']=btn_prnt
 
 return ret

 #return string, no SCRIPT tag!
 def myLOAD_any(contrl, fun, target, args=None, vars=None, ):

 if vars:
 vars_str='?'
 for k,v  in vars.items():
 vars_str+=('%s=%s'%(k,v))
 vars_str= vars_str[:-1] # remove last ''
 else:
 vars_str=''
 if args:
 args_str='/'.join([str(it) for it  in args])
 else:
 args_str=''
 data=dict(
rmt= /%s/%s/%s.load/%s%s%(request.application, contrl, fun, 
 args_str, vars_str ),
trg=target
 )
 load_str=$.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
 $(#%(trg)s));
 return load_str%data







 On Monday, August 10, 2015 at 4:05:57 AM UTC+3, Anthony wrote:

 All responses within the same session are supposed to have the same 
 session_id. The fact that all three Ajax requests can access the session 
 doesn't necessarily mean they are being processed in parallel (the requests 
 might still be completing one after another).

 It would be helpful if you could attach a minimal app that demonstrates 
 the problem.

 Anthony

 On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:

 I realize your advice - no effect!
 I analyzed *session.connect* and found  strange  place at the biginig 
 of *connect *definition:
 ...
 self._unlock(response)   # -  *unconditional unlock *session file 
 witch have a name == response.session_id
 ...

 Then I  

[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-10 Thread Val K
As I see, the problem is that ajax request (may be not ajax only) didn't 
wait for closing session file by another one and read/save data from/to it 
at any time! Lock did not work on my Win7 because , as I think, for Win 
it's one  process.
Request processing may be not pure parallel but fully asynchronous  - I 
placed some print statement in ajax controller and got full chaos - among 
print from one request were one from another.
Here is my littlle test. 3 ajax calls start at once but finish 
 asynchronously (time.sleep()).   By change time.sleep() it's possible to 
get any order (I did start first - finish last). At the end of all 
session contains only vars/changes of ajax which finish last.
   


import time

# it's a funny AJAX test
#just create new app and paste it in the default controller
# call   .../default/many_ajx_form

def ajx_bug():
if request.args(0)=='0':
time.sleep(10) # well, now wait until fish fall asleep in the pond
session.req_0='Only req_0 ... nothing else!!! Where are req_1, 
req_2 and other kids? It seems, that guys ignored my session lock?'
elif request.args(0)=='1':
time.sleep(5) 
session.req_1='I killed req_2 and created req_1 which will be 
killed by req_0 !'
else:
session.req_2='I created req_2'
response.flash=click 'Print Session' !
if request.args(0)=='0':
return dict(ret='Better late than never')
else:
return dict(ret='completed req_%s'%request.args(0))

def print_session():
lst=[]
for k,v in session.items():
lst.append(DIV(
DIV(k,_class='col-xs-2', _style=font-weight:bold; 
 text-align:right; min-height:50px),
DIV(':',_class='col-xs-1'),
DIV(v,_class='col-xs-9'),
_class='row'
   )
  )
return dict(r=DIV(*lst, _class=container, _style=max-width:800px))



# CALL THIS 
def many_ajx_form():
session.clear() #  - for clear test
session.dummy_data = 'dummy data'   # make some action for sure init 
session 
ret={}
for i in xrange(3):
ret['ajx_frm_%s'%i]= \
DIV(
LOAD('default','ajx_bug.load',
 args=[i],
 ajax=True,
 target='cont_%s'%i
 ),
_id='cont_%s'%i
   )

btn_prnt=DIV(BUTTON(Print Session, _type=button,_class=btn 
btn-default,
   _onclick=myLOAD_any(default,print_session, 
target=lst)),
 DIV(_id=lst) 
)

ret['z']=btn_prnt

return ret

#return string, no SCRIPT tag!
def myLOAD_any(contrl, fun, target, args=None, vars=None, ):

if vars:
vars_str='?'
for k,v  in vars.items():
vars_str+=('%s=%s'%(k,v))
vars_str= vars_str[:-1] # remove last ''
else:
vars_str=''
if args:
args_str='/'.join([str(it) for it  in args])
else:
args_str=''
data=dict(
   rmt= /%s/%s/%s.load/%s%s%(request.application, contrl, fun, 
args_str, vars_str ),
   trg=target
)
load_str=$.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
$(#%(trg)s));
return load_str%data







On Monday, August 10, 2015 at 4:05:57 AM UTC+3, Anthony wrote:

 All responses within the same session are supposed to have the same 
 session_id. The fact that all three Ajax requests can access the session 
 doesn't necessarily mean they are being processed in parallel (the requests 
 might still be completing one after another).

 It would be helpful if you could attach a minimal app that demonstrates 
 the problem.

 Anthony

 On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:

 I realize your advice - no effect!
 I analyzed *session.connect* and found  strange  place at the biginig of 
 *connect *definition:
 ...
 self._unlock(response)   # -  *unconditional unlock *session file witch 
 have a name == response.session_id
 ...

 Then I  changed definition of ajx_bug(): form=SQLFORM.factory(Field('
 any', *comment=response.session_id* ), table_name=form_name)
 and here is I got:

 Many Ajx Form
 ajx_frm_0:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_1:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_2:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350






 All ajax responses have the same response_id! i.e. each ajax-process can 
 unlock session file locked by another!
 In other words, requests parallel processing works properly across 
 sessions, but  not within one session, because all responses within session 
 have the same response_id
 It seems, that file is not locked across parallel process (on my Win7 at 
 least), may because it is children of one parent or something else?



 On Sunday, August 9, 2015 at 3:28:04 PM UTC+3, Anthony wrote:

 Does the problem occur only on the first page load of the session? If 
 

[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-09 Thread Val K
Hi!
I have the same problem (twice submission). Here is my little test:

#paste in default.py
#!!! for pure test clean cookies before run!!!

def print_form_keys():
ret=DIV(_class=container)
for i in xrange(5):
frm_k= '_formkey[%s]' % ('frm_id%s/create'%i) #- see html.FORM
ret.append( DIV( frm_k,
OL(*(session[frm_k] or ['None']))
)
  )
return dict(r=ret)

def ajx_bug():
form_name='frm_id%s'%request.args(0)
form=SQLFORM.factory(Field('any'), table_name=form_name)
if form.process(session=session).accepted:
response.flash=form.vars.any
return dict(form=form)

# CALL THIS 
def many_ajx_form():
ret={}
for i in xrange(5):
ret['ajx_frm_%s'%i]= \
DIV(
LOAD('utils','ajx_bug.load',
 args=[i],
 ajax=True,
 target='cont_%s'%i
 ),
_id='cont_%s'%i
   )

#--- ajax print session -
data=dict(
   rmt= '/%s/default/print_form_keys.load'%request.application,
   trg='print_session'
 )
scr=SCRIPT(
var i=0
var ajx_forms_num=5
$( document ).ajaxComplete(function(e)
{
print_session();
$(form).submit( print_session);
});

function print_session(e)
 {
if ((++i)==ajx_forms_num)
{
$.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
$(#%(trg)s));
}
 };
%data)
ret['scr']=scr
ret['print']=DIV(_id='print_session')
return ret

Result on local (win7x32, 2.12.1-stable+timestamp.2015.08.07.07.22.06   
(Running 
on Rocket 1.2.6, Python 2.7.9)):

Many Ajx Form
ajx_frm_0:
Any:
ajx_frm_1:
Any:
ajx_frm_2:
Any:
print:
_formkey[frm_id0/create]
   
   1. *None*

_formkey[frm_id1/create]
   
   1. *None*

_formkey[frm_id2/create]
   
   1. *41f6606c-f149-4382-9216-a35d205a3bd*


As seen, only one ajax form (frm_id2) has a formkey and it works properly! 
but other require twice submissions.
 It seems, that during ajax-request session locked for write only but not 
for read!
Keep in mind that browsers starts next  ajax-request before completion of 
previous one.
I put some log-code in  *FORM.accepts*  - it writes session's all formkeys 
every FORM.accepts-call to separated files  (one call - one file) and I got 
the same:
In each file there is only  one (but different) formkey! i.e. each 
ajax-request process has own version of session.
If set session=None   ( *form**.process( session = None )*  )  all works 
fine!



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-09 Thread Anthony
Does the problem occur only on the first page load of the session? If so, 
does the problem go away if you add the following line at the top of the 
many_ajx_form function:

session.dummy_data = 'dummy data'

If that's the case, then this is the same problem diagnosed in the original 
thread, with something like the above as the solution. The problem is not 
that Ajax reads fail to lock the session -- the problem is that at the very 
beginning of the session when the initial set of Ajax requests are made, 
there is no session file to lock at all. Adding some dummy data to the 
session in the parent page will force a session file to be created, so the 
session file will then exist and therefore be locked when the Ajax requests 
come in. Note, this won't work with sessions stored in the DB or in 
cookies, as there is no session locking at all with those methods (you will 
need some other means to avoid session race conditions in those cases).

Anthony



On Sunday, August 9, 2015 at 2:34:48 AM UTC-4, Val K wrote:

 Hi!
 I have the same problem (twice submission). Here is my little test:

 #paste in default.py
 #!!! for pure test clean cookies before run!!!

 def print_form_keys():
 ret=DIV(_class=container)
 for i in xrange(5):
 frm_k= '_formkey[%s]' % ('frm_id%s/create'%i) #- see html.FORM
 ret.append( DIV( frm_k,
 OL(*(session[frm_k] or ['None']))
 )
   )
 return dict(r=ret)

 def ajx_bug():
 form_name='frm_id%s'%request.args(0)
 form=SQLFORM.factory(Field('any'), table_name=form_name)
 if form.process(session=session).accepted:
 response.flash=form.vars.any
 return dict(form=form)

 # CALL THIS 
 def many_ajx_form():
 ret={}
 for i in xrange(5):
 ret['ajx_frm_%s'%i]= \
 DIV(
 LOAD('default','ajx_bug.load',
  args=[i],
  ajax=True,
  target='cont_%s'%i
  ),
 _id='cont_%s'%i
)

 #--- ajax print session -
 data=dict(
rmt= '/%s/default/print_form_keys.load'%request.application,
trg='print_session'
  )
 scr=SCRIPT(
 var i=0
 var ajx_forms_num=5
 $( document ).ajaxComplete(function(e)
 {
 print_session();
 $(form).submit( print_session);
 });

 function print_session(e)
  {
 if ((++i)=ajx_forms_num)
 {
 $.web2py.component(%(rmt)s, %(trg)s, 0, 1, 
 $(#%(trg)s));
 }
  };
 %data)
 ret['scr']=scr
 ret['print']=DIV(_id='print_session')
 return ret

 Result on local (win7x32, 2.12.1-stable+timestamp.2015.08.07.07.22.06   
 (Running 
 on Rocket 1.2.6, Python 2.7.9)):

 Many Ajx Form
 ajx_frm_0:
 Any:


 ajx_frm_1:
 Any:


 ajx_frm_2:
 Any:


 print:
 _formkey[frm_id0/create]

1. *None*

 _formkey[frm_id1/create]

1. *None*

 _formkey[frm_id2/create]

1. *41f6606c-f149-4382-9216-a35d205a3bd*


 As seen, only one ajax form (frm_id2) has a formkey and it works properly! 
 but other require twice submissions.
  It seems, that during ajax-request session locked for write only but not 
 for read!
 Keep in mind that browsers starts next  ajax-request before completion of 
 previous one.
 I put some log-code in  *FORM.accepts*  - it writes session's all 
 formkeys every FORM.accepts-call to separated files  (one call - one file) 
 and I got the same:
 In each file there is only  one (but different) formkey! i.e. each 
 ajax-request process has own version of session.
 If set session=None   ( *form**.process( session = None )*  )  all works 
 fine!





-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-09 Thread Val K
I realize your advice - no effect!
I analyzed *session.connect* and found  strange  place at the biginig of 
*connect *definition:
...
self._unlock(response)   # -  *unconditional unlock *session file witch 
have a name == response.session_id
...

Then I  changed definition of ajx_bug(): form=SQLFORM.factory(Field('any', 
*comment=response.session_id* ), table_name=form_name)
and here is I got:

Many Ajx Form
ajx_frm_0:
Any
127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
ajx_frm_1:
Any
127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
ajx_frm_2:
Any
127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350






All ajax responses have the same response_id! i.e. each ajax-process can 
unlock session file locked by another!
In other words, requests parallel processing works properly across 
sessions, but  not within one session, because all responses within session 
have the same response_id
It seems, that file is not locked across parallel process (on my Win7 at 
least), may because it is children of one parent or something else?



On Sunday, August 9, 2015 at 3:28:04 PM UTC+3, Anthony wrote:

 Does the problem occur only on the first page load of the session? If so, 
 does the problem go away if you add the following line at the top of the 
 many_ajx_form function:

 session.dummy_data = 'dummy data'

 If that's the case, then this is the same problem diagnosed in the 
 original thread, with something like the above as the solution. The problem 
 is not that Ajax reads fail to lock the session -- the problem is that at 
 the very beginning of the session when the initial set of Ajax requests are 
 made, there is no session file to lock at all. Adding some dummy data to 
 the session in the parent page will force a session file to be created, so 
 the session file will then exist and therefore be locked when the Ajax 
 requests come in. Note, this won't work with sessions stored in the DB or 
 in cookies, as there is no session locking at all with those methods (you 
 will need some other means to avoid session race conditions in those cases).

 Anthony







-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-08-09 Thread Anthony
All responses within the same session are supposed to have the same 
session_id. The fact that all three Ajax requests can access the session 
doesn't necessarily mean they are being processed in parallel (the requests 
might still be completing one after another).

It would be helpful if you could attach a minimal app that demonstrates the 
problem.

Anthony

On Sunday, August 9, 2015 at 12:30:01 PM UTC-4, Val K wrote:

 I realize your advice - no effect!
 I analyzed *session.connect* and found  strange  place at the biginig of 
 *connect *definition:
 ...
 self._unlock(response)   # -  *unconditional unlock *session file witch 
 have a name == response.session_id
 ...

 Then I  changed definition of ajx_bug(): form=SQLFORM.factory(Field('
 any', *comment=response.session_id* ), table_name=form_name)
 and here is I got:

 Many Ajx Form
 ajx_frm_0:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_1:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350
 ajx_frm_2:
 Any
 127.0.0.1-dd2c6b6c-3141-4826-8887-ab1691b67350






 All ajax responses have the same response_id! i.e. each ajax-process can 
 unlock session file locked by another!
 In other words, requests parallel processing works properly across 
 sessions, but  not within one session, because all responses within session 
 have the same response_id
 It seems, that file is not locked across parallel process (on my Win7 at 
 least), may because it is children of one parent or something else?



 On Sunday, August 9, 2015 at 3:28:04 PM UTC+3, Anthony wrote:

 Does the problem occur only on the first page load of the session? If so, 
 does the problem go away if you add the following line at the top of the 
 many_ajx_form function:

 session.dummy_data = 'dummy data'

 If that's the case, then this is the same problem diagnosed in the 
 original thread, with something like the above as the solution. The problem 
 is not that Ajax reads fail to lock the session -- the problem is that at 
 the very beginning of the session when the initial set of Ajax requests are 
 made, there is no session file to lock at all. Adding some dummy data to 
 the session in the parent page will force a session file to be created, so 
 the session file will then exist and therefore be locked when the Ajax 
 requests come in. Note, this won't work with sessions stored in the DB or 
 in cookies, as there is no session locking at all with those methods (you 
 will need some other means to avoid session race conditions in those cases).

 Anthony







-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-19 Thread Anthony
Not sure what's going on. I also tried 2.11.2, though on Windows 8.1 x64 
with Python 2.7.6.

On Sunday, July 19, 2015 at 4:57:48 PM UTC-4, 黄祥 wrote:

 strange, in my local, 
 the behaviour make me submit twice for the form in first component (web2py 
 source version 2.11.2, python 2.7.8, windows 7 x64), 
 while i test the same app in pythonanywhere, it didn't make me submit 
 twice for the form in first component (same like yours). 
 already remove the old web2py folder with new extracted from 
 web2py_src.zip, but still got the same result.

 any clue what is the root cause for this?

 thanks and best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-19 Thread 黄祥
strange, in my local, 
the behaviour make me submit twice for the form in first component (web2py 
source version 2.11.2, python 2.7.8, windows 7 x64), 
while i test the same app in pythonanywhere, it didn't make me submit twice 
for the form in first component (same like yours). 
already remove the old web2py folder with new extracted from 
web2py_src.zip, but still got the same result.

any clue what is the root cause for this?

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-19 Thread Anthony
Sorry, I can't reproduce the problem with the attached app. When I go to 
/default/sale_order and select a product (a or b) from the list, set and 
quantity, and hit Submit, the form submits properly, and the table below is 
updated via Ajax with the values I submitted. I do not have to submit the 
form twice.

Anthony

On Tuesday, July 14, 2015 at 5:51:22 PM UTC-4, 黄祥 wrote:

 attached the min app that reproduce an error.
 step i took :
 clean app (sessions, error, cache)
 login and then access the sale_order page (which contain the web2py 
 components)

 problem :
 SQLFORM.factory in first grid, need submit twice to response (either error 
 or accepted)

 environment :
 web2py latest version (source)

 pardon me, if i asked in irrelevant thread, should i create a new thread 
 for this.

 best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-16 Thread 黄祥
1. 
*action :*
after clean app, login, check the response.toolbar() 
*result *: 
no session value, no post_vars and no vars request
2. 
*action *:
fill in the SQLFORM.factory, submit the button, check the response.toolbar()
*result *:
the checkout in second load component is not filled (no session value yet 
the vars and post vars is filled with the value from SQLFORM.factory)
3. 
*action *:
fill in the SQLFORM.factory, submit the button, check the response.toolbar()
*result *:
the second load component have the value, there is vars, post_vars and 
session value in response.toolbar()
4.
after that all is well, the problem is sqlform is need to submit twice to 
get it work or responses (flash, error or fill the session), already tried 
clean app, give the form name, give the session a dummy value e.g. 
session_sale_order[1] = 0, 0

if this is not a bug in load component, perhaps i miss something, or this 
is just the way to use load component with two form with session.

best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-14 Thread Anthony
We need to see all the relevant code -- you haven't shown the link_callback 
code where the session is manipulated.

Anyway, it's not the same problem as the one originally raised in this 
thread -- you don't have two simultaneous Ajax requests writing to the 
session (your Ajax request that affects the session gets called after the 
two Ajax components have loaded and the user interacts with the form), and 
your problem persists throughout the session.

It's still not clear exactly what behavior you are observing. It might help 
if you can produce a simplified example that exhibits the problem, show 
*all* of the relevant code, explain the exact symptoms, and do some 
diagnostic work to see what data are being sent and received with each Ajax 
request, the state of the session at each point, etc.

Anthony

On Tuesday, July 14, 2015 at 1:16:30 AM UTC-4, 黄祥 wrote:

 sale_order_checkout use ajax callback to modify session.sale_order value, 
 that is in the form in the HTML (not web2py form)

 the form that must submit twice is the one in the first component : 
 sale_order_form which is generated via SQLFORM.factory.
 the form in second component is responsive (ajax callback is update 
 everytime i change the value)

 Already check the developer tools and request.toolbar() for that, after 
 clean all session, access sale_order the value of session.sale_order is 
 empty, in order to fill the session, i must hit submit twice for fill the 
 session, or receive form.errors (after first time hit the submit button, 
 the session value is still empty). 

 another funny reaction is, after clean all session, access the page with 2 
 components, hit submit once, after that refresh the page (page with 2 
 components), i must submit twice again to get the form react (either error 
 or accepted)

 i use web2py latest version, in win 7 64, test in chrome in firefox latest 
 version

 not sure which part i missed to get it work.

 thanks and best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread Anthony
I may be missing something, but I still don't see where sale_order_checkout 
touches the session (it has a form in the HTML, but it is not a web2py form 
with a _formkey token, so it doesn't use the session). I don't think your 
problem is the same as the one discussed in this thread.

Which of the two forms do you have to submit twice? More diagnostic info 
would be helpful (i.e., check developer tools in the browser and inspect 
request.vars, etc. on server when the form is submitted each time).

Anthony

On Monday, July 13, 2015 at 7:57:22 PM UTC-4, 黄祥 wrote:

 already tried to write the dummy session data in (sale_order and 
 sale_order_form) but still same (need submit twice), yet i got some bonus, 
 traceback error said :

 AttributeError: 'str' object has no attribute 'items'


 *controllers/default.py*
 def sale_order():
 session.sale_order = 'test'
 return locals()

 def sale_order_form():
 session.sale_order = 'test'
 form = SQLFORM.factory(
 Field('product', 'reference product', 
   requires = IS_IN_DB(db((db.product.
 quantity  0) ), 
   db.product.id, db.product._format) ),
 Field('quantity', 'integer', requires = IS_NOT_EMPTY() ), 
 )
 if form.process(formname = 'myform1').accepted:
 response.flash = T('Form accepted')
 
 id = int(request.vars.product)
 
 row = db(db.product.id == id).select().first()
 
 quantity = int(request.vars.quantity)
 price = int(row.selling_price)
 session.sale_order[id] = quantity, price
 
 response.js =  jQuery('#sale_order_checkout').get(0).reload()
 elif form.errors:
 response.flash = T('Form has errors')
 return dict(form = form)

 *views/default/sale_order_checkout.load*
 {{total_quantity = 0 }}
 {{grand_total = 0 }}

 table class = table table-condensed table-hover
 tr
 th{{=T('Product') }}/th
 th{{=T('Price') }}/th
 th{{=T('Quantity') }}/th
 th{{=T('Total Price') }}/th
 th{{=T('Action') }}/td
 /tr
 {{for id, (quantity, price) in session_detail.items():}}
 {{product = db.product(id) }}
 {{total_price = quantity * price}}
 {{total_quantity += quantity}}
 {{grand_total += total_price}}
 tr
 td
 {{=SPAN(product.name) }}
 /td
 td{{=SPAN('Rp. %s' % format(price, ,d).replace(,, .) ) 
 }}/td
 td
 form
 input name = {{='quantity_%s' % id}} value = 
 {{=quantity}} 
 onkeyup = ajax('{{=URL(link_callback, vars = dict(id = 
 id, price = price, 
 action = 'adjust_total') ) }}', ['{{='quantity_%s' % 
 id}}'], ':eval' ) /
 /form
 /td
 tdRp. {{=SPAN('%s' % format(total_price, ,d).replace(,, 
 .), _id = 'total_price_%s' % id) }}/td
 td
 {{=SPAN(A(I(_class = 'glyphicon glyphicon-remove-sign'), 
 callback = URL(link_callback, 
 vars = dict(id = id, action = 'remove') ), delete = 
 'tr', 
 _title = 'Remove %s' % product.name) ) }}
 /td
 /tr
 {{pass}}
 tr
 td/td
 td{{=B(T('Grand Total') ) }}/td
 td{{=SPAN('%s' % format(total_quantity, ,d).replace(,, .), 
 _id = 'total_quantity') }}/td
 tdRp. {{=SPAN('%s' % format(grand_total, ,d).replace(,, 
 .), _id = 'grand_total') }}/td
 td/td
 /tr
 /table

 {{=SPAN(A(T('Empty'), _href = URL(link_empty), _title = 'Empty', 
   _onclick = javascript:return confirm('Are you sure you want to 
 empty?'), 
   _class = 'btn btn-info') ) }}

 best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread Anthony
It's not clear this is the same problem, as you have only one form in a 
component, and the other component doesn't appear to save to the session. 
Read through the thread to repeat the diagnostics and see if you really are 
observing the same behavior (which implies the second component is saving 
something to the session). If so, the workaround is to have the parent 
action save some dummy data to the session in order to create a session 
file (which will be locked on the subsequent Ajax requests, preventing the 
race condition). If you have your sessions in the database or in cookies, 
then your out of luck, as they cannot be locked.

Anthony

On Monday, July 13, 2015 at 10:25:15 AM UTC-4, 黄祥 wrote:

 i face the same situation, already use the formname and clear session. the 
 form must submit twice to get it work.
 e.g.
 *controllers/default.py*
 def sale_order():
 return locals()

 def sale_order_form():
 form = SQLFORM.factory(
 Field('product', 'reference product', 
   requires = IS_IN_DB(db((db.product.quantity  0) ), 
   db.product.id, db.product._format) ),
 Field('quantity', 'integer', requires = IS_NOT_EMPTY() ), 
 )
 if form.process(formname = 'myform1').accepted:
 response.flash = T('Form accepted')
 
 id = int(request.vars.product)
 
 row = db(db.product.id == id).select().first()
 
 quantity = int(request.vars.quantity)
 price = int(row.selling_price)
 session.sale_order[id] = quantity, price
 
 response.js =  jQuery('#sale_order_checkout').get(0).reload()
 elif form.errors:
 response.flash = T('Form has errors')
 return dict(form = form)

 def sale_order_checkout():
 link_callback = 'sale_order_callback'
 link_empty = 'sale_order_empty'
 return dict(session_detail = session.sale_order, link_callback = 
 link_callback, 
 link_empty = link_empty)

 *views/default/sale_order.html*
 {{extend 'layout.html'}}

 {{=LOAD('default', 'sale_order_form.load', ajax = True, 
 target = 'sale_order_form') }}

 {{=LOAD('default', 'sale_order_checkout.load', ajax = True, 
 target = 'sale_order_checkout') }}

 *views/default/sale_order_form.load*
 {{=form}}

 any idea how to face this?

 thanks and best regards,
 stifan

 On Tuesday, April 23, 2013 at 7:09:51 PM UTC+7, Anthony wrote:


 What to do about this? I suppose one option would be to always create a 
 new session file when a new session is started, even if the session is 
 empty on the first request of the session (in the above example, an empty 
 session file would be created on accessing the index page). Some apps 
 never 
 use the session, though, and would therefore have a bunch of unnecessary 
 session files (though I suppose you could still use the global settings to 
 turn off sessions).


 turning to the old system makes me sick  sad . Creating a session 
 only when it's needed is the right thing to do© .


 The above suggestion isn't quite going back to the old system. In the old 
 system, the session file was created on the first request (of a new browser 
 session) *and* re-written on every request (even if it didn't change) -- 
 the latter was more a source of inefficiency than the former. The above 
 suggestion would return to creating the session file on the first request, 
 but it would not re-write the session on every request. Anyway, I'm not 
 saying we should necessarily take this approach, just spelling out the 
 issues and options.
  

 Another option is to leave it up to the developer to save something to 
 the session in the parent page request when the page contains multiple 
 Ajax 
 requests that will be accessing the session. Maybe we could provide a 
 convenience method for this, such as session.save(), which would force 
 saving the file even if the session is empty (such a method might have 
 other uses, such as saving and then unlocking a session in the middle of a 
 request).


 wouldn't a simple note in the book close the deal ?


 Saving dummy data to the session feels like a hack, so I think a new 
 method like session.save() would be nice.
  

 I think there's a bigger problem with sessions in cookies and the db -- 
 they aren't locked at all, so you can get race conditions with them even 
 once the session has initially been saved.

 it's a problem in general: either you want concurrency or you want 
 locking. can we even theoretically solve that problem ? I don't think 
 so. 


 I think with sessions we generally want locking (or at least the option 
 to lock) -- in order to avoid race conditions (presumably that's why 
 locking the file-based sessions was implemented to begin with). When 
 storing sessions in the db, the table definition does include a locked 
 field, but it is not used -- there is this commented line in 
 session.connect():

 # rows[0].update_record(locked=True)

 

[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread 黄祥
i face the same situation, already use the formname and clear session. the 
form must submit twice to get it work.
e.g.
*controllers/default.py*
def sale_order():
return locals()

def sale_order_form():
form = SQLFORM.factory(
Field('product', 'reference product', 
  requires = IS_IN_DB(db((db.product.quantity  0) ), 
  db.product.id, db.product._format) ),
Field('quantity', 'integer', requires = IS_NOT_EMPTY() ), 
)
if form.process(formname = 'myform1').accepted:
response.flash = T('Form accepted')

id = int(request.vars.product)

row = db(db.product.id == id).select().first()

quantity = int(request.vars.quantity)
price = int(row.selling_price)
session.sale_order[id] = quantity, price

response.js =  jQuery('#sale_order_checkout').get(0).reload()
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

def sale_order_checkout():
link_callback = 'sale_order_callback'
link_empty = 'sale_order_empty'
return dict(session_detail = session.sale_order, link_callback = 
link_callback, 
link_empty = link_empty)

*views/default/sale_order.html*
{{extend 'layout.html'}}

{{=LOAD('default', 'sale_order_form.load', ajax = True, 
target = 'sale_order_form') }}

{{=LOAD('default', 'sale_order_checkout.load', ajax = True, 
target = 'sale_order_checkout') }}

*views/default/sale_order_form.load*
{{=form}}

any idea how to face this?

thanks and best regards,
stifan

On Tuesday, April 23, 2013 at 7:09:51 PM UTC+7, Anthony wrote:


 What to do about this? I suppose one option would be to always create a 
 new session file when a new session is started, even if the session is 
 empty on the first request of the session (in the above example, an empty 
 session file would be created on accessing the index page). Some apps never 
 use the session, though, and would therefore have a bunch of unnecessary 
 session files (though I suppose you could still use the global settings to 
 turn off sessions).


 turning to the old system makes me sick  sad . Creating a session only 
 when it's needed is the right thing to do© .


 The above suggestion isn't quite going back to the old system. In the old 
 system, the session file was created on the first request (of a new browser 
 session) *and* re-written on every request (even if it didn't change) -- 
 the latter was more a source of inefficiency than the former. The above 
 suggestion would return to creating the session file on the first request, 
 but it would not re-write the session on every request. Anyway, I'm not 
 saying we should necessarily take this approach, just spelling out the 
 issues and options.
  

 Another option is to leave it up to the developer to save something to 
 the session in the parent page request when the page contains multiple Ajax 
 requests that will be accessing the session. Maybe we could provide a 
 convenience method for this, such as session.save(), which would force 
 saving the file even if the session is empty (such a method might have 
 other uses, such as saving and then unlocking a session in the middle of a 
 request).


 wouldn't a simple note in the book close the deal ?


 Saving dummy data to the session feels like a hack, so I think a new 
 method like session.save() would be nice.
  

 I think there's a bigger problem with sessions in cookies and the db -- 
 they aren't locked at all, so you can get race conditions with them even 
 once the session has initially been saved.

 it's a problem in general: either you want concurrency or you want 
 locking. can we even theoretically solve that problem ? I don't think 
 so. 


 I think with sessions we generally want locking (or at least the option to 
 lock) -- in order to avoid race conditions (presumably that's why locking 
 the file-based sessions was implemented to begin with). When storing 
 sessions in the db, the table definition does include a locked field, but 
 it is not used -- there is this commented line in session.connect():

 # rows[0].update_record(locked=True)

 Maybe that can be used. Not sure what to do about cookie-based sessions.

 More generally, maybe we could allow more control over session locking by 
 adding a lock argument to session.connect(). Those who want to take 
 advantage of the option could globally disable automatic sessions and 
 manually open the session via session.connect() in the app (choosing 
 whether to do so with or without locking, depending on whether it matters 
 for the particular action).

 Anthony



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.

[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread 黄祥
sale_order_checkout use ajax callback to modify session.sale_order value, 
that is in the form in the HTML (not web2py form)

the form that must submit twice is the one in the first component : 
sale_order_form which is generated via SQLFORM.factory.
the form in second component is responsive (ajax callback is update 
everytime i change the value)

Already check the developer tools and request.toolbar() for that, after 
clean all session, access sale_order the value of session.sale_order is 
empty, in order to fill the session, i must hit submit twice for fill the 
session, or receive form.errors (after first time hit the submit button, 
the session value is still empty). 

another funny reaction is, after clean all session, access the page with 2 
components, hit submit once, after that refresh the page (page with 2 
components), i must submit twice again to get the form react (either error 
or accepted)

i use web2py latest version, in win 7 64, test in chrome in firefox latest 
version

not sure which part i missed to get it work.

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread 黄祥
hm, sorry, when i open in google groups it appears in web2py-users but in 
gmail i received it from web2py-developers. k, back to the problems. in 
web2py-users first report said :

If the form has errors, the error messages are displayed after a 
second submit. So, I need to click two times the submit button to 
display them.

the condition i face is : i have 2 components, first is form to fill the 
product in session (SQLFORM.factory), the second is the checkout which is 
again have a form that have a function to modify the session via ajax 
callback.

the problem is : if the form has errors the error messages are displayed 
after a second submit, same for if the form is accepted, the data in form 
are save in session after a second submit, so, i need to click submit two 
times.

for session i have it on files not in database, and for dummy data, i'm not 
sure i'm getting it, because it's the order, i can't create the dummy data 
in the session, cause it can affect the total price. still about session, 
already check with response.toolbar() seems that the first time i land it 
is there with no value
e.g.
sale_order:


after second submit
sale_order:
1:
2
2

any idea why the form in first component must submit twice to response 
either error or accepted?

thanks and best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread 黄祥
already tried to write the dummy session data in (sale_order and 
sale_order_form) but still same (need submit twice), yet i got some bonus, 
traceback error said :

AttributeError: 'str' object has no attribute 'items'


*controllers/default.py*
def sale_order():
session.sale_order = 'test'
return locals()

def sale_order_form():
session.sale_order = 'test'
form = SQLFORM.factory(
Field('product', 'reference product', 
  requires = IS_IN_DB(db((db.product.
quantity  0) ), 
  db.product.id, db.product._format) ),
Field('quantity', 'integer', requires = IS_NOT_EMPTY() ), 
)
if form.process(formname = 'myform1').accepted:
response.flash = T('Form accepted')

id = int(request.vars.product)

row = db(db.product.id == id).select().first()

quantity = int(request.vars.quantity)
price = int(row.selling_price)
session.sale_order[id] = quantity, price

response.js =  jQuery('#sale_order_checkout').get(0).reload()
elif form.errors:
response.flash = T('Form has errors')
return dict(form = form)

*views/default/sale_order_checkout.load*
{{total_quantity = 0 }}
{{grand_total = 0 }}

table class = table table-condensed table-hover
tr
th{{=T('Product') }}/th
th{{=T('Price') }}/th
th{{=T('Quantity') }}/th
th{{=T('Total Price') }}/th
th{{=T('Action') }}/td
/tr
{{for id, (quantity, price) in session_detail.items():}}
{{product = db.product(id) }}
{{total_price = quantity * price}}
{{total_quantity += quantity}}
{{grand_total += total_price}}
tr
td
{{=SPAN(product.name) }}
/td
td{{=SPAN('Rp. %s' % format(price, ,d).replace(,, .) ) 
}}/td
td
form
input name = {{='quantity_%s' % id}} value = 
{{=quantity}} 
onkeyup = ajax('{{=URL(link_callback, vars = dict(id = id, 
price = price, 
action = 'adjust_total') ) }}', ['{{='quantity_%s' % 
id}}'], ':eval' ) /
/form
/td
tdRp. {{=SPAN('%s' % format(total_price, ,d).replace(,, .), 
_id = 'total_price_%s' % id) }}/td
td
{{=SPAN(A(I(_class = 'glyphicon glyphicon-remove-sign'), 
callback = URL(link_callback, 
vars = dict(id = id, action = 'remove') ), delete = 
'tr', 
_title = 'Remove %s' % product.name) ) }}
/td
/tr
{{pass}}
tr
td/td
td{{=B(T('Grand Total') ) }}/td
td{{=SPAN('%s' % format(total_quantity, ,d).replace(,, .), 
_id = 'total_quantity') }}/td
tdRp. {{=SPAN('%s' % format(grand_total, ,d).replace(,, .), 
_id = 'grand_total') }}/td
td/td
/tr
/table

{{=SPAN(A(T('Empty'), _href = URL(link_empty), _title = 'Empty', 
  _onclick = javascript:return confirm('Are you sure you want to 
empty?'), 
  _class = 'btn btn-info') ) }}

best regards,
stifan

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2015-07-13 Thread Anthony
Did you leave out some code, because the code you have shown for 
sale_order_checkout includes no form nor any writing to the session?

The idea of the dummy data is just to write some nonsense data to the 
session in the *parent* function:

def sale_order():
session.dummy = 'dummy data'
...

That will force a session file to be created when the parent page is 
loaded. Once a session file exists, it will be locked by each Ajax request, 
so there will be no race condition caused by the simultaneous Ajax requests.

Note, if this is the problem, it should only appear when you are starting a 
new session. Once you have visited a page that saves to the session and a 
session file has been created, there should be no subsequent problems 
during the same session. If you observe the same problem happening 
repeatedly during the same session, then something else is going on.

Anthony

On Monday, July 13, 2015 at 5:20:00 PM UTC-4, 黄祥 wrote:

 hm, sorry, when i open in google groups it appears in web2py-users but in 
 gmail i received it from web2py-developers. k, back to the problems. in 
 web2py-users first report said :

 If the form has errors, the error messages are displayed after a 
 second submit. So, I need to click two times the submit button to 
 display them.

 the condition i face is : i have 2 components, first is form to fill the 
 product in session (SQLFORM.factory), the second is the checkout which is 
 again have a form that have a function to modify the session via ajax 
 callback.

 the problem is : if the form has errors the error messages are displayed 
 after a second submit, same for if the form is accepted, the data in form 
 are save in session after a second submit, so, i need to click submit two 
 times.

 for session i have it on files not in database, and for dummy data, i'm 
 not sure i'm getting it, because it's the order, i can't create the dummy 
 data in the session, cause it can affect the total price. still about 
 session, already check with response.toolbar() seems that the first time i 
 land it is there with no value
 e.g.
 sale_order:


 after second submit
 sale_order:
 1:
 2
 2

 any idea why the form in first component must submit twice to response 
 either error or accepted?

 thanks and best regards,
 stifan


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-23 Thread Neil
Thanks Niphlod  Anthony - I'm glad we finally got to the bottom of this. I 
thought I was going crazy for a while there!

In the short term, I'll use Niphlod's trick of setting a dummy session 
variable to make sure the session is saved to disk. 

In the medium term, I vote for option 1 (always saving a session file, even 
if session is empty). As we've seen, the current logic can lead to 
unpredictable behavior (I still can't reproduce on my Ubuntu netbook - my 
best guess is that since it is old and slow, the ajax requests 
aren't overlapping). I'd say it is a little risky to rely on the developer 
to remember to add initialization code to every page that contains 2+ 
ajax components. It is easy to lose track of that sort of thing. On the 
other hand, allowing a developer to turn off sessions in general is a good 
optimization for those who know what they are doing.

On Tuesday, 23 April 2013 03:00:11 UTC+1, Anthony wrote:

 The problem is that we made a change so that no session file is created at 
 all if this is a new session and the session remains empty. So, when the 
 index page is requested, no session file is created. Next, the form1 Ajax 
 request comes in, and because there is no session file, there is nothing to 
 read or lock. Meanwhile, the form2 Ajax request comes in, and again, there 
 is no file to read or lock. So, both requests start with an empty session 
 and add their respective formkeys to it. Next, the form1 request creates a 
 session file and writes its version of the session to it. Finally, the 
 form2 request opens and completely overwrites that session file with its 
 version of the session (which does not include the form1 formkey).

 What to do about this? I suppose one option would be to always create a 
 new session file when a new session is started, even if the session is 
 empty on the first request of the session (in the above example, an empty 
 session file would be created on accessing the index page). Some apps never 
 use the session, though, and would therefore have a bunch of unnecessary 
 session files (though I suppose you could still use the global settings to 
 turn off sessions).

 Another option is to leave it up to the developer to save something to the 
 session in the parent page request when the page contains multiple Ajax 
 requests that will be accessing the session. Maybe we could provide a 
 convenience method for this, such as session.save(), which would force 
 saving the file even if the session is empty (such a method might have 
 other uses, such as saving and then unlocking a session in the middle of a 
 request).

 Other ideas?

 I think there's a bigger problem with sessions in cookies and the db -- 
 they aren't locked at all, so you can get race conditions with them even 
 once the session has initially been saved.

 Anthony

 On Monday, April 22, 2013 4:59:16 PM UTC-4, Niphlod wrote:

 umpf I can't understand why this is not working ok.

 The problem lies indeed in the fact that one ajax request overwrites the 
 session, if the session file is not there yet. 
 I can only guess that the logic is failing to acquire a lock before 
 creating the (new) file 
 If a request has completed yet, hence the session file is present, all 
 goes perfectly ok (it's probably the reason why nobody else ever noticed 
 the glitch, and why prepending a session.hello = 'world' to the index 
 function makes all go smoothly, it actually creates the session file before 
 the two ajax requests come in)
 can anyone testing this confirm this behaviour?
 steps to reproduce:
 - delete session file in the session/ dir
 - open the index page
 - session file ends up with one or another formname keys, never both
 - reload the page
 - session file holds both formnames
 - put session.hello = 'world' in the index() function before the return 
 dict()
 - delete the session file in the sessions/ dir
 - reload the page
 - session file holds both formnames

 If this is indeed the behaviour, we narrowed it down to a glitch that 
 happens in one case only: 2 concurrent requests comes in and there is no 
 session file yet.
 We can start from there to coordinate efforts for the patch. it's 
 definitely not an issue with javascript.




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-23 Thread Niphlod


On Tuesday, April 23, 2013 4:00:11 AM UTC+2, Anthony wrote:

 The problem is that we made a change so that no session file is created at 
 all if this is a new session and the session remains empty. So, when the 
 index page is requested, no session file is created. Next, the form1 Ajax 
 request comes in, and because there is no session file, there is nothing to 
 read or lock. Meanwhile, the form2 Ajax request comes in, and again, there 
 is no file to read or lock. So, both requests start with an empty session 
 and add their respective formkeys to it. Next, the form1 request creates a 
 session file and writes its version of the session to it. Finally, the 
 form2 request opens and completely overwrites that session file with its 
 version of the session (which does not include the form1 formkey).


ok, that's consistent with what observed
 


 What to do about this? I suppose one option would be to always create a 
 new session file when a new session is started, even if the session is 
 empty on the first request of the session (in the above example, an empty 
 session file would be created on accessing the index page). Some apps never 
 use the session, though, and would therefore have a bunch of unnecessary 
 session files (though I suppose you could still use the global settings to 
 turn off sessions).


turning to the old system makes me sick  sad . Creating a session only 
when it's needed is the right thing to do© .
 


 Another option is to leave it up to the developer to save something to the 
 session in the parent page request when the page contains multiple Ajax 
 requests that will be accessing the session. Maybe we could provide a 
 convenience method for this, such as session.save(), which would force 
 saving the file even if the session is empty (such a method might have 
 other uses, such as saving and then unlocking a session in the middle of a 
 request).


wouldn't a simple note in the book close the deal ? This happens only when 
there is no session file and the user concurrently requests something that 
needs to be saved to session. In any case, leaving up to the developer is 
the right choice.
 


 Other ideas?

 I think there's a bigger problem with sessions in cookies and the db -- 
 they aren't locked at all, so you can get race conditions with them even 
 once the session has initially been saved.

 Anthony


it's a problem in general: either you want concurrency or you want 
locking. can we even theoretically solve that problem ? I don't think 
so.
 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-23 Thread Anthony


 What to do about this? I suppose one option would be to always create a 
 new session file when a new session is started, even if the session is 
 empty on the first request of the session (in the above example, an empty 
 session file would be created on accessing the index page). Some apps never 
 use the session, though, and would therefore have a bunch of unnecessary 
 session files (though I suppose you could still use the global settings to 
 turn off sessions).


 turning to the old system makes me sick  sad . Creating a session only 
 when it's needed is the right thing to do© .


The above suggestion isn't quite going back to the old system. In the old 
system, the session file was created on the first request (of a new browser 
session) *and* re-written on every request (even if it didn't change) -- 
the latter was more a source of inefficiency than the former. The above 
suggestion would return to creating the session file on the first request, 
but it would not re-write the session on every request. Anyway, I'm not 
saying we should necessarily take this approach, just spelling out the 
issues and options.
 

 Another option is to leave it up to the developer to save something to the 
 session in the parent page request when the page contains multiple Ajax 
 requests that will be accessing the session. Maybe we could provide a 
 convenience method for this, such as session.save(), which would force 
 saving the file even if the session is empty (such a method might have 
 other uses, such as saving and then unlocking a session in the middle of a 
 request).


 wouldn't a simple note in the book close the deal ?


Saving dummy data to the session feels like a hack, so I think a new method 
like session.save() would be nice.
 

 I think there's a bigger problem with sessions in cookies and the db -- 
 they aren't locked at all, so you can get race conditions with them even 
 once the session has initially been saved.

 it's a problem in general: either you want concurrency or you want 
 locking. can we even theoretically solve that problem ? I don't think 
 so. 


I think with sessions we generally want locking (or at least the option to 
lock) -- in order to avoid race conditions (presumably that's why locking 
the file-based sessions was implemented to begin with). When storing 
sessions in the db, the table definition does include a locked field, but 
it is not used -- there is this commented line in session.connect():

# rows[0].update_record(locked=True)

Maybe that can be used. Not sure what to do about cookie-based sessions.

More generally, maybe we could allow more control over session locking by 
adding a lock argument to session.connect(). Those who want to take 
advantage of the option could globally disable automatic sessions and 
manually open the session via session.connect() in the app (choosing 
whether to do so with or without locking, depending on whether it matters 
for the particular action).

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Thanks for that. Unfortunately, there seems to be a little more to it. 

He is a minimal example (using web2py 2.4.6/rocket/windows, although 
the behavior is the same with other configurations).

controllers/default.py:

def index():
return dict()

def f1():
val1 = 
form1 = FORM('Form 1 input:', INPUT(_name='f1input', requires=
IS_NOT_EMPTY()), INPUT(_type='submit'))
if form1.accepts(request,session,formname=formname1):
val1 = form1.vars.f1input
elif form1.errors:
response.flash = 'Form 1 has errors'
return dict(form1=form1, val1=val1)

def f2():
val2 = 
form2 = FORM('Form 2 input:', INPUT(_name='f2input', requires=
IS_NOT_EMPTY()), INPUT(_type='submit'))
if form2.accepts(request,session,formname=formname2):
val2 = form2.vars.f2input
elif form2.errors:
response.flash = 'Form 2 has errors'
return dict(form2=form2, val2=val2)

views/default/f1.load:

p{{=val1}}/p
{{=form1}}

views/default/f2.load:

p{{=val2}}/p
{{=form2}}

views/default/index.html:

{{extend 'layout.html'}}
{{=LOAD('default','f1.load',ajax=True)}}
{{=LOAD('default','f2.load',ajax=True)}}


The behavior is unpredictable. Sometimes the first submit for form 1 
doesn't do anything.  You may need to refresh several times to reproduce.

Bug, or I have I done something wrong?

Neil

On Sunday, 21 April 2013 20:19:25 UTC+1, Anthony wrote:

 Probably both forms have the same formname, either because they are both 
 based on the same DAL table or because they are both SQLFORM.factory forms. 
 To avoid the problem, assign unique formnames to each via 
 .process(formname='myform1'), etc. This is discussed in the book: 
 http://web2py.com/books/default/chapter/29/07#Multiple-forms-per-page.

 Note, the problem isn't really limited to multiple forms on the same page, 
 but to multiple forms with the same name in the same browser session (even 
 if loaded into different tabs/windows that are open at the same time). The 
 problem is that the value of the formkey is stored in the session with a 
 key like _formkey[formname]. If a second form is created before the first 
 form has been submitted, the formkey associated with that particular 
 formname will be overwritten, so when the first form is submitted, it will 
 not be accepted. However, the submission itself will once again replace the 
 formkey value, so if you immediately submit a second time, it will work.

 Anthony

 On Sunday, April 21, 2013 5:03:06 AM UTC-4, Neil wrote:

 I'm having this problem now - is there a trick to having two ajax forms 
 on one page?

 Basically, as above, I have to hit submit twice for anything result. Has 
 anyone successfully had 2+ ajax forms on the same page?

 On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:

 will look into this.. it must be a JS issue. 

 On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote: 
  Hello, 
  
  I try to add two ajax forms into a page with something like this: 
  
  {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
  {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
  
  If the form has errors, the error messages are displayed after a 
  second submit. So, I need to click two times the submit button to 
  display them. 
  
  The second form has a normal behavior. 
  
  Thanks. 
  
  i.a.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
I've been playing around with it a bit more, and it seems to be the same 
underlying problem that Anthony described above. The question is: why 
doesn't the formname fix work for ajax components?

On Monday, 22 April 2013 09:19:06 UTC+1, Neil wrote:

 Thanks for that. Unfortunately, there seems to be a little more to it. 

 He is a minimal example (using web2py 2.4.6/rocket/windows, although 
 the behavior is the same with other configurations).

 controllers/default.py:

 def index():
 return dict()

 def f1():
 val1 = 
 form1 = FORM('Form 1 input:', INPUT(_name='f1input', requires=
 IS_NOT_EMPTY()), INPUT(_type='submit'))
 if form1.accepts(request,session,formname=formname1):
 val1 = form1.vars.f1input
 elif form1.errors:
 response.flash = 'Form 1 has errors'
 return dict(form1=form1, val1=val1)

 def f2():
 val2 = 
 form2 = FORM('Form 2 input:', INPUT(_name='f2input', requires=
 IS_NOT_EMPTY()), INPUT(_type='submit'))
 if form2.accepts(request,session,formname=formname2):
 val2 = form2.vars.f2input
 elif form2.errors:
 response.flash = 'Form 2 has errors'
 return dict(form2=form2, val2=val2)

 views/default/f1.load:

 p{{=val1}}/p
 {{=form1}}

 views/default/f2.load:

 p{{=val2}}/p
 {{=form2}}

 views/default/index.html:

 {{extend 'layout.html'}}
 {{=LOAD('default','f1.load',ajax=True)}}
 {{=LOAD('default','f2.load',ajax=True)}}


 The behavior is unpredictable. Sometimes the first submit for form 1 
 doesn't do anything.  You may need to refresh several times to reproduce.

 Bug, or I have I done something wrong?

 Neil

 On Sunday, 21 April 2013 20:19:25 UTC+1, Anthony wrote:

 Probably both forms have the same formname, either because they are both 
 based on the same DAL table or because they are both SQLFORM.factory forms. 
 To avoid the problem, assign unique formnames to each via 
 .process(formname='myform1'), etc. This is discussed in the book: 
 http://web2py.com/books/default/chapter/29/07#Multiple-forms-per-page.

 Note, the problem isn't really limited to multiple forms on the same 
 page, but to multiple forms with the same name in the same browser session 
 (even if loaded into different tabs/windows that are open at the same 
 time). The problem is that the value of the formkey is stored in the 
 session with a key like _formkey[formname]. If a second form is created 
 before the first form has been submitted, the formkey associated with that 
 particular formname will be overwritten, so when the first form is 
 submitted, it will not be accepted. However, the submission itself will 
 once again replace the formkey value, so if you immediately submit a second 
 time, it will work.

 Anthony

 On Sunday, April 21, 2013 5:03:06 AM UTC-4, Neil wrote:

 I'm having this problem now - is there a trick to having two ajax forms 
 on one page?

 Basically, as above, I have to hit submit twice for anything result. Has 
 anyone successfully had 2+ ajax forms on the same page?

 On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:

 will look into this.. it must be a JS issue. 

 On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote: 
  Hello, 
  
  I try to add two ajax forms into a page with something like this: 
  
  {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
  {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
  
  If the form has errors, the error messages are displayed after a 
  second submit. So, I need to click two times the submit button to 
  display them. 
  
  The second form has a normal behavior. 
  
  Thanks. 
  
  i.a.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony
I had already tried something similar, and now I have tried your exact 
code, and I cannot reproduce the problem (running from trunk with Rocket on 
Windows 7). Is it possible you are using an old version of web2py.js?

I've been playing around with it a bit more, and it seems to be the same 
 underlying problem that Anthony described above.


What do you observe that leads you to that conclusion?

Anthony 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread weheh
I've done this before -- multiple ajax forms on one page -- and not had any 
issues. EXCEPT, I'm guessing from the names of your functions that you have 
an upload type field in there somewhere, or possibly in both forms. That 
is going to be an issue, since upload fields have to be treated specially. 
There is a cookbook example that deals with this exact case. If that's your 
problem, I can help to dig up a solution for you.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
This is turning out to be an elusive one! Notes:

1) I don't think I'm using an old web2py.js, unless it is accidentally 
being packaged with the latest source.
2) weheh: Nope, no uploading involved - all the code is above.
3) I guessed it is related to the multiple forms issue since 
the behavior seems similar. In particular, it usually happens for a first 
submit, and it happens with forms on different tabs.

I've now reproduced this with a variety of web2py versions (*including trunk
*), servers  browsers. I've uploaded the minimal example to my production 
server (web2py version 2.3.3, nginx), so give this a try:

1) go to http://www.ai-therapy.com/ajax_test/
2) enter something in Form 1, and press submit
3) did it work *the first time*? (the second, and subsequent, submit 
usually works for me)
4) if I clear the cookies and restart the browser, the first submit fails 
about 50% of the time. 

I've now seen it happen with chrome, fireforx  IE.

Does that give any clues?

On Monday, 22 April 2013 12:24:14 UTC+1, Anthony wrote:

 I had already tried something similar, and now I have tried your exact 
 code, and I cannot reproduce the problem (running from trunk with Rocket on 
 Windows 7). Is it possible you are using an old version of web2py.js?

 I've been playing around with it a bit more, and it seems to be the same 
 underlying problem that Anthony described above.


 What do you observe that leads you to that conclusion?

 Anthony 


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Note: it is still frustratingly unpredictable. I followed my own 
instructions 10 times before it happened again...

On Monday, 22 April 2013 14:10:33 UTC+1, Neil wrote:

 1) go to http://www.ai-therapy.com/ajax_test/
 2) enter something in Form 1, and press submit
 3) did it work *the first time*? (the second, and subsequent, submit 
 usually works for me)
 4) if I clear the cookies and restart the browser, the first submit fails 
 about 50% of the time. 



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony


 1) I don't think I'm using an old web2py.js, unless it is accidentally 
 being packaged with the latest source.


web2py.js is inside your app (in /appname/static/js), so it does not get 
updated when you upgrade web2py. When you upgrade web2py, you have to 
manually copy the new version of web2py.js (and /views/web2py_ajax.html) 
from the new welcome app to your own app.

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
I didn't upgrade - when I ran locally I downloaded trunk from github and 
used that version with rocket. Same problem.

On Monday, 22 April 2013 14:47:14 UTC+1, Anthony wrote:


 web2py.js is inside your app (in /appname/static/js), so it does not get 
 updated when you upgrade web2py. When you upgrade web2py, you have to 
 manually copy the new version of web2py.js (and /views/web2py_ajax.html) 
 from the new welcome app to your own app.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Just to clarify, I used the new simple application option with trunk (I 
didn't copy over the app from a previous version). Just to be 100% sure I 
also copied the web2py.js and web2py_ajax.html files over from the welcome 
app with no success.

On Monday, 22 April 2013 14:53:28 UTC+1, Neil wrote:

 I didn't upgrade - when I ran locally I downloaded trunk from github and 
 used that version with rocket. Same problem.

 On Monday, 22 April 2013 14:47:14 UTC+1, Anthony wrote:


 web2py.js is inside your app (in /appname/static/js), so it does not get 
 updated when you upgrade web2py. When you upgrade web2py, you have to 
 manually copy the new version of web2py.js (and /views/web2py_ajax.html) 
 from the new welcome app to your own app.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony


 1) go to http://www.ai-therapy.com/ajax_test/

2) enter something in Form 1, and press submit
 3) did it work *the first time*? (the second, and subsequent, submit 
 usually works for me)
 4) if I clear the cookies and restart the browser, the first submit fails 
 about 50% of the time. 


Hmm, tried it from IE9, Chrome, and FF on Windows 7 and from Chrome and FF 
on Ubuntu -- multiple times in each browser, including clearing cookies, 
and never observed the problem.

Do you ever clear the cookies and then submit without reloading the page or 
restarting the browser -- that will cause the error because the form will 
be submitted without the original session cookie?

Anthony

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Wow, really! That's really frustrating... 

Nope, I never tried clearing cookies and then submitting. I always clear my 
history, shut down the browser, restart the browser, copy the URL, and then 
the first submit (sometimes) fails. 

What else about my system could lead to this behavior? I'm going to go try 
on a Mac.

Thanks for your help with this.


 Hmm, tried it from IE9, Chrome, and FF on Windows 7 and from Chrome and FF 
 on Ubuntu -- multiple times in each browser, including clearing cookies, 
 and never observed the problem.

 Do you ever clear the cookies and then submit without reloading the page 
 or restarting the browser -- that will cause the error because the form 
 will be submitted without the original session cookie?

 Anthony



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
My first submit failed on Mac (both Chrome and Safari). However, I can't 
get it to happen on Ubuntu. 

I can now reproduce in the following situations:

   - running web2py locally and remote
   - 2 server OSs (windows  linux)
   - 2 webservers (rocket  uwgsi/nginx)
   - 2 front-end OSs (windows  mac - not ubuntu)
   - 4 browsers (firefox, chrome, IE, safari)
   - multiple versions of web2py
   
Not sure where that leaves me (except in a state of confusion).


 What else about my system could lead to this behavior? I'm going to go try 
 on a Mac.


 Hmm, tried it from IE9, Chrome, and FF on Windows 7 and from Chrome and 
 FF on Ubuntu -- multiple times in each browser, including clearing cookies, 
 and never observed the problem.

 Do you ever clear the cookies and then submit without reloading the page 
 or restarting the browser -- that will cause the error because the form 
 will be submitted without the original session cookie?

 Anthony



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony
Not sure what's going on. In the browser, maybe use the developer tools to 
confirm what is being sent (i.e., session cookie, value of the hidden 
_formkey field). On the server, check that there is a _formkey[formname1] 
key in the session and that it matches the _formkey value submitted with 
the form. We need to figure out where it is failing.

Anthony

On Monday, April 22, 2013 10:04:48 AM UTC-4, Neil wrote:

 Wow, really! That's really frustrating... 

 Nope, I never tried clearing cookies and then submitting. I always clear 
 my history, shut down the browser, restart the browser, copy the URL, and 
 then the first submit (sometimes) fails. 

 What else about my system could lead to this behavior? I'm going to go try 
 on a Mac.

 Thanks for your help with this.


 Hmm, tried it from IE9, Chrome, and FF on Windows 7 and from Chrome and 
 FF on Ubuntu -- multiple times in each browser, including clearing cookies, 
 and never observed the problem.

 Do you ever clear the cookies and then submit without reloading the page 
 or restarting the browser -- that will cause the error because the form 
 will be submitted without the original session cookie?

 Anthony



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Good suggestion - I think we may be getting somewhere. When it fails, the 
server is getting a '_formkey[formname2]' when submitting form 1. I'll try 
to dig a little deeper.

On Monday, 22 April 2013 15:26:03 UTC+1, Anthony wrote:

 Not sure what's going on. In the browser, maybe use the developer tools to 
 confirm what is being sent (i.e., session cookie, value of the hidden 
 _formkey field). On the server, check that there is a _formkey[formname1] 
 key in the session and that it matches the _formkey value submitted with 
 the form. We need to figure out where it is failing.





-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
A little more progress - I can now predict when the problem will 
occur server side, before hitting submit. This is what I do:

1) clear all my web2py session files
2) open an incognito brower
3) go to the page with multiple ajax forms
4) take a look at the new session file. If it looks like this:

(dp1
S'_formkey[formname2]'
p2
S'e1983c3d-2695-4383-8ea4-f32d0687a0eb'
p3
sS'_session_hash'
p4
S'f36cc8f46f69c9d7b245d52c5630a427'
p5
s.

I know that the first submission for form 1 will fail. Once I submit it 
once, '_formkey[formname1]' is added to the session dictionary and it works 
from then on. Does this give any more clues?

On Monday, 22 April 2013 15:44:21 UTC+1, Neil wrote:

 Good suggestion - I think we may be getting somewhere. When it fails, the 
 server is getting a '_formkey[formname2]' when submitting form 1. I'll try 
 to dig a little deeper.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Niphlod
completely out-of-side observation (I'll make sure I get this tested once 
I get home to report the behaviour on my pc)  

are you sure that your incognito-mode browser accepts cookies ?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
Good thought, but that doesn't seem to be a factor since it works in 
incognito after the first submit, and I can reproduce in regular mode. 

For some reason, on initial page load it is not saving both formkeys. Is it 
possible that there is a conflict when saving the the sessions file? i.e. 
both ajax components are trying to save at the same time, and only one ends 
up getting saved? Or one is overwriting the other?

On Monday, 22 April 2013 17:01:59 UTC+1, Niphlod wrote:

 completely out-of-side observation (I'll make sure I get this tested 
 once I get home to report the behaviour on my pc)  

 are you sure that your incognito-mode browser accepts cookies ?



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony
If you are saving sessions in files, the session file should be locked by 
each request, so there shouldn't be any race conditions. However, if you 
are saving sessions in the db, you could get race conditions (e.g., both 
Ajax requests read the same empty session, then form1 saves its session 
with its formkey, then form2 overwrites that session with just the form2 
formkey).

Anthony

On Monday, April 22, 2013 12:13:25 PM UTC-4, Neil wrote:

 Good thought, but that doesn't seem to be a factor since it works in 
 incognito after the first submit, and I can reproduce in regular mode. 

 For some reason, on initial page load it is not saving both formkeys. Is 
 it possible that there is a conflict when saving the the sessions file? 
 i.e. both ajax components are trying to save at the same time, and only one 
 ends up getting saved? Or one is overwriting the other?

 On Monday, 22 April 2013 17:01:59 UTC+1, Niphlod wrote:

 completely out-of-side observation (I'll make sure I get this tested 
 once I get home to report the behaviour on my pc)  

 are you sure that your incognito-mode browser accepts cookies ?



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Neil
I've been doing a little debugging. When the page loads, 
_try_store_in_file(self, 
request, response) in globals.py is called twice. The first time it saves 
formname1, and the second time it seems to overwrite the original file with 
formname2 (occasionally the order is reversed). How would a lock would fix 
this? I can see how that would prevent simultaneous access to the file, but 
how would it prevent data from being overwritten?

On Monday, 22 April 2013 17:54:21 UTC+1, Anthony wrote:

 If you are saving sessions in files, the session file should be locked by 
 each request, so there shouldn't be any race conditions. However, if you 
 are saving sessions in the db, you could get race conditions (e.g., both 
 Ajax requests read the same empty session, then form1 saves its session 
 with its formkey, then form2 overwrites that session with just the form2 
 formkey).

 Anthony

 On Monday, April 22, 2013 12:13:25 PM UTC-4, Neil wrote:

 Good thought, but that doesn't seem to be a factor since it works in 
 incognito after the first submit, and I can reproduce in regular mode. 

 For some reason, on initial page load it is not saving both formkeys. Is 
 it possible that there is a conflict when saving the the sessions file? 
 i.e. both ajax components are trying to save at the same time, and only one 
 ends up getting saved? Or one is overwriting the other?

 On Monday, 22 April 2013 17:01:59 UTC+1, Niphlod wrote:

 completely out-of-side observation (I'll make sure I get this tested 
 once I get home to report the behaviour on my pc)  

 are you sure that your incognito-mode browser accepts cookies ?



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Niphlod
ok, behaviour confirmed on my pc too.
PS: noticed that with
def index():
 session.hello = 'world'
 return dict()

all works fine, every time.

I'm debugging right now to see what's going on on the 2 ajax requests.

On Monday, April 22, 2013 7:22:46 PM UTC+2, Neil wrote:

 I've been doing a little debugging. When the page loads, 
 _try_store_in_file(self, 
 request, response) in globals.py is called twice. The first time it saves 
 formname1, and the second time it seems to overwrite the original file with 
 formname2 (occasionally the order is reversed). How would a lock would fix 
 this? I can see how that would prevent simultaneous access to the file, but 
 how would it prevent data from being overwritten?

 On Monday, 22 April 2013 17:54:21 UTC+1, Anthony wrote:

 If you are saving sessions in files, the session file should be locked by 
 each request, so there shouldn't be any race conditions. However, if you 
 are saving sessions in the db, you could get race conditions (e.g., both 
 Ajax requests read the same empty session, then form1 saves its session 
 with its formkey, then form2 overwrites that session with just the form2 
 formkey).

 Anthony

 On Monday, April 22, 2013 12:13:25 PM UTC-4, Neil wrote:

 Good thought, but that doesn't seem to be a factor since it works in 
 incognito after the first submit, and I can reproduce in regular mode. 

 For some reason, on initial page load it is not saving both formkeys. Is 
 it possible that there is a conflict when saving the the sessions file? 
 i.e. both ajax components are trying to save at the same time, and only one 
 ends up getting saved? Or one is overwriting the other?

 On Monday, 22 April 2013 17:01:59 UTC+1, Niphlod wrote:

 completely out-of-side observation (I'll make sure I get this tested 
 once I get home to report the behaviour on my pc)  

 are you sure that your incognito-mode browser accepts cookies ?



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Niphlod
umpf I can't understand why this is not working ok.

The problem lies indeed in the fact that one ajax request overwrites the 
session, if the session file is not there yet. 
I can only guess that the logic is failing to acquire a lock before 
creating the (new) file 
If a request has completed yet, hence the session file is present, all goes 
perfectly ok (it's probably the reason why nobody else ever noticed the 
glitch, and why prepending a session.hello = 'world' to the index 
function makes all go smoothly, it actually creates the session file before 
the two ajax requests come in)
can anyone testing this confirm this behaviour?
steps to reproduce:
- delete session file in the session/ dir
- open the index page
- session file ends up with one or another formname keys, never both
- reload the page
- session file holds both formnames
- put session.hello = 'world' in the index() function before the return 
dict()
- delete the session file in the sessions/ dir
- reload the page
- session file holds both formnames

If this is indeed the behaviour, we narrowed it down to a glitch that 
happens in one case only: 2 concurrent requests comes in and there is no 
session file yet.
We can start from there to coordinate efforts for the patch. it's 
definitely not an issue with javascript.


-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-22 Thread Anthony
The problem is that we made a change so that no session file is created at 
all if this is a new session and the session remains empty. So, when the 
index page is requested, no session file is created. Next, the form1 Ajax 
request comes in, and because there is no session file, there is nothing to 
read or lock. Meanwhile, the form2 Ajax request comes in, and again, there 
is no file to read or lock. So, both requests start with an empty session 
and add their respective formkeys to it. Next, the form1 request creates a 
session file and writes its version of the session to it. Finally, the 
form2 request opens and completely overwrites that session file with its 
version of the session (which does not include the form1 formkey).

What to do about this? I suppose one option would be to always create a new 
session file when a new session is started, even if the session is empty on 
the first request of the session (in the above example, an empty session 
file would be created on accessing the index page). Some apps never use the 
session, though, and would therefore have a bunch of unnecessary session 
files (though I suppose you could still use the global settings to turn off 
sessions).

Another option is to leave it up to the developer to save something to the 
session in the parent page request when the page contains multiple Ajax 
requests that will be accessing the session. Maybe we could provide a 
convenience method for this, such as session.save(), which would force 
saving the file even if the session is empty (such a method might have 
other uses, such as saving and then unlocking a session in the middle of a 
request).

Other ideas?

I think there's a bigger problem with sessions in cookies and the db -- 
they aren't locked at all, so you can get race conditions with them even 
once the session has initially been saved.

Anthony

On Monday, April 22, 2013 4:59:16 PM UTC-4, Niphlod wrote:

 umpf I can't understand why this is not working ok.

 The problem lies indeed in the fact that one ajax request overwrites the 
 session, if the session file is not there yet. 
 I can only guess that the logic is failing to acquire a lock before 
 creating the (new) file 
 If a request has completed yet, hence the session file is present, all 
 goes perfectly ok (it's probably the reason why nobody else ever noticed 
 the glitch, and why prepending a session.hello = 'world' to the index 
 function makes all go smoothly, it actually creates the session file before 
 the two ajax requests come in)
 can anyone testing this confirm this behaviour?
 steps to reproduce:
 - delete session file in the session/ dir
 - open the index page
 - session file ends up with one or another formname keys, never both
 - reload the page
 - session file holds both formnames
 - put session.hello = 'world' in the index() function before the return 
 dict()
 - delete the session file in the sessions/ dir
 - reload the page
 - session file holds both formnames

 If this is indeed the behaviour, we narrowed it down to a glitch that 
 happens in one case only: 2 concurrent requests comes in and there is no 
 session file yet.
 We can start from there to coordinate efforts for the patch. it's 
 definitely not an issue with javascript.




-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-21 Thread Neil
I'm having this problem now - is there a trick to having two ajax forms on 
one page?

Basically, as above, I have to hit submit twice for anything result. Has 
anyone successfully had 2+ ajax forms on the same page?

On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:

 will look into this.. it must be a JS issue. 

 On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote: 
  Hello, 
  
  I try to add two ajax forms into a page with something like this: 
  
  {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
  {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
  
  If the form has errors, the error messages are displayed after a 
  second submit. So, I need to click two times the submit button to 
  display them. 
  
  The second form has a normal behavior. 
  
  Thanks. 
  
  i.a.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-21 Thread Massimo Di Pierro
I opened an issue and will check later today:

https://code.google.com/p/web2py/issues/detail?id=1457thanks=1457ts=1366557484

On Sunday, 21 April 2013 04:03:06 UTC-5, Neil wrote:

 I'm having this problem now - is there a trick to having two ajax forms on 
 one page?

 Basically, as above, I have to hit submit twice for anything result. Has 
 anyone successfully had 2+ ajax forms on the same page?

 On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:

 will look into this.. it must be a JS issue. 

 On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote: 
  Hello, 
  
  I try to add two ajax forms into a page with something like this: 
  
  {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
  {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
  
  If the form has errors, the error messages are displayed after a 
  second submit. So, I need to click two times the submit button to 
  display them. 
  
  The second form has a normal behavior. 
  
  Thanks. 
  
  i.a.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2013-04-21 Thread Anthony
Probably both forms have the same formname, either because they are both 
based on the same DAL table or because they are both SQLFORM.factory forms. 
To avoid the problem, assign unique formnames to each via 
.process(formname='myform1'), etc. This is discussed in the book: 
http://web2py.com/books/default/chapter/29/07#Multiple-forms-per-page.

Note, the problem isn't really limited to multiple forms on the same page, 
but to multiple forms with the same name in the same browser session (even 
if loaded into different tabs/windows that are open at the same time). The 
problem is that the value of the formkey is stored in the session with a 
key like _formkey[formname]. If a second form is created before the first 
form has been submitted, the formkey associated with that particular 
formname will be overwritten, so when the first form is submitted, it will 
not be accepted. However, the submission itself will once again replace the 
formkey value, so if you immediately submit a second time, it will work.

Anthony

On Sunday, April 21, 2013 5:03:06 AM UTC-4, Neil wrote:

 I'm having this problem now - is there a trick to having two ajax forms on 
 one page?

 Basically, as above, I have to hit submit twice for anything result. Has 
 anyone successfully had 2+ ajax forms on the same page?

 On Wednesday, 21 July 2010 08:37:54 UTC+1, mdipierro wrote:

 will look into this.. it must be a JS issue. 

 On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote: 
  Hello, 
  
  I try to add two ajax forms into a page with something like this: 
  
  {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}} 
  {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}} 
  
  If the form has errors, the error messages are displayed after a 
  second submit. So, I need to click two times the submit button to 
  display them. 
  
  The second form has a normal behavior. 
  
  Thanks. 
  
  i.a.



-- 

--- 
You received this message because you are subscribed to the Google Groups 
web2py-users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2010-07-21 Thread mdipierro
will look into this.. it must be a JS issue.

On Jul 20, 9:10 pm, ionel ionelanton...@gmail.com wrote:
 Hello,

 I try to add two ajax forms into a page with something like this:

 {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}}
 {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}}

 If the form has errors, the error messages are displayed after a
 second submit. So, I need to click two times the submit button to
 display them.

 The second form has a normal behavior.

 Thanks.

 i.a.


[web2py] Re: Multiples ajax forms (with LOAD). It is possible?

2010-07-20 Thread ionel
Addition: only the first form has the problem.

On Jul 20, 10:10 pm, ionel ionelanton...@gmail.com wrote:
 Hello,

 I try to add two ajax forms into a page with something like this:

 {{=LOAD(url=URL(r=request,f='add_person.load'), ajax=True)}}
 {{=LOAD(url=URL(r=request,f='add_image.load'), ajax=True)}}

 If the form has errors, the error messages are displayed after a
 second submit. So, I need to click two times the submit button to
 display them.

 The second form has a normal behavior.

 Thanks.

 i.a.