Hi Niphold,

many thanks for your reply and valuable tips.
On 23 Apr 2014 at 20:59:52, Niphlod (niph...@gmail.com) wrote:

you're doing "all" wrong. Stop copy/pasting for a sec and take a look to 
docs.....it'll save you from multiple headaches.
Despite my error, isn’t it normal doing some copy-past while giving  first 
steps?



in this case, you're "doing wrong" form processing.

It's either

form = SQLFORM(...)
if form.accepts(request.vars, session):
    ....things to do when form is valid
elif form.errors:
    ....things to do when form has errors
else:
    ....things to do when page is loaded the first time
return dict(form=form)



or (newer)

form = SQLFORM(...)
if form.process().accepted:
    ....things to do when form is valid
elif form.errors:
    ....things to do when form has errors
else:
    ....things to do when page is loaded the first time
return dict(form=form)



I’ve changed the code to this last newer form and it is working fine.
Yes It makes sense but I think what confuses me most is the ‘so many ways to do 
it’.

Meanwhile, looking here 
http://web2py.com/books/default/chapter/29/07/forms-and-validators I can’t 
figure where is the newer or ‘older’ version.

regards,
Frank



On Tuesday, April 22, 2014 7:32:03 PM UTC+2, ureal frank wrote:
Hi,

/newbie here/

I’ve up and running a very very simple task scheduler but I think it’s not well 
designed :/

under models/scheduler.py I have:

"
from gluon.scheduler import Scheduler

def task_add(name, target):
    sum = 'hello ' + name + ' ' + target + '\n'
    with open('/tmp/tasks', 'w') as f:
        f.write(sum)

scheduler = Scheduler(db, dict(task_add=task_add))
“

and in controller:

“
def new():

    form = SQLFORM(db.scan)
 
    name = “”
    target = “"

    if form.process().accepts(request.vars, session):

        name = form.vars.name
        target = form.vars.target

        response.flash = ‘Great scan'

    elif form.errors:
        response.flash = 'Error, try again'

    scheduler.queue_task('task_add’,
pargs=[],
        pvars={'name': name, 'target': target},
        start_time=request.now,     #datetime
        stop_time = None,           #datetime
        timeout = 60,               #seconds
        prevent_drift=False,
        period=60,                  #seconds
        immediate=False,
        repeats = 1)

    return dict(scans=scans, form=form)
“

This snippet is working but I think this “scheduler.queue_task(…)” should be 
processed inside “if form.process().accepts()”. But if I change the scheduler 
snipper into that code section, the task wont run and I don’t know why.

two: questions
1) what I am  doing wrong?
1.1) Maybe I should db.commit when the task is over. Should I code this under 
scheduler.py? 
2) where can I learn more about debugging?

Many many thanks in advance :)

Cheers,
-- 
Frank
--
Resources:
- http://web2py.comhttp://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.

-- 
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.

Reply via email to