[web2py] Re: lexical scanner
yes, i wrote a function in main.py which is an added controller in my application. under main.py, i have a function called file_lookup. i am trying to use file_lookup in a view between the standard delimitors {{ and }}. except that web2py is erroring out saying that file_lookup is not defined. so i am thinking that i have to pass the function reference off to a global storage so that when web2py renders the view, it has a reference is file_lookup. better? lucas
[web2py] Re: lexical scanner
Okay, in that caseyou pass the function to the view as you would any other variable. For example: return dict(form=form, rows=rows, file_lookup=file_lookup) On Nov 10, 4:57 pm, lucas wrote: > yes, i wrote a function in main.py which is an added controller in my > application. under main.py, i have a function called file_lookup. i > am trying to use file_lookup in a view between the standard delimitors > {{ and }}. except that web2py is erroring out saying that file_lookup > is not defined. so i am thinking that i have to pass the function > reference off to a global storage so that when web2py renders the > view, it has a reference is file_lookup. better? lucas
[web2py] Re: lexical scanner
yes, i wrote a function in main.py which is an added controller in my application. under main.py, i have a function called file_lookup. i am trying to use file_lookup in a view between the standard delimitors {{ and }}. except that web2py is erroring out saying that file_lookup is not defined. so i am thinking that i have to pass the function reference off to a global storage so that when web2py renders the view, it has a reference is file_lookup. better? lucas
[web2py] Re: lexical scanner
Sorry lucas, but I don't understand what you're trying to do. Can you explain further? On Nov 9, 4:53 pm, lucas wrote: > ok, i have done so much using this really really cool technique. > > anyway, how do i pass a function reference to a "global" storage > context so that the standard views that are stored under views are > rendered properly, like in the above examples? > > lucas
[web2py] Re: lexical scanner
ok, i have done so much using this really really cool technique. anyway, how do i pass a function reference to a "global" storage context so that the standard views that are stored under views are rendered properly, like in the above examples? lucas
[web2py] Re: lexical scanner
yes, working perfectly, beautiful. thank you much. lucas
[web2py] Re: lexical scanner
yes, working perfectly, beautiful. thank you much. lucas
[web2py] Re: lexical scanner
if you use the web2py Storage class: context = Storage() context.auth = auth render(content=content, context=context) or in raw python: context = {} context['auth'] = auth render(content=content, context=context) On Nov 3, 8:43 pm, lucas wrote: > ok, something more complicated now. > > i have reference to auth in my text, for cross checking with > permissions and stuff in an if statement. how do i pass the auth > pointer reference through to renderer so that when i use auth.* in the > text it runs properly? > > thank you in advance. lucas
[web2py] Re: lexical scanner
ok, something more complicated now. i have reference to auth in my text, for cross checking with permissions and stuff in an if statement. how do i pass the auth pointer reference through to renderer so that when i use auth.* in the text it runs properly? thank you in advance. lucas
[web2py] Re: lexical scanner
oh yeah, that is working awesome. sometimes coding is better then eating. thanx so much limedrop. have a great day. lucas
[web2py] Re: lexical scanner
Conceptually, this is the same as giving any module to access the web2py helpers...you will need to make them available within the namespace. I did a quick test: >>> content = "{{from gluon.html import *}}{{=A('hello world')}}" >>> render(content=content) 'hello world' So it works! Other things you might need are: from gluon.http import * from gluon.validators import * from gluon.sqlhtml import * As with the old local_import, if you want request, session, cache, T, db(s) they will need to be passed in the context. For example: context.db = db context.request = request Hope that clarifies it for you. On Nov 2, 3:25 pm, lucas wrote: > ok, i feel like i am on the right path, getting hot. i have this > sample code to break it down, > > q = """ok dude, italic text. > this is plain but bold text. > {{=A('web2py code', _href=URL('http://fscj.edu'))}}""" > from gluon.template import render > from gluon.storage import Storage > context = Storage() > q4 = render(content=q, context=context) > > or more simpler > > q = """ok dude, italic text. > this is plain but bold text. > {{=A('web2py code', _href=URL('http://fscj.edu'))}}""" > from gluon.template import render > q4 = render(content=q) > > i get the same error which ends in: > > File "/opt/web-apps/web2py/gluon/template.py", line 916, in render > exec(code) in context > File "", line 2, in > NameError: name 'A' is not defined > > make sense? suggestions, please? lucas
[web2py] Re: lexical scanner
ok, i feel like i am on the right path, getting hot. i have this sample code to break it down, q = """ok dude, italic text. this is plain but bold text. {{=A('web2py code', _href=URL('http://fscj.edu'))}}""" from gluon.template import render from gluon.storage import Storage context = Storage() q4 = render(content=q, context=context) or more simpler q = """ok dude, italic text. this is plain but bold text. {{=A('web2py code', _href=URL('http://fscj.edu'))}}""" from gluon.template import render q4 = render(content=q) i get the same error which ends in: File "/opt/web-apps/web2py/gluon/template.py", line 916, in render exec(code) in context File "", line 2, in NameError: name 'A' is not defined make sense? suggestions, please? lucas
[web2py] Re: lexical scanner
Render is the same function used to process the views. So, as long as you put all the variables in the namespace, your code will execute. Something like this should work: from gluon.template import render context = Storage() context.rows = rows content = """ {{ for row in rows: ..something with rows.. for c in rows.colnames: ..something with colnames.. =A("some link text", =href=URL("index")) }} """ rendered = render(content, context=context) On Nov 2, 11:43 am, lucas wrote: > yes, but even more general then only fields, like you can have entire > sections of blocked executable code in a view like > > > > {{ > for row in rows: > ..something with rows.. > for c in rows.colnames: > ..something with colnames.. > =A("some link text", =href=URL("index"))}} > > > > > that isn't so much a field as a big block of code, in a html/text > file. how do we get that to execute as python? lucas
[web2py] Re: lexical scanner
yes, but even more general then only fields, like you can have entire sections of blocked executable code in a view like {{ for row in rows: ..something with rows.. for c in rows.colnames: ..something with colnames.. =A("some link text", =href=URL("index")) }} that isn't so much a field as a big block of code, in a html/text file. how do we get that to execute as python? lucas
[web2py] Re: lexical scanner
I think you want render. For example: from gluon.template import render fields=Storage() fields.first_name = "John" content = "Hello {{=first_name}}" rendered = render(content, context=fields) On Nov 2, 9:02 am, lucas wrote: > ok, still stuck, > > i played with CODE(...) but that only displays the text in python or > web2py syntax, it doesn't run it. i tried exec("string"), like in the > web2py manual, under a function in index.py, but it failes to compile > on that line saying invalid syntax. > > so i am still not sure, so how does view get processed and separated > by html and python code and then the python code is interpreted and > run as executable code? > > thank you in advance, lucas
[web2py] Re: lexical scanner
ok, still stuck, i played with CODE(...) but that only displays the text in python or web2py syntax, it doesn't run it. i tried exec("string"), like in the web2py manual, under a function in index.py, but it failes to compile on that line saying invalid syntax. so i am still not sure, so how does view get processed and separated by html and python code and then the python code is interpreted and run as executable code? thank you in advance, lucas