[FIX] website_blog: Show tag by blog. No interest to display all tag, anyway the...
[odoo/odoo.git] / addons / website_blog / controllers / main.py
index 11e6c3f..5f2bea8 100644 (file)
 # -*- coding: utf-8 -*-
-##############################################################################
-#
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
-#
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU Affero General Public License as
-#    published by the Free Software Foundation, either version 3 of the
-#    License, or (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU Affero General Public License for more details.
-#
-#    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
 
+import datetime
+import werkzeug
+
+from openerp import tools
 from openerp.addons.web import http
 from openerp.addons.web.http import request
+from openerp.addons.website.models.website import slug
+from openerp.osv.orm import browse_record
 from openerp.tools.translate import _
 from openerp import SUPERUSER_ID
-
-import werkzeug
-import random
-import json
 from openerp.tools import html2plaintext
 
 
+class QueryURL(object):
+    def __init__(self, path='', path_args=None, **args):
+        self.path = path
+        self.args = args
+        self.path_args = set(path_args or [])
+
+    def __call__(self, path=None, path_args=None, **kw):
+        path = path or self.path
+        for k, v in self.args.items():
+            kw.setdefault(k, v)
+        path_args = set(path_args or []).union(self.path_args)
+        paths, fragments = [], []
+        for key, value in kw.items():
+            if value and key in path_args:
+                if isinstance(value, browse_record):
+                    paths.append((key, slug(value)))
+                else:
+                    paths.append((key, value))
+            elif value:
+                if isinstance(value, list) or isinstance(value, set):
+                    fragments.append(werkzeug.url_encode([(key, item) for item in value]))
+                else:
+                    fragments.append(werkzeug.url_encode([(key, value)]))
+        for key, value in paths:
+            path += '/' + key + '/%s' % value
+        if fragments:
+            path += '?' + '&'.join(fragments)
+        return path
+
+
 class WebsiteBlog(http.Controller):
-    _blog_post_per_page = 6
-    _post_comment_per_page = 6
+    _blog_post_per_page = 20
+    _post_comment_per_page = 10
 
     def nav_list(self):
         blog_post_obj = request.registry['blog.post']
-        groups = blog_post_obj.read_group(request.cr, request.uid, [], ['name', 'create_date'],
-            groupby="create_date", orderby="create_date asc", context=request.context)
+        groups = blog_post_obj.read_group(
+            request.cr, request.uid, [], ['name', 'create_date'],
+            groupby="create_date", orderby="create_date desc", context=request.context)
         for group in groups:
-            group['date'] = "%s_%s" % (group['__domain'][0][2], group['__domain'][1][2])
+            begin_date = datetime.datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
+            end_date = datetime.datetime.strptime(group['__domain'][1][2], tools.DEFAULT_SERVER_DATETIME_FORMAT).date()
+            group['date_begin'] = '%s' % datetime.date.strftime(begin_date, tools.DEFAULT_SERVER_DATE_FORMAT)
+            group['date_end'] = '%s' % datetime.date.strftime(end_date, tools.DEFAULT_SERVER_DATE_FORMAT)
         return groups
 
     @http.route([
         '/blog',
-        '/blog/page/<int:page>/',
-    ], type='http', auth="public", website=True, multilang=True)
-    def blogs(self, page=1):
-        BYPAGE = 60
+        '/blog/page/<int:page>',
+    ], type='http', auth="public", website=True)
+    def blogs(self, page=1, **post):
         cr, uid, context = request.cr, request.uid, request.context
         blog_obj = request.registry['blog.post']
         total = blog_obj.search(cr, uid, [], count=True, context=context)
         pager = request.website.pager(
-            url='/blog/',
+            url='/blog',
             total=total,
             page=page,
-            step=BYPAGE,
+            step=self._blog_post_per_page,
         )
-        bids = blog_obj.search(cr, uid, [], offset=(page-1)*BYPAGE, limit=BYPAGE, context=context)
-        blogs = blog_obj.browse(cr, uid, bids, context=context)
+        post_ids = blog_obj.search(cr, uid, [], offset=(page-1)*self._blog_post_per_page, limit=self._blog_post_per_page, context=context)
+        posts = blog_obj.browse(cr, uid, post_ids, context=context)
+        blog_url = QueryURL('', ['blog', 'tag'])
         return request.website.render("website_blog.latest_blogs", {
-            'blogs': blogs,
-            'pager': pager
+            'posts': posts,
+            'pager': pager,
+            'blog_url': blog_url,
         })
 
     @http.route([
-        '/blog/<model("blog.blog"):blog>/',
-        '/blog/<model("blog.blog"):blog>/page/<int:page>/',
-        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/',
-        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/page/<int:page>/',
-        '/blog/<model("blog.blog"):blog>/date/<string(length=21):date>/',
-        '/blog/<model("blog.blog"):blog>/date/<string(length=21):date>/page/<int:page>/',
-        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/date/<string(length=21):date>/',
-        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/date/<string(length=21):date>/page/<int:page>/',
-    ], type='http', auth="public", website=True, multilang=True)
-    def blog(self, blog=None, tag=None, date=None, page=1, **opt):
+        '/blog/<model("blog.blog"):blog>',
+        '/blog/<model("blog.blog"):blog>/page/<int:page>',
+        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>',
+        '/blog/<model("blog.blog"):blog>/tag/<model("blog.tag"):tag>/page/<int:page>',
+    ], type='http', auth="public", website=True)
+    def blog(self, blog=None, tag=None, page=1, **opt):
         """ Prepare all values to display the blog.
 
-        :param blog: blog currently browsed.
-        :param tag: tag that is currently used to filter blog posts
-        :param integer page: current page of the pager. Can be the blog or
-                            post pager.
-        :param date: date currently used to filter blog posts (dateBegin_dateEnd)
-
         :return dict values: values for the templates, containing
 
-         - 'blog_posts': list of browse records that are the posts to display
-                         in a given blog, if not blog_post_id
-         - 'blog': browse of the current blog, if blog_id
-         - 'blogs': list of browse records of blogs
-         - 'pager': the pager to display posts pager in a blog
-         - 'tag': current tag, if tag_id
+         - 'blog': current blog
+         - 'blogs': all blogs for navigation
+         - 'pager': pager of posts
+         - 'tag': current tag
+         - 'tags': all tags, for navigation
          - 'nav_list': a dict [year][month] for archives navigation
+         - 'date': date_begin optional parameter, used in archives navigation
+         - 'blog_url': help object to create URLs
         """
-        BYPAGE = 10
+        date_begin, date_end = opt.get('date_begin'), opt.get('date_end')
 
         cr, uid, context = request.cr, request.uid, request.context
         blog_post_obj = request.registry['blog.post']
 
-        blog_posts = None
-
         blog_obj = request.registry['blog.blog']
-        blog_ids = blog_obj.search(cr, uid, [], context=context)
+        blog_ids = blog_obj.search(cr, uid, [], order="create_date asc", context=context)
         blogs = blog_obj.browse(cr, uid, blog_ids, context=context)
 
-        path_filter = ""
         domain = []
-
         if blog:
-            path_filter += "%s/" % blog.id
-            domain += [("id", "in", [post.id for post in blog.blog_post_ids])]
+            domain += [('blog_id', '=', blog.id)]
         if tag:
-            path_filter += 'tag/%s/' % tag.id
-            domain += [("id", "in", [post.id for post in tag.blog_post_ids])]
-        if date:
-            path_filter += "date/%s/" % date
-            domain += [("create_date", ">=", date.split("_")[0]), ("create_date", "<=", date.split("_")[1])]
+            domain += [('tag_ids', 'in', tag.id)]
+        if date_begin and date_end:
+            domain += [("create_date", ">=", date_begin), ("create_date", "<=", date_end)]
+
+        blog_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end)
+        post_url = QueryURL('', ['blogpost'], tag_id=tag and tag.id or None, date_begin=date_begin, date_end=date_end)
 
-        blog_post_ids = blog_post_obj.search(cr, uid, domain, context=context)
+        blog_post_ids = blog_post_obj.search(cr, uid, domain, order="create_date desc", context=context)
         blog_posts = blog_post_obj.browse(cr, uid, blog_post_ids, context=context)
 
         pager = request.website.pager(
-            url="/blog/%s" % path_filter,
+            url=blog_url(),
             total=len(blog_posts),
             page=page,
             step=self._blog_post_per_page,
-            scope=BYPAGE
         )
         pager_begin = (page - 1) * self._blog_post_per_page
         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,
@@ -143,41 +145,34 @@ class WebsiteBlog(http.Controller):
             'blog_posts': blog_posts,
             'pager': pager,
             'nav_list': self.nav_list(),
-            'path_filter': path_filter,
-            'date': date,
+            'blog_url': blog_url,
+            'post_url': post_url,
+            'date': date_begin,
         }
         response = request.website.render("website_blog.blog_post_short", values)
-        response.set_cookie('unvisited', json.dumps(blog_post_ids))
         return response
 
     @http.route([
-        '/blogpost/<model("blog.post"):blog_post>/',
-    ], type='http', auth="public", website=True, multilang=True)
-    def blog_post(self, blog_post, tag=None, date=None, page=1, enable_editor=None, **post):
+            '''/blog/<model("blog.blog"):blog>/post/<model("blog.post", "[('blog_id','=',blog[0])]"):blog_post>''',
+    ], type='http', auth="public", website=True)
+    def blog_post(self, blog, blog_post, tag_id=None, page=1, enable_editor=None, **post):
         """ Prepare all values to display the blog.
 
-        :param blog_post: blog post currently browsed. If not set, the user is
-                          browsing the blog and a post pager is calculated.
-                          If set the user is reading the blog post and a
-                          comments pager is calculated.
-        :param blog: blog currently browsed.
-        :param tag: tag that is currently used to filter blog posts
-        :param integer page: current page of the pager. Can be the blog or
-                            post pager.
-        :param date: date currently used to filter blog posts (dateBegin_dateEnd)
-
-         - 'enable_editor': editor control
-
         :return dict values: values for the templates, containing
 
-         - 'blog_post': browse of the current post, if blog_post_id
-         - 'blog': browse of the current blog, if blog_id
+         - 'blog_post': browse of the current post
+         - 'blog': browse of the current blog
          - 'blogs': list of browse records of blogs
-         - 'pager': the pager to display comments pager in a blog post
-         - 'tag': current tag, if tag_id
+         - 'tag': current tag, if tag_id in parameters
+         - 'tags': all tags, for tag-based navigation
+         - 'pager': a pager on the comments
          - 'nav_list': a dict [year][month] for archives navigation
-         - 'next_blog': next blog post , display in footer
+         - 'next_post': next blog post, to direct the user towards the next interesting post
         """
+        cr, uid, context = request.cr, request.uid, request.context
+        tag_obj = request.registry['blog.tag']
+        blog_post_obj = request.registry['blog.post']
+        date_begin, date_end = post.get('date_begin'), post.get('date_end')
 
         pager_url = "/blogpost/%s" % blog_post.id
 
@@ -190,110 +185,130 @@ class WebsiteBlog(http.Controller):
         )
         pager_begin = (page - 1) * self._post_comment_per_page
         pager_end = page * self._post_comment_per_page
-        blog_post.website_message_ids = blog_post.website_message_ids[pager_begin:pager_end]
-
-        cr, uid, context = request.cr, request.uid, request.context
-        blog_obj = request.registry['blog.blog']
-        blog_ids = blog_obj.search(cr, uid, [], context=context)
-        blogs = blog_obj.browse(cr, uid, blog_ids, context=context)
+        comments = blog_post.website_message_ids[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)
+        tag = None
+        if tag_id:
+            tag = request.registry['blog.tag'].browse(request.cr, request.uid, int(tag_id), context=request.context)
+        post_url = QueryURL('', ['blogpost'], blogpost=blog_post, tag_id=tag_id, date_begin=date_begin, date_end=date_end)
+        blog_url = QueryURL('', ['blog', 'tag'], blog=blog_post.blog_id, tag=tag, date_begin=date_begin, date_end=date_end)
 
-        blog_post_obj = request.registry.get('blog.post')
-        if not request.httprequest.session.get(blog_post.id,False):
-                request.httprequest.session[blog_post.id] = True
-                counter = blog_post.visits + 1;
-                blog_post_obj.write(cr, SUPERUSER_ID, [blog_post.id], {'visits':counter},context=context)
+        if not blog_post.blog_id.id == blog.id:
+            return request.redirect("/blog/%s/post/%s" % (slug(blog_post.blog_id), slug(blog_post)))
 
-        MONTHS = [None, _('January'), _('February'), _('March'), _('April'),
-            _('May'), _('June'), _('July'), _('August'), _('September'),
-            _('October'), _('November'), _('December')]
+        tags = tag_obj.browse(cr, uid, tag_obj.search(cr, uid, [], context=context), context=context)
 
         # Find next Post
         visited_blogs = request.httprequest.cookies.get('visited_blogs') or ''
-        visited_ids = map(lambda x: int(x or blog_post.id), visited_blogs.split(',')) + [blog_post.id]
+        visited_ids = filter(None, visited_blogs.split(','))
+        visited_ids = map(lambda x: int(x), visited_ids)
         if blog_post.id not in visited_ids:
             visited_ids.append(blog_post.id)
         next_post_id = blog_post_obj.search(cr, uid, [
             ('id', 'not in', visited_ids),
-            ], order='visits desc', limit=1, context=context)
+        ], order='ranking desc', limit=1, context=context)
+        if not next_post_id:
+            next_post_id = blog_post_obj.search(cr, uid, [('id', '!=', blog.id)], order='ranking desc', limit=1, context=context)
         next_post = next_post_id and blog_post_obj.browse(cr, uid, next_post_id[0], context=context) or False
 
         values = {
-            'blog': blog_post.blog_id,
-            'blogs': blogs,
             'tags': tags,
-            'tag': tag and request.registry['blog.tag'].browse(cr, uid, int(tag), context=context) or None,
+            'tag': tag,
+            'blog': blog,
             'blog_post': blog_post,
             'main_object': blog_post,
-            'pager': pager,
             'nav_list': self.nav_list(),
             'enable_editor': enable_editor,
-            'date': date,
-            'date_name': date and "%s %s" % (MONTHS[int(date.split("-")[1])], date.split("-")[0]) or None,
-            'next_post' : next_post,
+            'next_post': next_post,
+            'date': date_begin,
+            'post_url': post_url,
+            'blog_url': blog_url,
+            'pager': pager,
+            'comments': comments,
         }
         response = request.website.render("website_blog.blog_post_complete", values)
         response.set_cookie('visited_blogs', ','.join(map(str, visited_ids)))
+
+        request.session[request.session_id] = request.session.get(request.session_id, [])
+        if not (blog_post.id in request.session[request.session_id]):
+            request.session[request.session_id].append(blog_post.id)
+            # Increase counter
+            blog_post_obj.write(cr, SUPERUSER_ID, [blog_post.id], {
+                'visits': blog_post.visits+1,
+            },context=context)
         return response
 
     def _blog_post_message(self, user, blog_post_id=0, **post):
         cr, uid, context = request.cr, request.uid, request.context
         blog_post = request.registry['blog.post']
+        partner_obj = request.registry['res.partner']
+
+        if uid != request.website.user_id.id:
+            partner_ids = [user.partner_id.id]
+        else:
+            partner_ids = blog_post._find_partner_from_emails(
+                cr, SUPERUSER_ID, 0, [post.get('email')], context=context)
+            if not partner_ids or not partner_ids[0]:
+                partner_ids = [partner_obj.create(cr, SUPERUSER_ID, {'name': post.get('name'), 'email': post.get('email')}, context=context)]
+
         message_id = blog_post.message_post(
             cr, SUPERUSER_ID, int(blog_post_id),
             body=post.get('comment'),
             type='comment',
             subtype='mt_comment',
-            author_id= user.partner_id.id,
-            discussion=post.get('discussion'),
-            context=dict(context, mail_create_nosubcribe=True))
+            author_id=partner_ids[0],
+            path=post.get('path', False),
+            context=context)
         return message_id
 
     @http.route(['/blogpost/comment'], type='http', auth="public", methods=['POST'], website=True)
     def blog_post_comment(self, blog_post_id=0, **post):
         cr, uid, context = request.cr, request.uid, request.context
         if post.get('comment'):
-            user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
-            group_ids = user.groups_id
-            group_id = request.registry["ir.model.data"].get_object_reference(cr, uid, 'website_mail', 'group_comment')[1]
-            if group_id in [group.id for group in group_ids]:
-                blog_post = request.registry['blog.post']
-                blog_post.check_access_rights(cr, uid, 'read')
-                self._blog_post_message(user, blog_post_id, **post)
+            user = request.registry['res.users'].browse(cr, uid, uid, context=context)
+            blog_post = request.registry['blog.post']
+            blog_post.check_access_rights(cr, uid, 'read')
+            self._blog_post_message(user, blog_post_id, **post)
         return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
 
-    @http.route(['/blogpost/post_discussion'], type='json', auth="public", website=True)
-    def post_discussion(self, blog_post_id=0, **post):
+    def _get_discussion_detail(self, ids, publish=False, **post):
         cr, uid, context = request.cr, request.uid, request.context
         values = []
-        if post.get('comment'):
-            user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
-            id = self._blog_post_message(user, blog_post_id, **post)
-            mail_obj = request.registry.get('mail.message')
-            post = mail_obj.browse(cr, SUPERUSER_ID, id)
-            values = {
-                "author_name": post.author_id.name,
-                "date": post.date,
-                "body": html2plaintext(post.body),
-                "author_image": "data:image/png;base64,%s" % post.author_id.image,
-                }
+        mail_obj = request.registry.get('mail.message')
+        for message in mail_obj.browse(cr, SUPERUSER_ID, ids, context=context):
+            values.append({
+                "id": message.id,
+                "author_name": message.author_id.name,
+                "author_image": message.author_id.image and \
+                    ("data:image/png;base64,%s" % message.author_id.image) or \
+                    '/website_blog/static/src/img/anonymous.png',
+                "date": message.date,
+                'body': html2plaintext(message.body),
+                'website_published' : message.website_published,
+                'publish' : publish,
+            })
         return values
-    
-    @http.route('/blogpost/new', type='http', auth="public", website=True, multilang=True)
+
+    @http.route(['/blogpost/post_discussion'], type='json', auth="public", website=True)
+    def post_discussion(self, blog_post_id, **post):
+        cr, uid, context = request.cr, request.uid, request.context
+        publish = request.registry['res.users'].has_group(cr, uid, 'base.group_website_publisher')
+        user = request.registry['res.users'].browse(cr, uid, uid, context=context)
+        id = self._blog_post_message(user, blog_post_id, **post)
+        return self._get_discussion_detail([id], publish, **post)
+
+    @http.route('/blogpost/new', type='http', auth="public", website=True)
     def blog_post_create(self, blog_id, **post):
         cr, uid, context = request.cr, request.uid, request.context
-        create_context = dict(context, mail_create_nosubscribe=True)
-        new_blog_post_id = request.registry['blog.post'].create(
-            request.cr, request.uid, {
-                'blog_id': blog_id,
-                'name': _("Blog Post Title"),
-                'content': '',
-                'website_published': False,
-            }, context=create_context)
-        return werkzeug.utils.redirect("/blogpost/%s/?enable_editor=1" % new_blog_post_id)
+        new_blog_post_id = request.registry['blog.post'].create(cr, uid, {
+            'blog_id': blog_id,
+            'name': _("Blog Post Title"),
+            'subtitle': _("Subtitle"),
+            'content': '',
+            'website_published': False,
+        }, context=context)
+        new_blog_post = request.registry['blog.post'].browse(cr, uid, new_blog_post_id, context=context)
+        return werkzeug.utils.redirect("/blog/%s/post/%s?enable_editor=1" % (slug(new_blog_post.blog_id), slug(new_blog_post)))
 
     @http.route('/blogpost/duplicate', type='http', auth="public", website=True)
     def blog_post_copy(self, blog_post_id, **post):
@@ -305,35 +320,39 @@ class WebsiteBlog(http.Controller):
         """
         cr, uid, context = request.cr, request.uid, request.context
         create_context = dict(context, mail_create_nosubscribe=True)
-        new_blog_post_id = request.registry['blog.post'].copy(cr, uid, blog_post_id, {}, context=create_context)
-        return werkzeug.utils.redirect("/blogpost/%s/?enable_editor=1" % new_blog_post_id)
+        nid = request.registry['blog.post'].copy(cr, uid, blog_post_id, {}, context=create_context)
+        new_blog_post = request.registry['blog.post'].browse(cr, uid, nid, context=context)
+        post = request.registry['blog.post'].browse(cr, uid, nid, context)
+        return werkzeug.utils.redirect("/blog/%s/post/%s?enable_editor=1" % (slug(post.blog_id), slug(new_blog_post)))
 
-    @http.route('/blogpost/get_discussion', type='json', auth="public", website=True)
-    def discussion(self, post_id=0, discussion=None, **post):
+    @http.route('/blogpost/get_discussion/', type='json', auth="public", website=True)
+    def discussion(self, post_id=0, path=None, count=False, **post):
+        cr, uid, context = request.cr, request.uid, request.context
         mail_obj = request.registry.get('mail.message')
-        values = []
-        ids = mail_obj.search(request.cr, SUPERUSER_ID, [('res_id', '=', int(post_id)) ,('model','=','blog.post'), ('discussion', '=', discussion)])
-        if ids:
-            for post in mail_obj.browse(request.cr, SUPERUSER_ID, ids):
-                values.append({
-                    "author_name": post.author_id.name,
-                    "date": post.date,
-                    'body': html2plaintext(post.body),
-                    'author_image': "data:image/png;base64,%s" % post.author_id.image,
-                })
-        return values
-
-    @http.route('/blogpsot/change_background', type='json', auth="public", website=True)
-    def change_bg(self, post_id=0,image=None, **post):
-        post_obj = request.registry.get('blog.post')
-        values = {'content_image' : image}
-        ids = post_obj.write(request.cr, SUPERUSER_ID, [int(post_id)], values)
-        return []
-
-    @http.route('/blogpsot/get_custom_options', type='json', auth="public", website=True)
-    def get_custom_options(self, post_id=0,image=None, **post):
-        values = {}
-        inherit_options = request.registry.get('ir.ui.view').search_read(request.cr, SUPERUSER_ID, [('name','in',['Inline Discussion','Select to Tweet'])], ['inherit_id','name'])
-        for options in inherit_options:
-            values[options.get('name')] = options.get('inherit_id')
-        return values
+        domain = [('res_id', '=', int(post_id)), ('model', '=', 'blog.post'), ('path', '=', path)]
+        #check current user belongs to website publisher group
+        publish = request.registry['res.users'].has_group(cr, uid, 'base.group_website_publisher')
+        if not publish:
+            domain.append(('website_published', '=', True))
+        ids = mail_obj.search(cr, SUPERUSER_ID, domain, count=count)
+        if count:
+            return ids
+        return self._get_discussion_detail(ids, publish, **post)
+
+    @http.route('/blogpost/get_discussions/', type='json', auth="public", website=True)
+    def discussions(self, post_id=0, paths=None, count=False, **post):
+        ret = []
+        for path in paths:
+            result = self.discussion(post_id=post_id, path=path, count=count, **post)
+            ret.append({"path": path, "val": result})
+        return ret
+
+    @http.route('/blogpost/change_background', type='json', auth="public", website=True)
+    def change_bg(self, post_id=0, image=None, **post):
+        if not post_id:
+            return False
+        return request.registry['blog.post'].write(request.cr, request.uid, [int(post_id)], {'background_image': image}, request.context)
+
+    @http.route('/blog/get_user/', type='json', auth="public", website=True)
+    def get_user(self, **post):
+        return [False if request.session.uid else True]