The /blog
path come from the defined path at file website_blog/controllers/main.py
under class WebsiteBlog(http.Controller):
. You can do the following to change /blog
to /news
:
- Create your own module inherited from
website_blog
module.
- Define
WebsiteBlog
class inherited from existing WebsiteBlog
.
- Redefine
def blog
with your own route like the following:
from odoo.addons.website_blog.controllers.main import WebsiteBlog
class WebsiteBlog(WebsiteBlog):
@http.route([
'/news',
'/news/page/<int:page>',
'/news/tag/<string:tag>',
'/news/tag/<string:tag>/page/<int:page>',
'''/news/<model("blog.blog"):blog>''',
'''/news/<model("blog.blog"):blog>/page/<int:page>''',
'''/news/<model("blog.blog"):blog>/tag/<string:tag>''',
'''/news/<model("blog.blog"):blog>/tag/<string:tag>/page/<int:page>''',
], type='http', auth="public", website=True, sitemap=True)
def news(self, blog=None, tag=None, page=1, search=None, **opt):
Blog = request.env['blog.blog']
if blog and not blog.can_access_from_current_website():
raise werkzeug.exceptions.NotFound()
blogs = Blog.search(request.website.website_domain(), order="create_date asc, id asc")
if not blog and len(blogs) == 1:
return werkzeug.utils.redirect('/news/%s' % slug(blogs[0]), code=302)
date_begin, date_end, state = opt.get('date_begin'), opt.get('date_end'), opt.get('state')
if tag and request.httprequest.method == 'GET':
# redirect get tag-1,tag-2 -> get tag-1
tags = tag.split(',')
if len(tags) > 1:
url = QueryURL('' if blog else '/news', ['blog', 'tag'], blog=blog, tag=tags[0], date_begin=date_begin, date_end=date_end, search=search)()
return request.redirect(url, code=302)
values = self._prepare_blog_values(blogs=blogs, blog=blog, date_begin=date_begin, date_end=date_end, tags=tag, state=state, page=page, search=search)
# in case of a redirection need by `_prepare_blog_values` we follow it
if isinstance(values, werkzeug.wrappers.Response):
return values
if blog:
values['main_object'] = blog
values['edit_in_backend'] = True
values['blog_url'] = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end, search=search)
else:
values['blog_url'] = QueryURL('/news', ['tag'], date_begin=date_begin, date_end=date_end, search=search)
return request.render("website_blog.blog_post_short", values)