From 07f70e3c1026b4cbe6edcb6e875584c868da3eb1 Mon Sep 17 00:00:00 2001 From: "Florimond Husquinet (fhu)" Date: Wed, 16 Oct 2019 09:33:18 +0000 Subject: [PATCH] [IMP] website_slide: add a card description independent from short description The Channel model contains the two following fields: `description` and `description_html`. The former is a short plain-text description that can be filled in the creation form. The latter is a long html-formatted description. Before this commit: The description displayed on the card of the course is the `description` field. After this commit: There is an additional `description_short` field, which is initialized to the same value as the `description` field. If the `description` field is modified the `description_short` reflects the modifications. This happens however only if the user didn't modify the `description_short` field manually. If it is modified to another value manually, the link is broken. Description short is now used only on the course page, below title, in the header. Description short is used in kanban card displayed in homepage. Html description is used as a long course description on course page. Beside, in the creation form of a course, the description textarea is now a one-line input field to reflect the fact that it's supposed to be a relatively short description. Task ID: 2026165 PR #39388 Signed-off-by: Thibault Delavallee (tde) --- addons/website_slides/models/slide_channel.py | 14 ++++++++++++-- .../static/src/xml/website_slides_channel.xml | 2 +- .../website_slides/views/slide_channel_views.xml | 5 ++++- .../views/website_slides_templates_homepage.xml | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 27399364992..77aacea09d9 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -87,8 +87,9 @@ class Channel(models.Model): # description name = fields.Char('Name', translate=True, required=True) active = fields.Boolean(default=True) - description = fields.Text('Short Description', translate=True) - description_html = fields.Html('Description', translate=tools.html_translate, sanitize_attributes=False) + 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_html = fields.Html('Detailed Description', translate=tools.html_translate, sanitize_attributes=False) channel_type = fields.Selection([ ('documentation', 'Documentation'), ('training', 'Training')], string="Course type", default="documentation", required=True) @@ -368,16 +369,24 @@ 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'): + vals['description_short'] = vals['description'] 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: channel._add_groups_members() + return channel 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: + vals['description_short'] = vals.get('description') + 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) if 'active' in vals: @@ -385,6 +394,7 @@ class Channel(models.Model): self.with_context(active_test=False).mapped('slide_ids').write({'active': vals['active']}) if 'enroll_group_ids' in vals: self._add_groups_members() + return res @api.returns('mail.message', lambda value: value.id) diff --git a/addons/website_slides/static/src/xml/website_slides_channel.xml b/addons/website_slides/static/src/xml/website_slides_channel.xml index c040ef438e1..c6c95ebbf2b 100644 --- a/addons/website_slides/static/src/xml/website_slides_channel.xml +++ b/addons/website_slides/static/src/xml/website_slides_channel.xml @@ -32,7 +32,7 @@
-