[IMP] website_blog: use 2 different URL schemes (post and blog), to ease url use...
authorThibault Delavallée <tde@openerp.com>
Tue, 1 Apr 2014 09:20:26 +0000 (11:20 +0200)
committerThibault Delavallée <tde@openerp.com>
Tue, 1 Apr 2014 09:20:26 +0000 (11:20 +0200)
bzr revid: tde@openerp.com-20140401092026-2patc88e0xu6ghyx

addons/website_blog/controllers/main.py
addons/website_blog/views/website_blog_templates.xml

index 199cf07..aeecaaa 100644 (file)
@@ -94,11 +94,11 @@ class WebsiteBlog(http.Controller):
         )
         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)
-        current_url = QueryURL('', ['blog', 'tag'])
+        blog_url = QueryURL('', ['blog', 'tag'])
         return request.website.render("website_blog.latest_blogs", {
             'posts': posts,
             'pager': pager,
-            'current_url': current_url,
+            'blog_url': blog_url,
         })
 
     @http.route([
@@ -145,13 +145,15 @@ class WebsiteBlog(http.Controller):
             domain += [("id", "in", [post.id for post in tag.blog_post_ids])]
         if date_begin and date_end:
             domain += [("create_date", ">=", date_begin), ("create_date", "<=", date_end)]
-        current_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=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, order="create_date asc", context=context)
         blog_posts = blog_post_obj.browse(cr, uid, blog_post_ids, context=context)
 
         pager = request.website.pager(
-            url=current_url(),
+            url=blog_url(),
             total=len(blog_posts),
             page=page,
             step=self._blog_post_per_page,
@@ -172,7 +174,8 @@ class WebsiteBlog(http.Controller):
             'blog_posts': blog_posts,
             'pager': pager,
             'nav_list': self.nav_list(),
-            'current_url': current_url,
+            'blog_url': blog_url,
+            'post_url': post_url,
             'date': date_begin,
         }
         return request.website.render("website_blog.blog_post_short", values)
@@ -221,9 +224,9 @@ class WebsiteBlog(http.Controller):
 
         tag = None
         if tag_id:
-            tag = request.registry['blog.tag'].browse(request.cr, request.uid, tag_id, context=request.context)
-
-        current_url = QueryURL('', ['blogpost'], blogpost=blog_post, tag_id=tag_id, date_begin=date_begin, date_end=date_end)
+            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)
 
         cr, uid, context = request.cr, request.uid, request.context
         blog_obj = request.registry['blog.blog']
@@ -245,7 +248,8 @@ class WebsiteBlog(http.Controller):
             'nav_list': self.nav_list(),
             'enable_editor': enable_editor,
             'date': date_begin,
-            'current_url': current_url
+            'post_url': post_url,
+            'blog_url': blog_url,
         }
         return request.website.render("website_blog.blog_post_complete", values)
 
index 5df7338..1fd1d7a 100644 (file)
@@ -53,7 +53,7 @@
                     <t t-foreach="posts" t-as="post">
                       <div class="col-md-4">
                         <h4>
-                            <a t-attf-href="#{current_url('', ['blogpost'], blogpost=post)}" t-field="post.name"></a>
+                            <a t-attf-href="#{blog_url('', ['blogpost'], blogpost=post)}" t-field="post.name"></a>
                             <span t-if="not post.website_published" class="text-warning">
                                 &amp;nbsp;
                                 <span class="fa fa-warning" title="Not published"/>
@@ -62,7 +62,7 @@
                         <div class="text-muted">
                             <span class="fa fa-calendar"> <span t-field="post.create_date"/> &amp;nbsp;</span>
                             <span class="fa fa-folder-open"> In
-                                <a t-attf-href="#{current_url(blog=post.blog_id)}">
+                                <a t-attf-href="#{blog_url(blog=post.blog_id)}">
                                 <span t-field="post.blog_id"/>
                                 </a> &amp;nbsp;
                             </span>
@@ -75,7 +75,7 @@
                         </div>
                         <div class="text-muted" t-if="len(post.message_ids) &gt; 0">
                             <span class="fa fa-comment-o">
-                                <a t-attf-href="#{current_url('', ['blogpost'], blogpost=post)}#comments">
+                                <a t-attf-href="#{blog_url('', ['blogpost'], blogpost=post)}#comments">
                                     <t t-if="len(post.message_ids) &lt;= 1" ><t t-esc="len(post.message_ids)"/> comment</t>
                                     <t t-if="len(post.message_ids) > 1"><t t-esc="len(post.message_ids)"/> comments</t>
                                 </a>
     <t t-foreach="blog_posts" t-as="blog_post">
       <div t-att-data-publish="blog_post.website_published and 'on' or 'off'">
         <h2 class="text-center">
-            <a t-attf-href="#{current_url('', ['blogpost'], blogpost=blog_post, blog=None, tag_id=tag and tag.id or None, tag=None)}" t-field="blog_post.name"></a>
+            <a t-attf-href="#{post_url(blogpost=blog_post)}" t-field="blog_post.name"></a>
         </h2>
         <p class="post-meta text-muted text-center" name='blog_post_data'>
             <span class="fa fa-calendar oe_date"> <span t-field="blog_post.create_date"/> &amp;nbsp;</span>
             <span t-if="len(blog_post.message_ids) &gt; 0" class="fa fa-comment-o">
-                <a t-attf-href="#{current_url('', ['blogpost'], blogpost=blog_post, blog=None)}#comments">
+                <a t-attf-href="#{post_url(blogpost=blog_post)}#comments">
                     <t t-if="len(blog_post.message_ids) &lt;= 1" ><t t-esc="len(blog_post.message_ids)"/> comment</t>
                     <t t-if="len(blog_post.message_ids) > 1"><t t-esc="len(blog_post.message_ids)"/> comments</t>
                 </a>
         <p class="post-meta text-muted text-center" t-if="len(blog_post.tag_ids)">
             <span class="fa fa-tags"/>
             <t t-foreach="blog_post.tag_ids" t-as="tag">
-                <a t-attf-href="#{current_url(tag_id=tag.id)}" t-esc="tag.name"/> &amp;nbsp;
+                <a t-attf-href="#{blog_url(tag=tag)}" t-esc="tag.name"/> &amp;nbsp;
             </t>
         </p>
     </xpath>
           <div class="row">
             <div class="col-sm-9">
                 <ol class="breadcrumb">
-                    <li><a t-attf-href="/blog/#{ slug(blog) }"><span t-field="blog.name"/></a></li>
-                    <li t-if="tag"><a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag) }"><span t-field="tag.name"/></a></li>
-                    <li t-if="tag and date"><a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag) }/date/#{ date }" t-esc="date_name"/></li>
-                    <li t-if="not tag and date"><a t-attf-href="/blog/#{ slug(blog) }/date/#{ date }" t-esc="date_name"/></li>
+                    <li><a t-attf-href="#{blog_url(tag=None, date_begin=None, date_end=None)}"><span t-field="blog.name"/></a></li>
+                    <li t-if="tag"><a t-attf-href="#{blog_url(date_begin=None, date_end=None)}"><span t-field="tag.name"/></a></li>
+                    <li t-if="date"><a t-attf-href="#{blog_url(tag=None)}" t-esc="date"/></li>
                     <li class="active"><span t-field="blog_post.name"/></li>
                 </ol>
             </div><div class="col-sm-3">
         <p class="post-meta text-muted text-center" t-if="len(blog_post.tag_ids)">
             <span class="fa fa-tags"/>
             <t t-foreach="blog_post.tag_ids" t-as="tag">
-                <a t-attf-href="/blog/#{ slug(blog) }/tag/#{ slug(tag) }" t-esc="tag.name"/> &amp;nbsp;
+                <a t-attf-href="#{blog_url(tag=tag)}" t-esc="tag.name"/> &amp;nbsp;
             </t>
         </p>
     </xpath>
         <section class="mt32">
         <h4>Tags</h4>
         <ul class="nav nav-pills nav-stacked">
-            <t t-foreach="tags" t-as="tag_id">
-            <li t-att-class="tag and tag_id.id == tag.id and 'active' or None" style="display: inline-block;">
-                <a t-attf-href="#{current_url(tag_id=tag_id)}"><span t-field="tag_id.name"/></a>
+            <t t-foreach="tags" t-as="nav_tag">
+            <li t-att-class="tag and tag.id == nav_tag.id and 'active' or None" style="display: inline-block;">
+                <a t-attf-href="#{blog_url(tag=nav_tag)}"><span t-field="nav_tag.name"/></a>
             </li>
             </t>
         </ul>
         <ul class="nav nav-pills nav-stacked">
             <t t-foreach="nav_list" t-as="months">
             <li t-att-class="months['date_begin'] == date and 'active' or None">
-                <a t-ignore="True" t-attf-href="#{current_url(tag_id=tag, date_begin=months['date_begin'], date_end=months['date_end'])}"><t t-esc="months['create_date']"/><span class="pull-right badge" t-esc="months['create_date_count']"/></a>
+                <a t-ignore="True" t-attf-href="#{blog_url(date_begin=months['date_begin'], date_end=months['date_end'])}"><t t-esc="months['create_date']"/><span class="pull-right badge" t-esc="months['create_date_count']"/></a>
             </li>
             </t>
         </ul>
         <ul class="nav nav-pills nav-stacked">
             <t t-foreach="blogs" t-as="nav_blog">
                 <li t-att-class="nav_blog.id == blog.id and 'active' or ''">
-                    <a t-attf-href="/blog/#{ slug(nav_blog) }">
+                    <a t-attf-href="#{blog_url(blog=nav_blog)}">
                         <span t-field="nav_blog.name"/>
                     </a>
                 </li>