What is the problem with the A() helper? Is it that the URL is a relative
URL rather than an absolute URL? If you need an absolute URL, you can do:
A('myrepresent', _href=URL(..., scheme=True))
If that's the issue, the leaving scheme=True will work in both cases, so
you don't necessarily need to check where the call is coming from, but if
you want, you can do:
def normal_page_function():
table = db(db.atable.id>0).select()
db.atable.oneofmyfields.represent = lambda value, record: A(
'myrepresent',
_href=URL(..., scheme=request.function != 'normal_page_function'))
That simply checks whether request.function is the normal_page_function,
and if not, it sets "scheme" to True.
Anthony
On Thursday, June 6, 2013 5:05:12 PM UTC-4, Richard wrote:
>
> 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] <javascript:>'],
> reply_to='[email protected] <javascript:>',
> 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.