Render._add_global does not work. #217

Open
vwochnik opened this Issue Mar 22, 2013 · 5 comments

Comments

Projects
None yet
2 participants
@vwochnik

Hello guys. The _add_global method in Render is completely useless, because it gets supressed by getattr which will raise an AttributeError due to non-existent template "_add_global".

Does not work:

render._add_global('bar', 'foo')

Instead, I have to manually

render._keywords['global']['foo'] = 'bar''

This is undesired behavior, I gess. Also, the function is unused in the template module itself, so I assume it was made for exactly this purpose.

@gardiner

This comment has been minimized.

Show comment
Hide comment
@gardiner

gardiner Mar 24, 2013

__getattr__ gets only called for missing attributes. For me _add_global works exactly as it's supposed to.

__getattr__ gets only called for missing attributes. For me _add_global works exactly as it's supposed to.

@vwochnik

This comment has been minimized.

Show comment
Hide comment
@vwochnik

vwochnik Mar 24, 2013

I'm getting the following:

import web
r = web.template.render(".")
r._add_global("value", "name")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/pymodules/python2.7/web/template.py", line 1021, in
getattr
t = self._template(name)
File "/usr/lib/pymodules/python2.7/web/template.py", line 1018, in
_template
return self._load_template(name)
File "/usr/lib/pymodules/python2.7/web/template.py", line 1005, in
_load_template
raise AttributeError, "No template named " + name
AttributeError: No template named _add_global

2013/3/24 Ole Trenner notifications@github.com

getattr gets only called for missing attributes. For me _add_global
works exactly as it's supposed to.


Reply to this email directly or view it on GitHubhttps://github.com/webpy/webpy/issues/217#issuecomment-15352072
.

I'm getting the following:

import web
r = web.template.render(".")
r._add_global("value", "name")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/pymodules/python2.7/web/template.py", line 1021, in
getattr
t = self._template(name)
File "/usr/lib/pymodules/python2.7/web/template.py", line 1018, in
_template
return self._load_template(name)
File "/usr/lib/pymodules/python2.7/web/template.py", line 1005, in
_load_template
raise AttributeError, "No template named " + name
AttributeError: No template named _add_global

2013/3/24 Ole Trenner notifications@github.com

getattr gets only called for missing attributes. For me _add_global
works exactly as it's supposed to.


Reply to this email directly or view it on GitHubhttps://github.com/webpy/webpy/issues/217#issuecomment-15352072
.

@gardiner

This comment has been minimized.

Show comment
Hide comment
@gardiner

gardiner Mar 24, 2013

Hmm. I've just tested (again) with web.py 0.36 and 0.37 and everything works as expected. Which version are you using?

>>> import web
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>> print web.__version__
0.36


>>> import web
>>> print web.__version__
0.37
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>>

Hmm. I've just tested (again) with web.py 0.36 and 0.37 and everything works as expected. Which version are you using?

>>> import web
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>> print web.__version__
0.36


>>> import web
>>> print web.__version__
0.37
>>> r = web.template.render('.')
>>> r._add_global('value', 'key')
>>>
@vwochnik

This comment has been minimized.

Show comment
Hide comment
@vwochnik

vwochnik Mar 25, 2013

Using version 0.34. I guess, that's the problem.

2013/3/24 Ole Trenner notifications@github.com

Hmm. I've just tested (again) with web.py 0.36 and 0.37 and everything
works as expected. Which version are you using?

import web
r = web.template.render('.')
r._add_global('value', 'key')
print web.version
0.36

import web
print web.version
0.37
r = web.template.render('.')
r._add_global('value', 'key')


Reply to this email directly or view it on GitHubhttps://github.com/webpy/webpy/issues/217#issuecomment-15367164
.

E-Mail: v.wochnik@gmail.com
Facebook: https://www.facebook.com/v.wochnik
Mobile: +49 (0) 151 26 39 21 22

Using version 0.34. I guess, that's the problem.

2013/3/24 Ole Trenner notifications@github.com

Hmm. I've just tested (again) with web.py 0.36 and 0.37 and everything
works as expected. Which version are you using?

import web
r = web.template.render('.')
r._add_global('value', 'key')
print web.version
0.36

import web
print web.version
0.37
r = web.template.render('.')
r._add_global('value', 'key')


Reply to this email directly or view it on GitHubhttps://github.com/webpy/webpy/issues/217#issuecomment-15367164
.

E-Mail: v.wochnik@gmail.com
Facebook: https://www.facebook.com/v.wochnik
Mobile: +49 (0) 151 26 39 21 22

@gardiner

This comment has been minimized.

Show comment
Hide comment
@gardiner

gardiner Mar 25, 2013

Yes, version 0.34 did not have a method _add_global. If I'm not mistaken you can add globals in 0.34 with a globals keyword argument:

>>> import web
>>> print web.__version__
0.34
>>> r = web.template.render('.', globals={'key':'value'})
>>> r.test() #test.html contains the line "Hello $key."
<TemplateResult: {'__body__': u'Hello value.\n'}>
>>>

(The render constructor passes additional keyword arguments down to the template constructor)

Yes, version 0.34 did not have a method _add_global. If I'm not mistaken you can add globals in 0.34 with a globals keyword argument:

>>> import web
>>> print web.__version__
0.34
>>> r = web.template.render('.', globals={'key':'value'})
>>> r.test() #test.html contains the line "Hello $key."
<TemplateResult: {'__body__': u'Hello value.\n'}>
>>>

(The render constructor passes additional keyword arguments down to the template constructor)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment