summaryrefslogtreecommitdiff
path: root/addons/website_blog
diff options
context:
space:
mode:
authorRomain Derie <rde@odoo.com>2019-05-13 17:29:24 +0000
committerJeremy Kersten <jke@odoo.com>2019-08-03 09:51:22 +0000
commitcc1d78a80b518bd5eaec7eb70d7bc14ec4c31275 (patch)
tree9f5dff2b44804e14701e4fe7bc9603086df9af55 /addons/website_blog
parentf9c2716b3e76ce9bc36d87d69a37a897391c9cdb (diff)
[IMP] *: correctly read/write website_published
The `website_published` field from the website's mixins is basically a readonly from `is_published` field. On read, this field will simply read `is_published` and check if the record's website_id is accessible (only for the multi mixin). On write, it will always write on `is_published`. This commit improves a few things: - A lot of code was writting on website_published which was just then writting on is_published. Writting directly on is_published makes more sense. - Some backend fields would still reference `website_published` instead of `is_published` which would just go through the related for no reason. Plus, using `is_published` will make the field tooltip more accurate as we are not in a website context ('Visible on current website' to 'Is Published') - Filter and search on tree view were still using the `website_published` related field, which is just a readonly when we are not in a frontend context. - Some create and write function would have security check on `website_published` value but that was wrong as the user could bypass that by simply writting on `is_published`. For the write method, check `is_published` is more accurate as it will cover both case since `website_published` will then call the write method on `is_published`
Diffstat (limited to 'addons/website_blog')
-rw-r--r--addons/website_blog/controllers/main.py2
-rw-r--r--addons/website_blog/data/website_blog_demo.xml4
-rw-r--r--addons/website_blog/models/website_blog.py7
3 files changed, 7 insertions, 6 deletions
diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py
index 1d09540e8cf..0874169871d 100644
--- a/addons/website_blog/controllers/main.py
+++ b/addons/website_blog/controllers/main.py
@@ -286,7 +286,7 @@ class WebsiteBlog(http.Controller):
new_blog_post = request.env['blog.post'].create({
'blog_id': blog_id,
- 'website_published': False,
+ 'is_published': False,
})
return werkzeug.utils.redirect("/blog/%s/post/%s?enable_editor=1" % (slug(new_blog_post.blog_id), slug(new_blog_post)))
diff --git a/addons/website_blog/data/website_blog_demo.xml b/addons/website_blog/data/website_blog_demo.xml
index bb9106206d0..f80c2bd782d 100644
--- a/addons/website_blog/data/website_blog_demo.xml
+++ b/addons/website_blog/data/website_blog_demo.xml
@@ -15,7 +15,7 @@
<field name="subtitle">Ideas behind the Odoo communication tools.</field>
<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="is_published" eval="True"/>
<field name="published_date" eval="time.strftime('%Y-%m-%d %H:%M:%S')"/>
<field name="website_meta_keywords">Odoo, email</field>
<field name="website_meta_description">Ideas behind the Odoo communication tools.</field>
@@ -130,7 +130,7 @@
<field name="name">Integrating your CMS and E-Commerce</field>
<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="is_published" eval="True"/>
<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>
diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py
index 6bf40b32f63..6ec13d08370 100644
--- a/addons/website_blog/models/website_blog.py
+++ b/addons/website_blog/models/website_blog.py
@@ -194,7 +194,7 @@ class BlogPost(models.Model):
blog_post._write(dict(post_date=blog_post.create_date)) # dont trigger inverse function
def _check_for_publication(self, vals):
- if vals.get('website_published'):
+ if vals.get('is_published'):
for post in self:
post.blog_id.message_post_with_view(
'website_blog.blog_post_template_new_post',
@@ -214,9 +214,10 @@ class BlogPost(models.Model):
result = True
for post in self:
copy_vals = dict(vals)
- if ('website_published' in vals and 'published_date' not in vals and
+ published_in_vals = set(vals.keys()) & {'is_published', 'website_published'}
+ if (published_in_vals and 'published_date' not in vals and
(not post.published_date or post.published_date <= fields.Datetime.now())):
- copy_vals['published_date'] = vals['website_published'] and fields.Datetime.now() or False
+ copy_vals['published_date'] = vals[list(published_in_vals)[0]] and fields.Datetime.now() or False
result &= super(BlogPost, self).write(copy_vals)
self._check_for_publication(vals)
return result