From fe40538aff2b65f7719840c8e2d6e51e858f560f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 11 Oct 2013 15:00:59 +0200 Subject: [PATCH] [IMP] website_blog: website view and routes improvements - cleaning of routes: now having blog/cat/category_id, blog/blog_post_id to simplify routes (previously: blog/category_id/blog_post_id, leading to issues when having routes using sometimes category_id, sometimes blog_post_id as first argument). - improved website templates: publish management, added duplication. misc cleaning of the display. bzr revid: tde@openerp.com-20131011130059-zum19mjvi336u9b4 --- addons/website_blog/controllers/main.py | 43 +++++++++++-------- .../views/website_blog_templates.xml | 39 +++++++++++------ 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index feb0544ce31..7d40e080636 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -35,10 +35,10 @@ class WebsiteBlog(http.Controller): @website.route([ '/blog/', - '/blog//', - '/blog///', - '/blog//page//', - '/blog///page//', + '/blog//', + '/blog//page//', + '/blog/cat//', + '/blog/cat//page//', '/blog/tag/', '/blog/tag//', ], type='http', auth="public") @@ -90,11 +90,13 @@ class WebsiteBlog(http.Controller): tag = tag_obj.browse(cr, uid, tag_id, context=context) if category_id: category = category_obj.browse(cr, uid, category_id, context=context) - - if category and blog_post_id: + elif blog_post_id: blog_post = blog_post_obj.browse(cr, uid, blog_post_id, context=context) blog_message_ids = blog_post.website_message_ids - else: + category = blog_post.category_id + category_id = category.id + + if not blog_post_id: if category and tag: blog_posts = [cat_post for cat_post in category.blog_post_ids if tag_id in [post_tag.id for post_tag in cat_post.tag_ids]] @@ -108,7 +110,7 @@ class WebsiteBlog(http.Controller): if blog_posts: pager = request.website.pager( - url="/blog/%s/" % category_id, + url="/blog/cat/%s/" % category_id, total=len(blog_posts), page=page, step=self._category_post_per_page, @@ -120,7 +122,7 @@ class WebsiteBlog(http.Controller): if blog_post: pager = request.website.pager( - url="/blog/%s/%s/" % (category_id, blog_post_id), + url="/blog/%s/" % blog_post_id, total=len(blog_message_ids), page=page, step=self._post_comment_per_page, @@ -138,8 +140,8 @@ class WebsiteBlog(http.Controller): nav[year]['months'].append(group) values = { - 'categories': categories, 'category': category, + 'categories': categories, 'tag': tag, 'blog_post': blog_post, 'blog_posts': blog_posts, @@ -170,13 +172,13 @@ class WebsiteBlog(http.Controller): ] return simplejson.dumps(blog_post_data) - @website.route(['/blog///post'], type='http', auth="public") - def blog_comment(self, category_id=None, blog_post_id=None, **post): + @website.route(['/blog//post'], type='http', auth="public") + def blog_post_comment(self, blog_post_id=None, **post): cr, uid, context = request.cr, request.uid, request.context url = request.httprequest.host_url request.session.body = post.get('body') if request.context['is_public_user']: # purpose of this ? - return '%s/admin#action=redirect&url=%s/blog/%s/%s/post' % (url, url, category_id, blog_post_id) + return '%s/admin#action=redirect&url=%s/blog/%s/post' % (url, url, blog_post_id) if request.session.get('body') and blog_post_id: request.registry['blog.post'].message_post( @@ -187,17 +189,24 @@ class WebsiteBlog(http.Controller): context=dict(context, mail_create_nosubcribe=True)) request.session.body = False - return werkzeug.utils.redirect("/blog/%s/%s/?unable_editor=1" % (category_id, blog_post_id)) + return werkzeug.utils.redirect("/blog/%s/?unable_editor=1" % (blog_post_id)) @website.route(['/blog//new'], type='http', auth="public") - def create_blog_post(self, category_id=None, **post): + def blog_post_create(self, category_id=None, **post): cr, uid, context = request.cr, request.uid, request.context create_context = dict(context, mail_create_nosubscribe=True) - blog_post_id = request.registry['blog.post'].create( + new_blog_post_id = request.registry['blog.post'].create( request.cr, request.uid, { 'category_id': category_id, 'name': _("Blog title"), 'content': '', 'website_published': False, }, context=create_context) - return werkzeug.utils.redirect("/blog/%s/%s/?unable_editor=1" % (category_id, blog_post_id)) + return werkzeug.utils.redirect("/blog/%s/?unable_editor=1" % (new_blog_post_id)) + + @website.route(['/blog//duplicate'], type='http', auth="public") + def blog_post_copy(self, blog_post_id=None, **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'].copy(cr, uid, blog_post_id, {}, context=create_context) + return werkzeug.utils.redirect("/blog/%s/?unable_editor=1" % (new_blog_post_id)) diff --git a/addons/website_blog/views/website_blog_templates.xml b/addons/website_blog/views/website_blog_templates.xml index c0565cea7d3..96ae25c321a 100644 --- a/addons/website_blog/views/website_blog_templates.xml +++ b/addons/website_blog/views/website_blog_templates.xml @@ -5,25 +5,34 @@