Your problem number 1 is because you are commiting before p.update_record(). Put your db.commit() after p.update_record() and see what happens.
Your problem number 2 probably is because your GetProgres() function should send a GET request. But your controller#2/GetProgress() is reading more rows than is needed. Try to return a simple timestamp to check if the request is touching your web2py controller. On Tue, Jan 29, 2013 at 9:29 AM, Andriy <unhappyhardc...@gmail.com> wrote: > I have a time consuming server side calculation, which is triggered by > edit-form submitting and can run up to several minutes (its a sports event > data recalculation if rules are changed). During this time I want to receive > messages via ajax from server and post them in a div for a progress > visualization. So far I`v done this using DB table for recording log > messages: > > db.py: > #here I store messages > db.define_table('log', Field('message', 'string')) > > controller #1: > def editForm(): > ... > if form.process().accepted: > event=db(db.event.id==request.get_vars.id).select().first() > recalculateEvent(event) > > myModel.py: > #recalculation must be accessible from all controller files, so I put it in > a Model > import myModule > > recalculateEvent(event): > db.log.truncate() #clear log > session._unlock(response) #without this, this function does not > allow functions in other controllers to run > db.log.insert(message='Starting Calculation') > db.commit() #if I do not commit after every insert, > messages do not appear in DB table > myModule.calculateSomeMoreData() > for p in players: > db.log.insert(message='Calculating player '+p.name) > db.commit() > ...more calculations... > p.update_record() > > controller#2: > #ajax calls this function every .5 seconds for messages > def getProgress(): > m=' '.join([l.message for l in db(db.log).select()]) > return json.dumps(dict(m=m)) > > View, javascript: > $("#submit_button").click(function(e){ > $('#progress').show(); > GetProgres(); > $("#myForm").submit(); > }); > function GetProgres() { > $.ajax({ > type: "POST", > url: '{{=URL('controller#2', 'getProgress')}}', > dataType: "json", > success: function(data) { > $('#progress').html(data.m); > setTimeout(function() { GetProgres(); }, 500); > }, > error: function (xhr, ajaxOptions, thrownError){ > alert(xhr.status); > alert(xhr.statusText); > alert(thrownError); > } > }); > } > > I have 2 problems with this: > > 1. Every other time web2py throws this error after recalculateEvent(event) > function completes: > Traceback (most recent call last): > File "gluon/main.py", line 576, in wsgibase > File "gluon/globals.py", line 749, in _try_store_in_cookie_or_file > File "gluon/globals.py", line 768, in _try_store_in_file > IOError: [Errno 13] Permission denied > > If I remove db.log.insert+db.commit lines - no error. But how else can I > transfer live data between running real-time function in a model and > function in a controller? I tried storing messages in a session, but it does > not update until model function is finished. > > 2. Ajax call from view works only when hosting on my local machine and only > in Opera and IE. It does not call controller#2/getProgress function in > Chrome and Firefox on localhost. When hosting on outside server it does not > work on any browser... Only Firefox triggers ajax error, with > xhr.statusText='error'. > > I guess this is something to do with that I`m triggering form submission, > calculation function and at the same time polling sever. But I have no idea > what to do. > > May be if my approach is totally wrong somebody can suggest how to implement > this in other way. > > -- > > --- > 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. > > -- --- 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.