[FIX] website_blog: Show tag by blog. No interest to display all tag, anyway the search by tag is done for the current blog
This commit is contained in:
parent
dbc9241eaf
commit
b21b32ed2e
|
@ -135,9 +135,7 @@ class WebsiteBlog(http.Controller):
|
|||
pager_end = page * self._blog_post_per_page
|
||||
blog_posts = blog_posts[pager_begin:pager_end]
|
||||
|
||||
tag_obj = request.registry['blog.tag']
|
||||
tag_ids = tag_obj.search(cr, uid, [], context=context)
|
||||
tags = tag_obj.browse(cr, uid, tag_ids, context=context)
|
||||
tags = blog.all_tags()[blog.id]
|
||||
|
||||
values = {
|
||||
'blog': blog,
|
||||
|
|
|
@ -23,6 +23,32 @@ class Blog(osv.Model):
|
|||
'description': fields.text('Description'),
|
||||
}
|
||||
|
||||
def all_tags(self, cr, uid, ids, min_limit=1, context=None):
|
||||
req = """
|
||||
SELECT
|
||||
p.blog_id, count(*), r.blog_tag_id
|
||||
FROM
|
||||
blog_post_blog_tag_rel r
|
||||
join blog_post p on r.blog_post_id=p.id
|
||||
WHERE
|
||||
p.blog_id in %s
|
||||
GROUP BY
|
||||
p.blog_id,
|
||||
r.blog_tag_id
|
||||
ORDER BY
|
||||
count(*) DESC
|
||||
"""
|
||||
cr.execute(req, [tuple(ids)])
|
||||
tag_by_blog = {i: [] for i in ids}
|
||||
for blog_id, freq, tag_id in cr.fetchall():
|
||||
if freq >= min_limit:
|
||||
tag_by_blog[blog_id].append(tag_id)
|
||||
|
||||
tag_obj = self.pool['blog.tag']
|
||||
for blog_id in tag_by_blog:
|
||||
tag_by_blog[blog_id] = tag_obj.browse(cr, uid, tag_by_blog[blog_id], context=context)
|
||||
return tag_by_blog
|
||||
|
||||
|
||||
class BlogTag(osv.Model):
|
||||
_name = 'blog.tag'
|
||||
|
|
Loading…
Reference in New Issue