def add_seo_url(self): """Add SEO urls for existing blogs and blog posts. If this module will be installed this function is called. It is needed for existing databases with existing blogs and blog posts. """ for blog in self.env['blog.blog'].search([('seo_url', '=', False)]): blog.write({'seo_url': slug(blog)}) for post in self.env['blog.post'].search([('seo_url', '=', False)]): post.write({'seo_url': slug(post)}) return True
def __call__(self, path=None, path_args=None, **kw): """Update the url generation to use the new SEO url structure.""" path = path or self.path for k, v in self.args.items(): kw.setdefault(k, v) path_args = set(path_args or []).union(self.path_args) paths, fragments = [], [] for key, value in kw.items(): if value and key in path_args: if isinstance(value, browse_record): paths.append((key, slug(value))) else: paths.append((key, value)) elif value: if isinstance(value, list) or isinstance(value, set): fragments.append( werkzeug.url_encode([(key, item) for item in value])) else: fragments.append(werkzeug.url_encode([(key, value)])) for key, value in paths: if key in ['blog', 'post', 'tag']: path += '/%s' % value else: path += '/' + key + '/%s' % value if fragments: path += '?' + '&'.join(fragments) return path
def create(self, vals): """Add check for correct SEO urls. Normally this case happens when a blog post is created in the frontend. """ if vals.get('name', False) and not vals.get('seo_url', False): vals['seo_url'] = slug((1, vals['name'])) return super(BlogPost, self).create(vals)
def create(self, vals): """Add check for correct SEO urls. """ if vals.get('name', False) and not vals.get('seo_url', False): vals['seo_url'] = slug((1, vals['name'])) if not vals.get('website_meta_robots', False): vals['website_meta_robots'] = self.get_default_meta_robots() return super(BlogTag, self).create(vals)
def onchange_name(self, name=False, seo_url=False): """If SEO url is empty generate the SEO url when changing the name.""" if name and not seo_url: return {'value': {'seo_url': slug((1, name))}} return {}
def write(self, vals): if len(self) == 1 and vals.get('name', False): vals['seo_url'] = slug((1, vals['name'])) return super(BlogPost, self).write(vals)