[REF] website_slides: use mixin.image on channel and slide models

This recently introduced mixin allows to hide complexity of defining, using
and resizing images. Let us use it in channel and image model.

Commit linked to task ID 1941250 and PR #31272.
This commit is contained in:
Thibault Delavallée
2019-02-20 12:24:30 +00:00
parent 0e56426252
commit 4e116ef055
7 changed files with 12 additions and 24 deletions
+7 -12
View File
@@ -6,7 +6,6 @@ import uuid
from odoo import api, fields, models, tools, _
from odoo.addons.http_routing.models.ir_http import slug
from odoo.tools.translate import html_translate
from odoo.exceptions import UserError
from odoo.osv import expression
@@ -63,7 +62,10 @@ class Channel(models.Model):
""" A channel is a container of slides. """
_name = 'slide.channel'
_description = 'Slide Channel'
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.multi.mixin', 'rating.mixin']
_inherit = [
'mail.thread', 'rating.mixin',
'image.mixin',
'website.seo.metadata', 'website.published.multi.mixin']
_order = 'sequence, id'
def _default_access_token(self):
@@ -72,7 +74,7 @@ class Channel(models.Model):
# description
name = fields.Char('Name', translate=True, required=True)
active = fields.Boolean(default=True)
description = fields.Html('Description', translate=html_translate, sanitize_attributes=False)
description = fields.Html('Description', translate=tools.html_translate, sanitize_attributes=False)
channel_type = fields.Selection([
('documentation', 'Documentation'), ('training', 'Training')],
string="Course type", default="documentation", required=True)
@@ -82,10 +84,6 @@ class Channel(models.Model):
'slide.channel.tag', 'slide_channel_tag_rel', 'channel_id', 'tag_id',
string='Tags', help='Used to categorize and filter displayed channels/courses')
category_ids = fields.One2many('slide.category', 'channel_id', string="Categories")
image = fields.Binary("Image", attachment=True)
image_large = fields.Binary("Large image", attachment=True)
image_medium = fields.Binary("Medium image", attachment=True)
image_small = fields.Binary("Small image", attachment=True)
# slides: promote, statistics
slide_ids = fields.One2many('slide.slide', 'channel_id', string="Slides")
slide_last_update = fields.Date('Last Update', compute='_compute_slide_last_update', store=True)
@@ -126,7 +124,7 @@ class Channel(models.Model):
help='Condition to enroll: everyone, on invite, on payment (sale bridge).')
enroll_msg = fields.Html(
'Enroll Message', help="Message explaining the enroll process",
default=False, translate=html_translate, sanitize_attributes=False)
default=False, translate=tools.html_translate, sanitize_attributes=False)
enroll_group_ids = fields.Many2many('res.groups', string='Auto Enroll Groups', help="Members of those groups are automatically added as members of the channel.")
visibility = fields.Selection([
('public', 'Public'), ('members', 'Members')],
@@ -287,9 +285,8 @@ class Channel(models.Model):
vals['channel_partner_ids'] = [(0, 0, {
'partner_id': self.env.user.partner_id.id
})]
if 'image' in vals:
tools.image_resize_images(vals, return_large=True)
channel = super(Channel, self.with_context(mail_create_nosubscribe=True)).create(vals)
if channel.user_id:
channel._action_add_members(channel.user_id.partner_id)
if 'enroll_group_ids' in vals:
@@ -298,8 +295,6 @@ class Channel(models.Model):
@api.multi
def write(self, vals):
if 'image' in vals:
tools.image_resize_images(vals, return_large=True)
res = super(Channel, self).write(vals)
if vals.get('user_id'):
self._action_add_members(self.env['res.users'].sudo().browse(vals['user_id']).partner_id)
+5 -12
View File
@@ -11,7 +11,7 @@ import uuid
from werkzeug import urls
from odoo import api, fields, models, tools, _
from odoo import api, fields, models, _
from odoo.addons.http_routing.models.ir_http import slug
from odoo.exceptions import Warning, UserError
from odoo.http import request
@@ -78,7 +78,10 @@ class SlideTag(models.Model):
class Slide(models.Model):
_name = 'slide.slide'
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.mixin', 'rating.mixin']
_inherit = [
'mail.thread', 'rating.mixin',
'image.mixin',
'website.seo.metadata', 'website.published.mixin']
_description = 'Slides'
_mail_post_access = 'read'
_order_by_strategy = {
@@ -104,10 +107,6 @@ class Slide(models.Model):
access_token = fields.Char("Security Token", copy=False, default=_default_access_token)
is_preview = fields.Boolean('Always visible', default=False)
completion_time = fields.Float('# Hours', default=1, digits=(10, 4))
image = fields.Binary("Image", attachment=True)
image_large = fields.Binary("Large image", attachment=True)
image_medium = fields.Binary("Medium image", attachment=True)
image_small = fields.Binary("Small image", attachment=True)
# subscribers
partner_ids = fields.Many2many('res.partner', 'slide_slide_partner', 'slide_id', 'partner_id',
string='Subscribers', groups='base.group_website_publisher')
@@ -287,9 +286,6 @@ class Slide(models.Model):
for key, value in doc_data.items():
values.setdefault(key, value)
if 'image' in values:
tools.image_resize_images(values, return_large=True)
slide = super(Slide, self).create(values)
if slide.website_published:
@@ -303,9 +299,6 @@ class Slide(models.Model):
for key, value in doc_data.items():
values.setdefault(key, value)
if 'image' in values:
tools.image_resize_images(values, return_large=True)
res = super(Slide, self).write(values)
if values.get('website_published'):
self.date_published = datetime.datetime.now()
Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB