[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) <tde@openerp.com>
This commit is contained in:
Florimond Husquinet (fhu)
2019-11-21 12:25:52 +00:00
committed by Thibault Delavallée
parent 27a87141dd
commit 07f70e3c10
4 changed files with 18 additions and 5 deletions
+12 -2
View File
@@ -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)
@@ -32,7 +32,7 @@
</fieldset>
<div class="form-group">
<label for="title">Description</label>
<textarea name="description" id="description" style="height:8em" class="form-control" placeholder="Write here a short description of your first course"/>
<input type="text" class="form-control" name="description" id="description" placeholder="Write here a short description of your first course" />
</div>
<div class="form-group">
<label id="communication-label">Review</label>
@@ -77,7 +77,10 @@
</field>
</page>
<page name="description" string="Description">
<field name="description" colspan="4" nolabel="1"/>
<group>
<field name="description" colspan="4" />
<field name="description_short" colspan="4" />
</group>
</page>
<page name="options" string="Options">
<group>
@@ -328,7 +328,7 @@
<a class="card-title h5 mb-2 o_wslides_desc_truncate_2" t-attf-href="/slides/#{slug(channel)}" t-esc="channel.name"/>
<span t-if="not channel.is_published" class="badge badge-danger p-1">Unpublished</span>
<div class="card-text mt-1">
<div class="font-weight-light o_wslides_desc_truncate_3" t-field="channel.description"/>
<div class="font-weight-light o_wslides_desc_truncate_3" t-field="channel.description_short"/>
<div t-if="channel.tag_ids" class="mt-2 pt-1 o_wslides_desc_truncate_2">
<t t-foreach="channel.tag_ids" t-as="tag">
<a t-att-href="'/slides/all?channel_tag_id=%s' % tag.id" class="badge badge-light" t-esc="tag.name"/>