[FIX] website_blog: Show tag by blog. No interest to display all tag, anyway the...
authorJeremy Kersten <jke@odoo.com>
Tue, 2 Dec 2014 09:28:18 +0000 (10:28 +0100)
committerJeremy Kersten <jke@odoo.com>
Tue, 2 Dec 2014 10:35:29 +0000 (11:35 +0100)
addons/website_blog/controllers/main.py
addons/website_blog/models/website_blog.py

index b6812de..5f2bea8 100644 (file)
@@ -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,
index 4aa78f6..94cee66 100644 (file)
@@ -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'