[IMP] website_slides: Slide form view revamp

This commit improves the user experience in the slide.slide
form view by reorganizing fields, renaming fields and  hiding
unnecessary fields.

This commit also introduces two  new fields:
 - comment_count: computed field that gets the number of comments on the slide
 - channel_allow_comment: Related field to the channel_id.allow_coment.
                          This field is used to hide/show unnecessary fields

TaskID: 1978736
PR: #34232
This commit is contained in:
qmo-odoo
2019-07-31 08:19:01 +00:00
parent ecc760b6ae
commit 9c5e4338fb
2 changed files with 54 additions and 44 deletions
@@ -152,11 +152,21 @@ class Slide(models.Model):
slide_views = fields.Integer('# of Website Views', store=True, compute="_compute_slide_views")
public_views = fields.Integer('# of Public Views')
total_views = fields.Integer("Total # Views", default="0", compute='_compute_total', store=True)
# comments
comments_count = fields.Integer('Number of comments', compute="_compute_comments_count")
# channel
channel_type = fields.Selection(related="channel_id.channel_type", string="Channel type")
channel_allow_comment = fields.Boolean(related="channel_id.allow_comment", string="Allows comment")
_sql_constraints = [
('exclusion_html_content_and_url', "CHECK(html_content IS NULL OR url IS NULL)", "A slide is either filled with a document url or HTML content. Not both.")
]
@api.depends('website_message_ids.res_id', 'website_message_ids.model', 'website_message_ids.message_type')
def _compute_comments_count(self):
for slide in self:
slide.comments_count = len(slide.website_message_ids)
@api.depends('slide_views', 'public_views')
def _compute_total(self):
for record in self:
@@ -52,54 +52,39 @@
/>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name" string="Name"/>
<label for="name" string="Content Title"/>
</div>
<h1>
<field name="name" default_focus="1" placeholder="Name"/>
<field name="name" default_focus="1" placeholder="Title"/>
</h1>
<field name="tag_ids" widget="many2many_tags" placeholder="Tags..."/>
</div>
<group>
<field name="active" invisible="1"/>
<field name="user_id"/>
<field name="channel_id"/>
<field name="category_id" context="{'default_channel_id': channel_id}"/>
<field name="website_id" groups="website.group_multi_website"/>
<field name="website_url"/>
</group>
<notebook>
<page name="description" string="Description">
<field name="description"/>
</page>
<page name="document" string="Document">
<page string="Document">
<group>
<field name="slide_type"/>
<field name="url"
attrs="{'required': [('slide_type', 'in', ('video'))], 'invisible': [('slide_type', 'not in', ('document', 'presentation', 'video'))]}" />
<field name="document_id" readonly="1" attrs="{'invisible': [('document_id', '=', False)]}"/>
<field name="mime_type" readonly="1"
attrs="{'invisible': [('slide_type', 'not in', ('document', 'presentation', 'infographic', 'webpage'))]}"/>
<field name="datas"
attrs="{'invisible': [('slide_type', 'not in', ('document', 'presentation', 'infographic', 'webpage'))]}"/>
</group>
</page>
<page name="website" string="Website">
<group>
<group name="website_settings">
<group>
<field name="active" invisible="1"/>
<field name="user_id"/>
<field name="slide_type" readonly="1"/>
<field name="url"
attrs="{'required': [('slide_type', 'in', ('video'))], 'invisible': [('slide_type', 'not in', ('video'))]}" />
<field name="document_id" invisible="1"/>
<field name="mime_type" readonly="1"
attrs="{'invisible': True}"/>
<field string="Attachment" name="datas"
attrs="{'invisible': [('slide_type', 'not in', ('document', 'presentation'))]}"/>
</group>
<group>
<field name="channel_id"/>
<field name="website_id" groups="website.group_multi_website"/>
<field name="website_url"/>
<field name="is_preview"/>
<field name="date_published"/>
<field name="likes"/>
<field name="dislikes"/>
</group>
<group name="website_statistics">
<field name="slide_views"/>
<field name="public_views"/>
<field name="total_views"/>
<field name="completion_time" widget='float_time'/>
<field name="date_published" string="Published Date"/>
</group>
</group>
<label for="index_content"/>
<field name="index_content"/>
</page>
<page string="Description">
<field name="description"/>
</page>
<page name="external_links" string="External Links">
<group>
@@ -111,14 +96,14 @@
</field>
</group>
</page>
<page name="quiz" string="Quiz">
<page string="Quiz">
<group name="container_row_2">
<group name="quiz_earnings" string="Earnings">
<group string="Rewards">
<group>
<field name="quiz_first_attempt_reward"/>
<field name="quiz_second_attempt_reward"/>
<field name="quiz_third_attempt_reward"/>
<field name="quiz_fourth_attempt_reward"/>
<field string="First attempt" name="quiz_first_attempt_reward"/>
<field string="Second attempt" name="quiz_second_attempt_reward"/>
<field string="Third attempt" name="quiz_third_attempt_reward"/>
<field string="Fourth and more attempt" name="quiz_fourth_attempt_reward"/>
</group>
</group>
<group name="questions" string="Questions">
@@ -131,6 +116,21 @@
</group>
</group>
</page>
<page string="Statistics">
<group>
<group string="Views">
<field string="Member views" name="slide_views"/>
<field string="Public views" name="public_views" readonly="1"/>
<field string="Total views" name="total_views"/>
<hr attrs="{'invisible': [('channel_allow_comment', '!=', True), ('channel_type', '=', 'training')]}"/>
<field name="channel_type" invisible="1" readonly="1"/>
<field name="channel_allow_comment" invisible="1" readonly="1"/>
<field name="likes" attrs="{'invisible': [('channel_type', '=', 'training')]}"/>
<field name="dislikes" attrs="{'invisible': [('channel_type', '=', 'training')]}"/>
<field name="comments_count" attrs="{'invisible': [('channel_allow_comment', '!=', True)]}"/>
</group>
</group>
</page>
</notebook>
</sheet>
<div class="oe_chatter">