category_ids = category_obj.search(cr, uid, [], context=context)
categories = category_obj.browse(cr, uid, category_ids, context=context)
- pager_url = "/blog/"
+ path_filter = ""
domain = []
if category:
- pager_url += "cat/%s/" % category.id
+ path_filter += "cat/%s/" % category.id
domain += [("id", "=", [blog.id for blog in category.blog_post_ids])]
if tag:
- pager_url += 'tag/%s/' % tag.id
+ path_filter += 'tag/%s/' % tag.id
domain += [("id", "=", [blog.id for blog in tag.blog_post_ids])]
if date:
- pager_url += "date/%s/" % date
+ path_filter += "date/%s/" % date
date = date.split("_")
domain = [("create_date", ">=", date[0]), ("create_date", "<=", date[1])]
blog_posts = blog_post_obj.browse(cr, uid, blog_post_ids, context=context)
pager = request.website.pager(
- url=pager_url,
+ url="/blog/%s" % path_filter,
total=len(blog_posts),
page=page,
step=self._category_post_per_page,
'blog_posts': blog_posts,
'pager': pager,
'nav_list': self.nav_list(),
+ 'path_filter': path_filter,
}
if tag:
return request.website.render("website_blog.blog_post_short", values)
@website.route([
- '/blog/<model("blog.post"):blog_post>/',
- '/blog/<model("blog.post"):blog_post>/page/<int:page>/'
+ '/blog/<model("blog.post"):blog_post>/page/<int:page>/',
+ '/blog/<model("blog.post"):blog_post>/cat/<model("blog.category"):category>/',
+ '/blog/<model("blog.post"):blog_post>/cat/<model("blog.category"):category>/page/<int:page>/',
+ '/blog/<model("blog.post"):blog_post>/tag/<model("blog.tag"):tag>/',
+ '/blog/<model("blog.post"):blog_post>/tag/<model("blog.tag"):tag>/page/<int:page>/',
+ '/blog/<model("blog.post"):blog_post>/cat/<model("blog.category"):category>/date/<string(length=21):date>/',
+ '/blog/<model("blog.post"):blog_post>/tag/<model("blog.tag"):tag>/date/<string(length=21):date>/',
+ '/blog/<model("blog.post"):blog_post>/tag/<model("blog.tag"):tag>/date/<string(length=21):date>/page/<int:page>/',
], type='http', auth="public", multilang=True)
- def blog_post(self, blog_post=None, page=1, enable_editor=None):
+ def blog_post(self, blog_post=None, category=None, tag=None, page=1, date=None, enable_editor=None, path_filter=''):
""" Prepare all values to display the blog.
:param blog_post: blog post currently browsed. If not set, the user is
browsing the category and a post pager is calculated.
If set the user is reading the blog post and a
comments pager is calculated.
+ :param category: category currently browsed.
+ :param tag: tag that is currently used to filter blog posts
:param integer page: current page of the pager. Can be the category or
post pager.
- :param dict post: kwargs, may contain
+ :param date: date currently used to filter blog posts (dateBegin_dateEnd)
- 'enable_editor': editor control
- 'blog_post': browse of the current post, if blog_post_id
- 'category': browse of the current category, if category_id
+ - 'categories': list of browse records of categories
- 'pager': the pager to display comments pager in a blog post
+ - 'tag': current tag, if tag_id
- 'nav_list': a dict [year][month] for archives navigation
"""
+
+ pager_url = "/blog/%s" % blog_post.id
+
+ if path_filter:
+ pager_url += path_filter
+
pager = request.website.pager(
- url="/blog/%s/" % blog_post.id,
+ url=pager_url,
total=len(blog_post.website_message_ids),
page=page,
step=self._post_comment_per_page,
categories = category_obj.browse(cr, uid, category_ids, context=context)
values = {
- 'category': blog_post.category_id,
+ 'category': category,
'categories': categories,
+ 'tag': tag,
'blog_post': blog_post,
'pager': pager,
'nav_list': self.nav_list(),
'enable_editor': enable_editor,
+ 'path_filter': path_filter,
}
return request.website.render("website_blog.blog_post_complete", values)
context=dict(context, mail_create_nosubcribe=True))
return werkzeug.utils.redirect(request.httprequest.referrer + "#comments")
- @website.route(['/blog/<int:category_id>/new'], type='http', auth="public", multilang=True)
- def blog_post_create(self, category_id=None, **post):
+ @website.route(['/blog/<int:category_id><path:path_filter>/new'], type='http', auth="public", multilang=True)
+ def blog_post_create(self, category_id=None, path_filter='', **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(
'content': '',
'website_published': False,
}, context=create_context)
- return werkzeug.utils.redirect("/blog/%s/?enable_editor=1" % (new_blog_post_id))
+ return werkzeug.utils.redirect("/blog/%s%s/?enable_editor=1" % (new_blog_post_id, path_filter))
- @website.route(['/blog/<int:blog_post_id>/duplicate'], type='http', auth="public")
- def blog_post_copy(self, blog_post_id=None, **post):
+ @website.route(['/blog/<int:blog_post_id><path:path_filter>/duplicate'], type='http', auth="public")
+ def blog_post_copy(self, blog_post_id=None, path_filter='', **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/?enable_editor=1" % (new_blog_post_id))
+ return werkzeug.utils.redirect("/blog/%s%s/?enable_editor=1" % (new_blog_post_id, path_filter))
<t t-foreach="blogs" t-as="blog">
<div class="col-md-4">
<h4>
- <a t-href="/blog/#{blog.id}" t-field="blog.name"></a>
+ <a t-href="/blog/#{blog.id}/#{ path_filter }" t-field="blog.name"></a>
<span t-if="not blog.website_published" class="text-warning">
&nbsp;
<span class="icon-warning-sign" title="Not published"/>
</div>
<div class="text-muted" t-if="len(blog.message_ids) > 0">
<span class="icon-comment">
- <a t-href="/blog/#{blog.id}/#comment">
+ <a t-href="/blog/#{blog.id}/#{ path_filter }/#comment">
<t t-if="len(blog.message_ids) <= 1" ><t t-esc="len(blog.message_ids)"/> comment</t>
<t t-if="len(blog.message_ids) > 1"><t t-esc="len(blog.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-href="/blog/#{blog_post.id}" t-field="blog_post.name"></a>
+ <a t-href="/blog/#{blog_post.id}/#{ path_filter }" t-field="blog_post.name"></a>
</h2>
<p class="post-meta text-muted text-center" name='blog_post_data'>
<span class="icon-calendar"> <span t-field="blog_post.create_date"/> &nbsp;</span>
<span t-if="len(blog_post.message_ids) > 0" class="icon-comment">
- <a t-href="/blog/#{blog_post.id}/#comment">
+ <a t-href="/blog/#{blog_post.id}/#{ path_filter }/#comment">
<t t-if="len(blog_post.message_ids) <= 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>
<t t-set="object" t-value="blog_post"/>
<t t-set="publish_edit" t-value="True"/>
<li>
- <a href="#" t-attf-data-href="/blog/#{blog_post.id}/duplicate">Duplicate</a>
+ <a href="#" t-attf-data-href="/blog/#{blog_post.id}/#{ path_filter }/duplicate">Duplicate</a>
<script>
var $a=$("[data-href$='/duplicate']");
$a.attr("href", $a.data('href')).removeAttr('data-href');
<xpath expr="//ul[@id='comments-list']" position="after">
<t t-if="not is_public_user">
<section groups="group_website_blog_reply" class="mb32">
- <form id="comment" t-attf-action="/blog/#{blog_post.id}/comment"
+ <form id="comment" t-attf-action="/blog/#{blog_post.id}/#{ path_filter }/comment"
method="POST">
<img class="img pull-left img-rounded" t-att-src="'/website/image?model=res.partner&field=image_small&id='+str(user_id.partner_id.id)" style="width: 50px; margin-right: 10px;"/>
<div class="pull-left mb32" style="width: 75%%">
<h4>Archives</h4>
<ul class="list-unstyled">
<li t-foreach="nav_list" t-as="months">
- <a t-href="/blog/#{ category and 'cat/%s/' % category.id or '' }#{ tag and 'tag/%s/' % tag.id or '' }date/#{ months['date'] }"><t t-esc="months['create_date']"/></a>
+ <a t-ignore="True" t-href="/blog/#{ category and 'cat/%s/' % category.id or '' }#{ tag and 'tag/%s/' % tag.id or '' }date/#{ months['date'] }"><t t-esc="months['create_date']"/></a>
<span class="pull-right badge" t-esc="months['create_date_count']"/>
</li>
</ul>