Hello,

I found my self need to check if a function is call by browser or is call 
internally by an other function...

I want to re-use a function in a weekly email sent automatically and want 
my code to be as DRY as possible... 

Until now, I have something like this :

def normal_page_function():
    table = db(db.atable.id>0).select()
    db.atable.oneofmyfield.represent = lambda value, record: 
A('myrepresent',_href...)
    html_table = SQLTABLE(table, ...)
    return dict(html_table=html_table)

def send_page_function():
    mail.send(to=['[email protected]'],
        reply_to='[email protected]',
        subject='subject',
        message="""<html>%(html_table)s</html>""" %normal_page_function())

But, it produces issue because the A() helper can be processed...

So, my idea is to make this littler change :

def normal_page_function():
    table = db(db.atable.id>0).select()
   * if request.IS_NOT_FROM_BROWSER:*
*        db.atable.oneofmyfield.represent = lambda value, record: 
A('myrepresent',_href...)*
*    else:*
*        db.atable.oneofmyfield.represent = lambda value, record: 
'myrepresent'*
    html_table = SQLTABLE(table, ...)
    return dict(html_table=html_table)

I think I can get the same result checking into request.http_user_agent and 
if it empty I know that the request is not comming from browser, but I am 
not sure it works and would know if there is not already a 
request.variable_name for that purpose...

Thanks

Richard

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to