Community mailing list archives

t-esc in website

Pedro Cachaca
- 10/14/2014 06:22:37
Hi everybody

<t t-esc=""/> works fine in any page of the website.

How to render something like <t t-esc="Courses[0].name"/> in any page ? :
class Courses(models.Model):
    _name = ''
    name = fields.Char()
    description = fields.Html()

I tested below solutions. The third one is working fine but is it a good way to do this ? or another alternative ?

1/ with controllers : seems limited to a page
I can do this with a controller but seems not compatible to show in any page, this will works only in a generated page /academy/courses. Do I miss something ?
    @http.route('/academy/courses', auth='public', website=True)
    def courses_list(self):
        Courses = http.request.env['']
        return http.request.render('academy.courses_list', {'courses':[]),})

2/ with controllers+javascript : a little complex
I teste with the use of a javascript (declared as, in order to replace a <div class="courseblock/> with the content, but seems a little complex, to just show a simple t-esc.....
.js :
           $.post( "/academy/courses", function( data ) {
                   $( ".courseblock" ).replaceWith( data );

3/ linked with a res_company : OK, is it a good solution ? 

<div t-esc="res_company.course_ids[0].description"/>

works fine ;), needs to link Courses with Res_company in the models. Is it a good solution ?
class res_company(models.Model):
    _inherit =''
    course_ids = fields.One2many('weebnb.bnbs', 'company_id', string="bnb")
class Courses(models.Model):
    _name = ''
    name = fields.Char()
    description = fields.Html()
    company_id = fields.Many2one('', string="Company")

4/ Note: Res_company

I saw in  /addons/website/models/ that res_company is defined into the def render.
Do we have to do something similar ?

def render(self, cr, uid, id_or_xml_id, values=None, engine='ir.qweb', context=None):
company = self.pool[''].browse(cr, SUPERUSER_ID,, context=context)

Thanks your help ;)