pyTenjin problem with Python expression

15 views
Skip to first unread message

Radek

unread,
Feb 4, 2011, 8:14:16 AM2/4/11
to kuwata-lab-products
Hello,

I the documentation, there is note that in template I can use Python
expression.
http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html
#{...}
Python expression (without HTML escape)

But when I use this and put an expression, it's on the following
example second line. I get an error: AttributeError: unreadable
attribute

<td>#{user.password}</td>
<td>#{'a'}</td>

I need python expression not for putting 'a' in template but primary
though for it was something like this:

<td>#{ ', '.join(user.roles}</td>

which of course do not work to.

Radek

unread,
Feb 4, 2011, 11:28:40 AM2/4/11
to kuwata-lab-products
I'm sorry,

It looks like its mine error.

On 4 ún, 14:14, Radek <radek.hnil...@gmail.com> wrote:
> Hello,
>
> I the documentation, there is note that in template I can use Python
> expression.http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html

Makoto Kuwata

unread,
Feb 4, 2011, 9:38:20 PM2/4/11
to kuwata-la...@googlegroups.com
Hi Radek,
thank you for trying Tenjin.
If you have any questions or troubles, let me know them.
By the way, I'll release pyTenjin 1.0.0 (or preview release) in the
nex few days.
if you have feature request, let me know it.
--
regards,
makoto kuwata

Radek

unread,
Feb 7, 2011, 1:20:17 PM2/7/11
to kuwata-lab-products
Hi makoto kuwata

I'm new to Python, trying to program GAE/P for about two months.

I've hard time with pyTenjin.
After some initial experiments I'm able to use tenjin under some
special circumstances.
I rewrote code of one application, so I can see some output.
Application works, but then integration problems arises.

for the first. I'm not able to put tenjin in directory structure of
my project. If it is in the root of the aplication it works, but I do
not know how to move it into place it belongs (lib/vendor/tenjin).

When in root I can import the tenjin into specific handler by this
code.

# Tenjin
import tenjin
from tenjin.helpers import *
import tenjin.gae; tenjin.gae.init()
import logging
logging.basicConfig(level=logging.DEBUG)
tenjin.logger = logging

When moving tenjin in the right place it belongs to I do not know how
to write the code in handler.

# Tenjin
import lib.vendor.tenjin
from tenjin.helpers import *
import tenjin.gae; tenjin.gae.init()
logging.basicConfig(level=logging.DEBUG)
tenjin.logger = logging

But i does not work saying that tenjin.helpers does not work. Looking
at the code for the first time does not help. Seems that tenjin.py is
nothing else then program that builds programs. As I write before,
I'm new to python.

The second problem is. Tenjin breaks my handler testing code. It
just breaks during test load before executing any test code. Saying
something like:

File "/home/radek/firma/lekarna/src/cl/src/cl-control/trunk/app/
handlers/user.py", line 21, in <module>
from tenjin.helpers import *
File "/home/radek/firma/lekarna/src/cl/src/cl-control/trunk/
tenjin.py", line 1538, in init
ver = os.environ.get('CURRENT_VERSION_ID').split('.')[0]
AttributeError: 'NoneType' object has no attribute 'split'


I'm so completely lost, that I'm now searching internet to learn how
the import internaly works.

Radek

unread,
Feb 7, 2011, 2:32:04 PM2/7/11
to kuwata-lab-products
Hi makoto kuwata

If I didn't miss something, I solve my first problem.

I put following lines in my main.py file.

import sys # Because of Tenjin
sys.path.append('lib/vendor') # Because of tenjin

Makoto Kuwata

unread,
Feb 7, 2011, 6:14:47 PM2/7/11
to kuwata-la...@googlegroups.com
Hi Radek,

Strange. It seems GAE specific issue because
there is no problem on console.

$ python


>>> import lib.vendor.tenjin
>>> from tenjin.helpers import *

>>> to_str(None)
''

Workaround is to add 'lib/vendor' into sys.path.

import sys
sys.path.insert(0, 'lib/vendor')
#sys.path.append('lib/vendor') # not work?


import tenjin
from tenjin.helpers import *
import tenjin.gae; tenjin.gae.init()

This may not a solution for you, but it works well.


>
> The second problem is.  Tenjin breaks my handler testing code.  It
> just breaks during test load before executing any test code.  Saying
> something like:
>
>   File "/home/radek/firma/lekarna/src/cl/src/cl-control/trunk/app/
> handlers/user.py", line 21, in <module>
>    from tenjin.helpers import *
>  File "/home/radek/firma/lekarna/src/cl/src/cl-control/trunk/
> tenjin.py", line 1538, in init
>    ver = os.environ.get('CURRENT_VERSION_ID').split('.')[0]
> AttributeError: 'NoneType' object has no attribute 'split'
>
>
> I'm so completely lost, that I'm now searching internet to learn how
> the import internaly works.
>

This is because environment variable $CURRENT_VERSION_ID is missing
on testing environment.
Workaround is to set dummy value before tenjin.gae.init().

import os
os.environ['CURRENT_VERSION_ID'] = '1.1'
import tenjin.gae; tenjin.gae.init()

--
regards,
makoto kuwata

Makoto Kuwata

unread,
Feb 7, 2011, 6:17:41 PM2/7/11
to kuwata-la...@googlegroups.com

Congratulation.
My code do work with:

sys.path.insert(0, 'lib/vendor')

but doesn't with:

sys.path.append('lib/vendor') # your solution

Hmm. Strange.

--
regards,
makoto kuwata

Makoto Kuwata

unread,
Feb 7, 2011, 6:30:31 PM2/7/11
to kuwata-la...@googlegroups.com
On Tue, Feb 8, 2011 at 8:14 AM, Makoto Kuwata <k...@kuwata-lab.com> wrote:
>
>    import os
>    os.environ['CURRENT_VERSION_ID'] = '1.1'
>    import tenjin.gae; tenjin.gae.init()

I' sorry. In this case, we should use setdefault().

import os
os.environ.setdefault('CURRENT_VENDOR_ID', '1.1')

Radek

unread,
Feb 7, 2011, 8:33:38 PM2/7/11
to kuwata-lab-products
hi makoto kuwata

thanks for answer
I found following

On 8 ún, 00:17, Makoto Kuwata <k...@kuwata-lab.com> wrote:
> Congratulation.
> My code do work with:
>
>   sys.path.insert(0, 'lib/vendor')
>
> but doesn't with:
>
>   sys.path.append('lib/vendor')    # your solution
>
> Hmm. Strange.
sys.path.append behaves realy strange. It works in application but
not in tests. The tests says that tenjin cant be found.
So I change it to: sys.path.insert which works both in application and
also in tests.


> This is because environment variable $CURRENT_VERSION_ID is missing
> on testing environment.
> Workaround is to set dummy value before tenjin.gae.init().
> import os
> os.environ['CURRENT_VERSION_ID'] = '1.1'
> import tenjin.gae; tenjin.gae.init()

thnaks for help, it works with real tests.


Radek

unread,
Feb 8, 2011, 6:17:30 AM2/8/11
to kuwata-lab-products
hi makoto kuwata

---- example: set.py --------------
#!/usr/bin/env python
# -*- coding: utf-8; -*-
import os

os.environ.setdefault('VERA', '0')
vera = os.environ.get('VERA')
print 'vera=', vera

os.environ['VERB'] = '1'
verb = os.environ.get('VERB')
print 'verb=', verb

verc = os.environ.get('VERC', '2')
print 'verc=', verc
------------- end of program-------
vera= 0
verb= 1
verc= 2
------------- end of screen -------

As a new to python, I do not underestand the difference between
os.environ['...']= and os.environ.setdefault.

But I will propose to solve this problem with the third variant as in
example, by using the default parameter of os.environ.get method. If
you change the os.environ.get as in the example, no other setting will
be necesary.


-- radek

Makoto Kuwata

unread,
Feb 8, 2011, 7:06:40 AM2/8/11
to kuwata-la...@googlegroups.com
Radek,

On Tue, Feb 8, 2011 at 8:17 PM, Radek <radek....@gmail.com> wrote:
>
> But I will propose to solve this problem with the third variant as in
> example, by using the default parameter of os.environ.get method.  If
> you change the os.environ.get as in the example, no other setting will
> be necesary.

Yes, that's right. I'll change code in the next release.
Thank you.

--
regards,
makoto kuwata

Reply all
Reply to author
Forward
0 new messages