Massimo, I omitted a test case because it seems occurring in any of my
components and it can easily reproduced.

Here using the component example in the Book (modified a bit):

model:

db.define_table('comment',
   Field('body','text',label='Your comment'),
   Field('posted_on','datetime',default=request.now))
db.comment.posted_on.writable=db.comment.posted_on.readable=False

controller:

def index():

    return dict()

def post():
    return dict(form=crud.create(db.comment),
                comments=db(db.comment.id>0).select())

views:
default/post.load:

{{for comment in comments:}}
<div class="comment">
  on {{=comment.posted_on}}
  says <span class="comment_body">{{=comment.body}}</span>
</div>
{{pass}}
{{session.mysession={}}}
{{session.mysession['mylabel']=comment.body}}}
{{=form}}

default/index.html:

{{extend 'layout.html'}}
{{=LOAD('default','post.load',ajax=True)}}

This is part of the ticket:

Traceback (most recent call last):
  File "E:\Python26\web2py\gluon\restricted.py", line 186, in
restricted
    ccode = compile2(code,layer)
  File "E:\Python26\web2py\gluon\restricted.py", line 173, in compile2
    return compile(code.rstrip().replace('\r\n','\n')+'\n', layer,
'exec')
  File "E:\Python26\web2py\applications\test/views\default/post.load",
line 11
    session.mysession['mylabel']=comment.body
          ^
SyntaxError: invalid syntax


But if you change the component post.load as:

{{for comment in comments:}}
<div class="comment">
  on {{=comment.posted_on}}
  says <span class="comment_body">{{=comment.body}}</span>
</div>
{{pass}}
{{session.mysession=""}}
{{session.mysession=comment.body}}
{{=form}}

This is working.

carlo




On 29 Mar, 01:22, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> what do you mean by "fails" can you provide a test case?
>
> On Mar 28, 5:15 pm, carlo <syseng...@gmail.com> wrote:
>
> > I have a behaviour I can not explain.
>
> > In a controller this is a regular syntax:
>
> > session.mysession={}
> > session.mysession['myfield']=myvalue
>
> > but in a .load component the same fails.
>
> > On the other side:
>
> > session.simplevalue=myvalue
>
> > works with no problem even in components.
>
> > Does anyone has an explanation?
>
> > carlo
>
>

Reply via email to