[IMP] website_slides: webpage slide type

The idea is a slide can be a HTML page completely customized by
user. So, you can now easily create custom content and publish
it on your website, like a normal slide.

Task-1938643
This commit is contained in:
qmo-odoo
2019-02-12 11:22:59 +00:00
committed by jem-odoo
parent b8a24751c2
commit 0f22f95289
5 changed files with 28 additions and 7 deletions
+3 -2
View File
@@ -114,10 +114,11 @@ class WebsiteSlides(http.Controller):
if search:
domain += [
'|', '|',
'|', '|', '|',
('name', 'ilike', search),
('description', 'ilike', search),
('index_content', 'ilike', search)]
('index_content', 'ilike', search),
('html_content', 'ilike', search)]
pager_args['search'] = search
else:
if category:
@@ -91,6 +91,7 @@ class Channel(models.Model):
nbr_documents = fields.Integer('Number of Documents', compute='_compute_slides_statistics', store=True)
nbr_videos = fields.Integer('Number of Videos', compute='_compute_slides_statistics', store=True)
nbr_infographics = fields.Integer('Number of Infographics', compute='_compute_slides_statistics', store=True)
nbr_webpages = fields.Integer("Number of Webpages", compute='_compute_slides_statistics', store=True)
total_slides = fields.Integer('# Slides', compute='_compute_slides_statistics', store=True, oldname='total')
total_views = fields.Integer('# Views', compute='_compute_slides_statistics', store=True)
total_votes = fields.Integer('# Votes', compute='_compute_slides_statistics', store=True)
@@ -150,7 +151,7 @@ class Channel(models.Model):
'slide_ids.likes', 'slide_ids.dislikes', 'slide_ids.total_views')
def _compute_slides_statistics(self):
result = dict.fromkeys(self.ids, dict(
nbr_presentations=0, nbr_documents=0, nbr_videos=0, nbr_infographics=0,
nbr_presentations=0, nbr_documents=0, nbr_videos=0, nbr_infographics=0, nbr_webpages=0,
total_slides=0, total_views=0, total_votes=0, total_time=0))
read_group_res = self.env['slide.slide'].read_group(
[('is_published', '=', True), ('channel_id', 'in', self.ids)],
@@ -163,6 +164,7 @@ class Channel(models.Model):
result[cid]['nbr_documents'] += res_group.get('slide_type', '') == 'document' and res_group['__count'] or 0
result[cid]['nbr_videos'] += res_group.get('slide_type', '') == 'video' and res_group['__count'] or 0
result[cid]['nbr_infographics'] += res_group.get('slide_type', '') == 'infographic' and res_group['__count'] or 0
result[cid]['nbr_webpages'] += res_group.get('slide_type', '') == 'webpage' and res_group['__count'] or 0
result[cid]['total_slides'] += res_group['__count']
result[cid]['total_views'] += res_group.get('total_views', 0)
result[cid]['total_votes'] += res_group.get('likes', 0)
@@ -364,6 +366,7 @@ class Category(models.Model):
nbr_documents = fields.Integer("Number of Documents", compute='_count_presentations', store=True)
nbr_videos = fields.Integer("Number of Videos", compute='_count_presentations', store=True)
nbr_infographics = fields.Integer("Number of Infographics", compute='_count_presentations', store=True)
nbr_webpages = fields.Integer("Number of Webpages", compute='_count_presentations', store=True)
total_slides = fields.Integer(compute='_count_presentations', store=True, oldname='total')
@api.depends('slide_ids.slide_type', 'slide_ids.is_published')
@@ -380,4 +383,5 @@ class Category(models.Model):
record.nbr_documents = result[record.id].get('document', 0)
record.nbr_videos = result[record.id].get('video', 0)
record.nbr_infographics = result[record.id].get('infographic', 0)
record.total_slides = record.nbr_presentations + record.nbr_documents + record.nbr_videos + record.nbr_infographics
record.nbr_webpages = result[record.id].get('webpage', 0)
record.total_slides = record.nbr_presentations + record.nbr_documents + record.nbr_videos + record.nbr_infographics + record.nbr_webpages
+8 -1
View File
@@ -83,6 +83,7 @@ class Slide(models.Model):
- Document
- Infographic
- Video
- Webpage
Slide has various statistics like view count, embed count, like, dislikes """
@@ -101,6 +102,10 @@ class Slide(models.Model):
'channel_id', 'description', 'tag_ids', 'write_date', 'create_date',
'website_published', 'website_url', 'website_meta_title', 'website_meta_description', 'website_meta_keywords', 'website_meta_og_img']
_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.")
]
# description
name = fields.Char('Title', required=True, translate=True)
active = fields.Boolean(default=True)
@@ -127,9 +132,10 @@ class Slide(models.Model):
('infographic', 'Infographic'),
('presentation', 'Presentation'),
('document', 'Document'),
('webpage', 'Web Page'),
('video', 'Video')],
string='Type', required=True,
default='document',
default='document', readonly=True,
help="The document type will be set automatically based on the document URL and properties (e.g. height and width for presentation and document).")
index_content = fields.Text('Transcript')
datas = fields.Binary('Content', attachment=True)
@@ -137,6 +143,7 @@ class Slide(models.Model):
document_id = fields.Char('Document ID', help="Youtube or Google Document ID")
link_ids = fields.One2many('slide.slide.link', 'slide_id', string="External URL for this slide")
mime_type = fields.Char('Mime-type')
html_content = fields.Html("HTML Content", help="Custom HTML content for slides of type 'Web Page'.", translate=True)
# website
website_id = fields.Many2one(related='channel_id.website_id', readonly=True)
date_published = fields.Datetime('Publish Date')
@@ -70,7 +70,7 @@
<group>
<field name="url" attrs="{'required': [('image', '=', False)]}"/>
<field name="slide_type" readonly="1"/>
<field name="document_id" readonly="1"/>
<field name="document_id" readonly="1" attrs="{'invisible': [('document_id', '=', False)]}"/>
<field name="mime_type" readonly="1"/>
<field name="datas" readonly="1"/>
</group>
@@ -182,6 +182,12 @@
<span class="badge badge-pill" t-esc="header_object.nbr_infographics"/> Infographics
</a>
</li>
<li t-if="header_object.nbr_webpages" class="nav-item">
<a t-attf-href="/slides/#{slug(channel)}#{category and '/category/' + slug(category) or ''}/webpage"
t-attf-class="nav-link#{slide_type == 'webpage' and ' active' or ''}">
<span class="badge badge-pill" t-esc="header_object.nbr_webpages"/> Pages
</a>
</li>
</ul>
</div>
<!-- Sort options -->
@@ -411,7 +417,10 @@
<div t-if="slide.slide_type == 'video' and slide.document_id" class="embed-responsive embed-responsive-16by9 embed-responsive-item mb8">
<t t-raw="slide.embed_code"/>
</div>
<div class="row">
<div t-if="slide.slide_type == 'webpage'" class="border border-light rounded">
<div t-field="slide.html_content"/>
</div>
<div class="row mt-3">
<h4 t-field="slide.name" class="col-lg-6"/>
<div class="col-lg-6">
<div clas="row">