[IMP] website_slides: improves field type from text to html

Replace text fields to html fields as we have our own 'OdooEditor'.
Indeed, it gives more options to users in the way they format their
content without weighting too much on the UI
(tools appear on demand and not by default).

Models -> Fields

1) slide.channel -> description
2) slide.channel -> description_short
3) slide.slide -> description

Task Id: 2499504

X-original-commit: 6d914c005183aa5ae69650e3002a5a85ca83b4a6
This commit is contained in:
dht-odoo
2021-06-07 05:24:08 +00:00
committed by Thibault Delavallée
parent dbf1ab157d
commit b8fb33817b
3 changed files with 10 additions and 9 deletions
@@ -11,6 +11,7 @@ from odoo import api, fields, models, tools, _
from odoo.addons.http_routing.models.ir_http import slug
from odoo.exceptions import AccessError
from odoo.osv import expression
from odoo.tools import is_html_empty
_logger = logging.getLogger(__name__)
@@ -148,8 +149,8 @@ class Channel(models.Model):
# description
name = fields.Char('Name', translate=True, required=True)
active = fields.Boolean(default=True, tracking=100)
description = fields.Text('Description', translate=True, help="The description that is displayed on top of the course page, just below the title")
description_short = fields.Text('Short Description', translate=True, help="The description that is displayed on the course card")
description = fields.Html('Description', translate=True, help="The description that is displayed on top of the course page, just below the title")
description_short = fields.Html('Short Description', translate=True, help="The description that is displayed on the course card")
description_html = fields.Html('Detailed Description', translate=tools.html_translate, sanitize_attributes=False, sanitize_form=False)
channel_type = fields.Selection([
('training', 'Training'), ('documentation', 'Documentation')],
@@ -455,7 +456,7 @@ class Channel(models.Model):
vals['channel_partner_ids'] = [(0, 0, {
'partner_id': self.env.user.partner_id.id
})]
if vals.get('description') and not vals.get('description_short'):
if not is_html_empty(vals.get('description')) and is_html_empty(vals.get('description_short')):
vals['description_short'] = vals['description']
channel = super(Channel, self.with_context(mail_create_nosubscribe=True)).create(vals)
@@ -468,7 +469,7 @@ class Channel(models.Model):
def write(self, vals):
# If description_short wasn't manually modified, there is an implicit link between this field and description.
if vals.get('description') and not vals.get('description_short') and self.description == self.description_short:
if not is_html_empty(vals.get('description')) and is_html_empty(vals.get('description_short')) and self.description == self.description_short:
vals['description_short'] = vals.get('description')
res = super(Channel, self).write(vals)
+4 -4
View File
@@ -18,7 +18,7 @@ from odoo.addons.http_routing.models.ir_http import slug
from odoo.exceptions import Warning, UserError, AccessError
from odoo.http import request
from odoo.addons.http_routing.models.ir_http import url_for
from odoo.tools import sql
from odoo.tools import html2plaintext, sql
class SlidePartnerRelation(models.Model):
@@ -132,7 +132,7 @@ class Slide(models.Model):
active = fields.Boolean(default=True, tracking=100)
sequence = fields.Integer('Sequence', default=0)
user_id = fields.Many2one('res.users', string='Uploaded by', default=lambda self: self.env.uid)
description = fields.Text('Description', translate=True)
description = fields.Html('Description', translate=True)
channel_id = fields.Many2one('slide.channel', string="Course", required=True)
tag_ids = fields.Many2many('slide.tag', 'rel_slide_tag', 'slide_id', 'tag_id', string='Tags')
is_preview = fields.Boolean('Allow Preview', default=False, help="The course is accessible by anyone : the users don't need to join the channel to access the content of the course.")
@@ -876,9 +876,9 @@ class Slide(models.Model):
def _default_website_meta(self):
res = super(Slide, self)._default_website_meta()
res['default_opengraph']['og:title'] = res['default_twitter']['twitter:title'] = self.name
res['default_opengraph']['og:description'] = res['default_twitter']['twitter:description'] = self.description
res['default_opengraph']['og:description'] = res['default_twitter']['twitter:description'] = html2plaintext(self.description)
res['default_opengraph']['og:image'] = res['default_twitter']['twitter:image'] = self.env['website'].image_url(self, 'image_1024')
res['default_meta_description'] = self.description
res['default_meta_description'] = html2plaintext(self.description)
return res
# ---------------------------------------------------------
@@ -130,7 +130,7 @@
<div class="col-12 col-md-8 col-lg-9 d-flex flex-column">
<div class="d-flex flex-column">
<h1 t-field="channel.name"/>
<p class="mb-0 mb-xl-3" t-field="channel.description"/>
<div class="mb-0 mb-xl-3" t-field="channel.description"/>
<div t-if="channel.channel_type == 'documentation'" class="d-flex mb-md-5">
<button role="button" class="btn text-white pl-0" title="Share Channel"