From 7f770210b87739a1a8770692793d23d42dee4edc Mon Sep 17 00:00:00 2001 From: ivan deng Date: Sun, 23 Jul 2023 17:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E7=AB=99=E4=BC=98=E5=8C=96misc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app_website_blog_editor/controllers/main.py | 64 ++------------------- 1 file changed, 5 insertions(+), 59 deletions(-) diff --git a/app_website_blog_editor/controllers/main.py b/app_website_blog_editor/controllers/main.py index 5d05281d..5c278a77 100644 --- a/app_website_blog_editor/controllers/main.py +++ b/app_website_blog_editor/controllers/main.py @@ -11,62 +11,8 @@ from odoo.addons.website_blog.controllers.main import WebsiteBlog class WebsiteBlog(WebsiteBlog): - @http.route([ - '/blog', - '/blog/page/', - '/blog/tag/', - '/blog/tag//page/', - '''/blog/''', - '''/blog//page/''', - '''/blog//tag/''', - '''/blog//tag//page/''', - ], type='http', auth="public", website=True, sitemap=True) - def blog(self, blog=None, tag=None, page=1, search=None, **opt): - Blog = request.env['blog.blog'] - - # TODO adapt in master. This is a fix for templates wrongly using the - # 'blog_url' QueryURL which is defined below. Indeed, in the case where - # we are rendering a blog page where no specific blog is selected we - # define(d) that as `QueryURL('/blog', ['tag'], ...)` but then some - # parts of the template used it like this: `blog_url(blog=XXX)` thus - # generating an URL like "/blog?blog=blog.blog(2,)". Adding "blog" to - # the list of params would not be right as would create "/blog/blog/2" - # which is still wrong as we want "/blog/2". And of course the "/blog" - # prefix in the QueryURL definition is needed in case we only specify a - # tag via `blog_url(tab=X)` (we expect /blog/tag/X). Patching QueryURL - # or making blog_url a custom function instead of a QueryURL instance - # could be a solution but it was judged not stable enough. We'll do that - # in master. Here we only support "/blog?blog=blog.blog(2,)" URLs. - if isinstance(blog, str): - blog = Blog.browse(int(re.search(r'\d+', blog)[0])) - if not blog.exists(): - raise werkzeug.exceptions.NotFound() - - blogs = tools.lazy(lambda: Blog.search(request.website.website_domain(), order="sequence asc, name asc")) - - if not blog and len(blogs) == 1: - url = QueryURL('/blog/%s' % slug(blogs[0]), search=search, **opt)() - return request.redirect(url, 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 '/blog', ['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['blog_url'] = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end, search=search) - else: - values['blog_url'] = QueryURL('/blog', ['tag'], date_begin=date_begin, date_end=date_end, search=search) - - return request.render("website_blog.blog_post_short", values) + def _prepare_blog_values(self, blogs, blog=False, date_begin=False, date_end=False, tags=False, state=False, page=False, search=None): + blogs = blogs.sorted(key='sequence') + res = super(WebsiteBlog, self)._prepare_blog_values(blogs, blog, date_begin, date_end, tags, state, page, search) + return res +