Sorry, my mistake -- there is no "context" argument. Just pass the dict as 
an unnamed argument, or pass each item as its own keyword argument:

response.render(dict(organization=session.organization, ...))

or just:

response.render(organization=session.organization, ...)

Side note: you don't need the line continuation slash ("\") if what you're 
continuing is in parentheses.

Anthony

On Monday, April 16, 2012 1:23:53 AM UTC-4, Annet wrote:
>
> Hi Anthony,
>
> Thanks for your reply.
>
> You could do:
>>
>> {{if organization:}}FN: {{=organization.name}}
>> ORG: {{=organization.name}}{{pass}}
>>
>> and you won't get any blank lines when there is an organization, but I 
>> think you'll still get two blank lines when there is no organization.
>>
>
> This won't be a problem in case of the organization, however, in case of 
> telecom addresses this solution won't solve the problem.
>
>  I tried this solution:
>
> Another option might be to render the response in the controller and then 
>> remove any blank lines from the text:
>>
>> def make_vcard():
>>     data = [code to generate vcard data]
>>     vcard = response.render(context=dict(data=data))
>>     return vcard.replace('\n\n', '\n')
>>
>>
> ... but got the following error:
>
>  
>
> Traceback (most recent call last):
>   File "/Library/Python/2.5/site-packages/web2py/gluon/restricted.py", line 
> 205, in restricted
>     exec ccode in environment
>   File 
> "/Library/Python/2.5/site-packages/web2py/applications/bootstrap/views/addressbook/downloadvcard.vcf",
>  line 1, in <module>
>     {{response.headers['Content-Disposition'] = 'attachment;filename=%s.vcf' 
> % IS_SLUG()(organization.name)[0]}}BEGIN:VCARD
> NameError: name 'organization' is not defined
>
>
> In the address book controller I got a function vcard which returns a vcard 
> to an html view. In this function I store organization, address and telecom 
> data in session:
>
> session.organization=db(db.Organization.nodeID==session.id).select(db.Organization.nodeID,db.Organization.name).first()
> session.address=db(db.Address.nodeID==session.id).select(db.Address.ALL).first()
> session.telecom=db(db.Telecom.nodeID==session.id).select(db.Telecom.ALL)
>
> The view contains a button 'download vcard' which calls the function 
> downloadvcard:
>
> def downloadvcard():
>     if request.args(0)!=session.id:
>         redirect(URL('vcard',args=request.args(0)))
>     else:
>         vcard=response.render(context=dict(organization=session.organization,\
>         address=session.address,telecom=session.telecom))
>         return vcard.replace('\n\n','\n')
>
> I guess my problem lies in the data part of your solution. organization and 
> address are single row objects, telecom contains as many rows as an 
> organization has telecom addresses.
>
> I hope I provided you with sufficient information to help me solve the 
> problem.
>
>
> Kind regards,
>
> Annet.
>
>

Reply via email to