0
votes

I use class 'website.seo.metadata' for extend my model.

In model added filed noindex:

class service(models.Model):
    _name = 'pr_filials.service'
    _inherit = ['mail.thread', 'website.seo.metadata', 'website.published.mixin']

    name = fields.Char(string="Name", required=True)
    noindex = fields.Boolean(string="Noindex", default=False)
....

In template I'm using such view:

<template id="assets_frontend_noindex" inherit_id="website.assets_frontend" name="Noindex">
            <xpath expr="." position="inside">
                <t t-if="main_object and 'noindex' in main_object">
                    <t t-if="main_object.index">
                        <meta name="robots" content="noindex" />                        
                    </t>
                </t>
            </xpath>
</template>

But template not seen field noindex

I tried extend class website.seo.metadata too. Nothing changed.

In header present such information:

<html lang="ru-RU" data-website-id="1" data-editable="1" data-view-xmlid="882" data-main-object="pr_filials.service(13,)" data-oe-company-name="SiteName"> 

All work fine if i try to connect name field - data from it displayed.

How can a get data from my noindex field in header?

UPDATE: I extended ir.ui.view:

class view(osv.osv):
    _name = "ir.ui.view"
    _inherit = "ir.ui.view"
    _columns = {
        'noindex': fields.boolean("Noindex"),
    }

Added to class service such code:

@api.onchange('noindex')
def _set_noindex(self):
    self.website_meta_noindex = self.noindex
    url = u'/uslugi/' + self.url_name
    _logger.warning('URL: %s', url)
    self.write_to_ui_view(url=url, noindex=self.noindex)

def write_to_ui_view(self, cr, uid, url, noindex=False, ispage=True, template='pr_filials.servicepage', context=None):
    _logger.error('write_to_ui_view')
    context = context or {}
    imd = self.pool.get('ir.model.data')
    view = self.pool.get('ir.ui.view')
    template_module, template_name = template.split('.')

    # completely arbitrary max_length
    page_name = url
    page_xmlid = "%s.%s" % (template_module, page_name)

    _, template_id = imd.get_object_reference(cr, uid, template_module, template_name)
    website_id = context.get('website_id')
    key = template_module+'.'+page_name
    page_id = None

    if view.search(cr, openerp.SUPERUSER_ID, [('key', '=', key)]):
        page_id = view.search(cr, openerp.SUPERUSER_ID, [('key', '=', key)])[0]
    else:
        page_id = view.copy(cr, uid, template_id, {'website_id': website_id, 'key': key}, context=context)
    page = view.browse(cr, uid, page_id, context=dict(context, lang=None))
    page.write({
        'arch': page.arch.replace(template, page_xmlid),
        'name': page_name,
        'page': ispage,
        'noindex': noindex
    })
    return page_xmlid

Now, I can use noindex filed in main_Object. But every time it return False. In DB present True but filed noindex return False...

I try to check value noindex on page. For this I added meta-tag to header and convert noindex to string:

<meta name="RB" content="noindex" ><t t-raw="str(main_object.noindex)"/></meta>

Here present result: enter image description here

In DB this record has value True: enter image description here

1

1 Answers

0
votes

Keep it simply...

I keep it with qweb template:

<template id="layout" inherit_id="website.layout">
                <xpath expr="html/head" position="inside">
                    <t t-if="page_data.noindex">
                            <meta name="robots" content="noindex" />
                    </t>
                </xpath>
</template>

<template id="servicepage">
            <t t-call="pr_filials.layout">...</t>
</template>

and I do not need any modified class.