fix #I7J61Y [app_website_blog_editor]让博文分类的显示按sequence排序

This commit is contained in:
Chill
2023-07-07 18:47:02 +08:00
parent 5c82965036
commit ae44f2023c
25 changed files with 439 additions and 1 deletions

View File

@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
# from . import main
from . import main

View File

@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
import re
import werkzeug
from odoo import http, fields, tools
from odoo.addons.http_routing.models.ir_http import slug, unslug
from odoo.addons.website.controllers.main import QueryURL
from odoo.http import request
from odoo.addons.website_blog.controllers.main import WebsiteBlog
class WebsiteBlog(WebsiteBlog):
@http.route([
'/blog',
'/blog/page/<int:page>',
'/blog/tag/<string:tag>',
'/blog/tag/<string:tag>/page/<int:page>',
'''/blog/<model("blog.blog"):blog>''',
'''/blog/<model("blog.blog"):blog>/page/<int:page>''',
'''/blog/<model("blog.blog"):blog>/tag/<string:tag>''',
'''/blog/<model("blog.blog"):blog>/tag/<string:tag>/page/<int: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)

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="group_01" model="product.attribute.value.group">
<field name="name">CHN</field>
<field name="ref">CN</field>
</record>
<record id="group_02" model="product.attribute.value.group">
<field name="name">Eur</field>
<field name="ref">EU</field>
</record>
<record id="group_03" model="product.attribute.value.group">
<field name="name">US</field>
<field name="ref">US</field>
</record>
</data>
</odoo>

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo import api, models, fields, _
from odoo.tools.safe_eval import safe_eval
class BlogBlog(models.Model):
@@ -9,3 +10,9 @@ class BlogBlog(models.Model):
# 排序
sequence = fields.Integer(string='Sequence', default=20, index=True, help="Determine the display order")
def action_view_blog_post(self):
self.ensure_one()
action = self.env.ref('website_blog.action_blog_post').read()[0]
action['domain'] = [('blog_id', '=', self.id)]
return action

View File

@@ -11,6 +11,20 @@
</xpath>
</field>
</record>
<record id="app_view_blog_blog_form" model="ir.ui.view">
<field name="name">app.blog.blog.form</field>
<field name="model">blog.blog</field>
<field name="inherit_id" ref="website_blog.view_blog_blog_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet//group" position="before">
<div class="oe_button_box" name="button_box">
<button name="action_view_blog_post" type="object" class="oe_stat_button">
<field name="blog_post_count" widget="statinfo"/>
</button>
</div>
</xpath>
</field>
</record>
</odoo>