[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
This commit is contained in:
parent
c639b7aad6
commit
fe40538aff
|
@ -35,10 +35,10 @@ class WebsiteBlog(http.Controller):
|
|||
|
||||
@website.route([
|
||||
'/blog/',
|
||||
'/blog/<int:category_id>/',
|
||||
'/blog/<int:category_id>/<int:blog_post_id>/',
|
||||
'/blog/<int:category_id>/page/<int:page>/',
|
||||
'/blog/<int:category_id>/<int:blog_post_id>/page/<int:page>/',
|
||||
'/blog/<int:blog_post_id>/',
|
||||
'/blog/<int:blog_post_id>/page/<int:page>/',
|
||||
'/blog/cat/<int:category_id>/',
|
||||
'/blog/cat/<int:category_id>/page/<int:page>/',
|
||||
'/blog/tag/',
|
||||
'/blog/tag/<int:tag_id>/',
|
||||
], 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/<int:category_id>/<int:blog_post_id>/post'], type='http', auth="public")
|
||||
def blog_comment(self, category_id=None, blog_post_id=None, **post):
|
||||
@website.route(['/blog/<int:blog_post_id>/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/<int:category_id>/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/<int:blog_post_id>/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))
|
||||
|
|
|
@ -5,25 +5,34 @@
|
|||
<!-- Layout add nav and footer -->
|
||||
<template id="header_footer_custom" inherit_id="website.layout">
|
||||
<xpath expr="//header//ul[@id='top_menu']/li[@name='contactus']" position="before">
|
||||
<li><a href="/blog/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
<li><a t-attf-href="/blog/cat/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
</xpath>
|
||||
<xpath expr="//footer//div[@name='info']/ul" position="inside">
|
||||
<li><a href="/blog/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
<li><a t-attf-href="/blog/cat/%(website_blog.blog_category_1)d/">News</a></li>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
<!-- Blog Post Summary -->
|
||||
<template id="blog_post_short" name="Blog Post Summary">
|
||||
<div>
|
||||
<div class="pull-right">
|
||||
<t t-call="website.publish_management">
|
||||
<t t-set="object" t-value="blog_post"/>
|
||||
<t t-set="publish_edit" t-value="True"/>
|
||||
<t t-set="publish_duplicate" t-value="'/blog/%s/duplicate' % (blog_post.id)"/>
|
||||
</t>
|
||||
</div>
|
||||
<h2 class="text-center">
|
||||
<a t-attf-href="/blog/#{blog_post.category_id.id}/#{blog_post.id}" t-field="blog_post.name"></a>
|
||||
<a t-attf-href="/blog/#{blog_post.id}" 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"/></span> &nbsp;
|
||||
<span class="icon-user"> By <span t-field="blog_post.create_uid"/> &nbsp;</span>
|
||||
<span t-if="len(blog_post.message_ids) > 0" class="icon-comment"> With
|
||||
<a t-if="len(blog_post.message_ids) <= 1" t-attf-href="/blog/#{blog_post.category_id.id}/#{blog_post.id}#comments"><t t-esc="len(blog_post.message_ids)"/> comment</a>
|
||||
<a t-if="len(blog_post.message_ids) > 1" t-attf-href="/blog/#{blog_post.category_id.id}/#{blog_post.id}#comments"><t t-esc="len(blog_post.message_ids)"/> comments</a>
|
||||
<span t-if="len(blog_post.message_ids) > 0" class="icon-comment">
|
||||
<a t-attf-href="/blog/#{blog_post.id}/#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>
|
||||
</span>
|
||||
</p>
|
||||
<div t-field="blog_post.shortened_content" class="blog_content"/>
|
||||
|
@ -67,6 +76,7 @@
|
|||
<t t-call="website.publish_management">
|
||||
<t t-set="object" t-value="blog_post"/>
|
||||
<t t-set="publish_edit" t-value="True"/>
|
||||
<t t-set="publish_duplicate" t-value="'/blog/%s/duplicate' % (blog_post.id)"/>
|
||||
</t>
|
||||
</div>
|
||||
<div class="clearfix"/>
|
||||
|
@ -76,8 +86,10 @@
|
|||
<span class="icon-calendar"> <span t-field="blog_post.create_date"/></span> &nbsp;
|
||||
<span class="icon-user"> By <span t-field="blog_post.create_uid"/> &nbsp;</span>
|
||||
<span t-if="len(blog_post.message_ids) > 0" class="icon-comment"> With
|
||||
<a t-if="len(blog_post.message_ids) <= 1" t-attf-href="#comments"><t t-esc="len(blog_post.message_ids)"/> comment</a>
|
||||
<a t-if="len(blog_post.message_ids) > 1" t-attf-href="#comments"><t t-esc="len(blog_post.message_ids)"/> comments</a>
|
||||
<a t-attf-href="#comments">
|
||||
<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>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
|
@ -117,7 +129,7 @@
|
|||
<xpath expr="//ul[last()]" position="after">
|
||||
<section groups="group_website_blog_reply" class="mb32">
|
||||
<h4>Leave a Comment</h4>
|
||||
<form id="comment" t-attf-action="/blog/#{blog_post.category_id.id}/#{blog_post.id}/post#post"
|
||||
<form id="comment" t-attf-action="/blog/#{blog_post.id}/post#post"
|
||||
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%%">
|
||||
|
@ -170,6 +182,11 @@
|
|||
<div class="container mt16 js_website_blog">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-sm-12" t-if="not blog_post" id="blog_post">
|
||||
<t t-if="category and editable">
|
||||
<div class="row">
|
||||
<a t-attf-href="/blog/#{category.id}/new" class="btn btn-primary pull-right">New Blog Post</a>
|
||||
</div>
|
||||
</t>
|
||||
<t t-foreach="blog_posts" t-as="blog_post" data-publish="">
|
||||
<t t-call="website_blog.blog_post_short"/>
|
||||
</t>
|
||||
|
@ -191,10 +208,6 @@
|
|||
inherit_option_id="website_blog.index" inherit_id="website_blog.index">
|
||||
<xpath expr="//div[@class='row']" position="inside">
|
||||
<div class="col-lg-3 col-sm-3 hidden-xs col-lg-offset-1 mb32" id="right_column">
|
||||
<t t-if="category and editable">
|
||||
<a t-attf-href="/blog/#{category.id}/new" class="btn btn-primary pull-right">New Blog Post</a>
|
||||
</t>
|
||||
<div class="clearfix mb48"/>
|
||||
</div>
|
||||
</xpath>
|
||||
<xpath expr="//div[@id='blog_post']" position="attributes">
|
||||
|
|
Loading…
Reference in New Issue