[IMP] "website_blog" compatible with Multi-Website

This commit is contained in:
Kaushal Prajapati 2017-12-25 10:32:11 +05:30 committed by Siddharth Bhalgami
parent 23e5ea0865
commit 6a35afc191
6 changed files with 19 additions and 9 deletions

View File

@ -23,7 +23,8 @@ class WebsiteBlog(http.Controller):
def nav_list(self, blog=None):
dom = blog and [('blog_id', '=', blog.id)] or []
if not request.env.user.has_group('website.group_website_designer'):
dom += [('post_date', '<=', fields.Datetime.now())]
dom += [('post_date', '<=', fields.Datetime.now()),
("website_ids", "in", request.website.id)]
groups = request.env['blog.post']._read_group_raw(
dom,
['name', 'post_date'],
@ -63,7 +64,7 @@ class WebsiteBlog(http.Controller):
page=page,
step=self._blog_post_per_page,
)
posts = BlogPost.search([], offset=(page - 1) * self._blog_post_per_page, limit=self._blog_post_per_page)
posts = BlogPost.search([("website_ids", "in", request.website.id)], offset=(page - 1) * self._blog_post_per_page, limit=self._blog_post_per_page)
blog_url = QueryURL('', ['blog', 'tag'])
return request.render("website_blog.latest_blogs", {
'posts': posts,
@ -113,16 +114,16 @@ class WebsiteBlog(http.Controller):
domain += [("post_date", ">=", date_begin), ("post_date", "<=", date_end)]
if request.env.user.has_group('website.group_website_designer'):
count_domain = domain + [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now())]
count_domain = domain + [("website_published", "=", True), ("website_ids", "in", request.website.id), ("post_date", "<=", fields.Datetime.now())]
published_count = BlogPost.search_count(count_domain)
unpublished_count = BlogPost.search_count(domain) - published_count
if state == "published":
domain += [("website_published", "=", True), ("post_date", "<=", fields.Datetime.now())]
domain += [("website_published", "=", True), ("website_ids", "in", request.website.id), ("post_date", "<=", fields.Datetime.now())]
elif state == "unpublished":
domain += ['|', ("website_published", "=", False), ("post_date", ">", fields.Datetime.now())]
domain += ['|', ("website_published", "=", False), ("website_ids", "not in", request.website.id), ("post_date", ">", fields.Datetime.now())]
else:
domain += [("post_date", "<=", fields.Datetime.now())]
domain += [("post_date", "<=", fields.Datetime.now()), ("website_ids", "in", request.website.id)]
blog_url = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end)
@ -330,7 +331,7 @@ class WebsiteBlog(http.Controller):
#check current user belongs to website publisher group
publish = request.env.user.has_group('website.group_website_publisher')
if not publish:
domain.append(('website_published', '=', True))
domain.append(('website_published', '=', True), ("website_ids", "in", request.website.id))
messages = request.env['mail.message'].sudo().search(domain, count=count)
if count:
return messages.ids

View File

@ -16,6 +16,7 @@
<field name="blog_id" ref="blog_blog_1"/>
<field name="tag_ids" eval="[(6, 0, [ref('blog_tag_1')])]"/>
<field name="website_published" eval="True"/>
<field name="website_ids" eval="[(4,ref('website.default_website'))]"/>
<field name="published_date" eval="time.strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="website_meta_keywords">Flectra, email</field>
<field name="website_meta_description">The Future of Emails</field>
@ -131,6 +132,7 @@
<field name="subtitle">Building your company's website and selling your products online easy.</field>
<field name="blog_id" ref="blog_blog_1"/>
<field name="website_published" eval="True"/>
<field name="website_ids" eval="[(4,ref('website.default_website'))]"/>
<field name="published_date" eval="time.strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="tag_ids" eval="[(6, 0, [ref('blog_tag_1'), ref('blog_tag_2')])]"/>
<field name="cover_properties">{"background-image": "url(/web/image/website_blog.blog_post_cover_02)", "resize_class": "cover container-fluid cover_full", "background-color": "oe_black", "opacity": "0.0"}</field>

View File

@ -153,6 +153,11 @@ class BlogPost(models.Model):
author_avatar = fields.Binary(related='author_id.image_small', string="Avatar")
visits = fields.Integer('No of Views', copy=False)
ranking = fields.Float(compute='_compute_ranking', string='Ranking')
website_ids = fields.Many2many('website', 'website_blog_pub_rel',
'website_id', 'blog_id',
string='Websites', copy=False,
help='List of websites in which '
'Blog Post is published.')
@api.multi
@api.depends('content', 'teaser_manual')

View File

@ -17,6 +17,7 @@ class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
- if someone subscribe to the post or comment it, it become follower
and receive notification for future comments. """
self.website = self.env['website'].browse(1)
# Create a new blog, subscribe the employee to the blog
test_blog = self.env['blog.blog'].sudo(self.user_blogmanager).create({
'name': 'New Blog',
@ -39,7 +40,7 @@ class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
'website_blog: subscribing to a blog should not subscribe to its posts')
# Publish the blog
test_blog_post.write({'website_published': True})
test_blog_post.write({'website_published': True, 'website_ids': [(6, 0, [self.website.id])]})
# Check publish message has been sent to blog followers
publish_message = next((m for m in test_blog_post.blog_id.message_ids if m.subtype_id.id == self.ref('website_blog.mt_blog_blog_published')), None)

View File

@ -133,7 +133,7 @@
</p>
</div>
<div t-foreach="blog_posts" t-as="blog_post" class="mb32" name="blog_post">
<div t-foreach="blog_posts" t-as="blog_post" class="mb32" name="blog_post" t-att-data-publish="website in blog_post.website_ids and 'on' or 'off'">
<a t-attf-href="/blog/#{ slug(blog_post.blog_id) }/post/#{ slug(blog_post) }">
<h2 t-field="blog_post.name" class="mb4 o_blog_post_title">Untitled Post</h2>
</a>

View File

@ -81,6 +81,7 @@
</group>
<group string="Publishing Options">
<field name="author_id"/>
<field name="website_ids" widget="many2many_tags"/>
<field name="create_date" groups="base.group_no_one"/>
<field name="post_date"/>
<field name="write_uid"/>