Permalink
Browse files

[REF] website_slides: remove promoted slide feature, add image and ch…

…annel_type

Purpose of this commit is to clean a bit channel model. Promoted slide
feature is removed as people can already choose an order for a given
channel. Moreover promoted slide will not be used when having a eLearning
display of a channel.

Image field on channels is added as it is not depending on promoted slide
anymore.

To simplify future additions a search-specific template is removed to
have a unique template to display a channel content. It will ease future
merge.

This commit is linked to task ID 1936153 and PR #30985.
  • Loading branch information...
tde-banana-odoo committed Feb 7, 2019
1 parent c0a24af commit 0ec13d2e099b5686b5ba6d9c3dfb1c8133dd2be5
@@ -148,6 +148,7 @@ def channel(self, channel, category=None, tag=None, page=1, slide_type=None, sor
'tag': tag,
'slide_type': slide_type,
'sorting': sorting,
'search': search,
'user': user,
'pager': pager,
'is_public_user': request.website.is_public_user(),
@@ -164,9 +165,6 @@ def channel(self, channel, category=None, tag=None, page=1, slide_type=None, sor
'last_message': html2plaintext(last_message_data.get('body', '')),
'last_rating_value': last_message_data.get('rating_value'),
})
if search:
values['search'] = search
return request.render('website_slides.slides_search', values)

# Display uncategorized slides
if not slide_type and not category:
@@ -221,11 +219,6 @@ def slide_download(self, slide, **kw):
return request.redirect('/web/login?redirect=/slides/slide/%s' % (slide.id))
return request.render("website.403")

@http.route('''/slides/slide/<model("slide.slide"):slide>/promote''', type='http', auth='user', website=True)
def slide_set_promoted(self, slide, **kwargs):
slide.channel_id.promoted_slide_id = slide.id
return request.redirect("/slides/%s" % slide.channel_id.id)

# JSONRPC
@http.route('/slides/slide/like', type='json', auth="user", website=True)
def slide_like(self, slide_id, upvote):
@@ -256,7 +256,6 @@ Discover Odoo Inventory: https://www.odoo.com/page/warehouse</field>

<record model="slide.channel" id="channel_public">
<field name="promote_strategy">custom</field>
<field name="custom_slide_id" ref="slide_0"/>
</record>

</data>
@@ -4,7 +4,7 @@
import math
import uuid

from odoo import api, fields, models, _
from odoo import api, fields, models, tools, _
from odoo.addons.http_routing.models.ir_http import slug
from odoo.tools.translate import html_translate
from odoo.osv import expression
@@ -48,9 +48,7 @@ def _compute_completion(self):


class Channel(models.Model):
""" A channel is a container of slides. It has group-based access configuration
allowing to configure slide upload and access. Slides can be promoted in
channels. """
""" A channel is a container of slides. """
_name = 'slide.channel'
_description = 'Slide Channel'
_inherit = ['mail.thread', 'website.seo.metadata', 'website.published.multi.mixin', 'rating.mixin']
@@ -63,11 +61,17 @@ def _default_access_token(self):
name = fields.Char('Name', translate=True, required=True)
active = fields.Boolean(default=True)
description = fields.Html('Description', translate=html_translate, sanitize_attributes=False)
channel_type = fields.Selection([
('documentation', 'Documentation'), ('training', 'Training')],
string="Course type", default="documentation", required=True)
sequence = fields.Integer(default=10, help='Display order')
tag_ids = fields.Many2many(
'slide.channel.tag', 'slide_channel_tag_rel', 'channel_id', 'tag_id',
string='Tags', help='Used to categorize and filter displayed channels/courses')
category_ids = fields.One2many('slide.category', 'channel_id', string="Categories")
image = fields.Binary("Image", attachment=True)
image_medium = fields.Binary("Medium image", attachment=True)
image_small = fields.Binary("Small image", attachment=True)
# slides: promote, statistics
slide_ids = fields.One2many('slide.slide', 'channel_id', string="Slides")
slide_partner_ids = fields.One2many('slide.slide.partner', 'channel_id', string="Slide User Data", groups='website.group_website_publisher')
@@ -78,8 +82,7 @@ def _default_access_token(self):
('most_viewed', 'Most Viewed'),
('custom', 'Featured Presentation')],
string="Featuring Policy", default='most_voted', required=True)
custom_slide_id = fields.Many2one('slide.slide', string='Slide to Promote')
promoted_slide_id = fields.Many2one('slide.slide', string='Featured Slide', compute='_compute_promoted_slide_id', store=True)

access_token = fields.Char("Security Token", copy=False, default=_default_access_token)
nbr_presentations = fields.Integer('Number of Presentations', compute='_compute_slides_statistics', store=True)
nbr_documents = fields.Integer('Number of Documents', compute='_compute_slides_statistics', store=True)
@@ -119,20 +122,6 @@ def _default_access_token(self):
can_upload = fields.Boolean('Can Upload', compute='_compute_access')
can_publish = fields.Boolean('Can Publish', compute='_compute_access')

@api.depends('custom_slide_id', 'promote_strategy', 'slide_ids.likes',
'slide_ids.total_views', "slide_ids.date_published")
def _compute_promoted_slide_id(self):
for record in self:
if record.promote_strategy == 'none':
record.promoted_slide_id = False
elif record.promote_strategy == 'custom':
record.promoted_slide_id = record.custom_slide_id
elif record.promote_strategy:
slides = self.env['slide.slide'].search(
[('website_published', '=', True), ('channel_id', '=', record.id)],
limit=1, order=self.env['slide.slide']._order_by_strategy[record.promote_strategy])
record.promoted_slide_id = slides and slides[0] or False

@api.depends('channel_partner_ids.partner_id')
@api.model
def _compute_is_member(self):
@@ -227,10 +216,14 @@ def create(self, vals):
vals['channel_partner_ids'] = [(0, 0, {
'partner_id': self.env.user.partner_id.id
})]
if 'image' in vals:
tools.image_resize_images(vals)
return super(Channel, self.with_context(mail_create_nosubscribe=True)).create(vals)

@api.multi
def write(self, vals):
if 'image' in vals:
tools.image_resize_images(vals)
res = super(Channel, self).write(vals)
if 'active' in vals:
# archiving/unarchiving a channel does it on its slides, too
@@ -259,9 +259,7 @@ def write(self, values):
doc_data = self._parse_document_url(values['url']).get('values', dict())
for key, value in doc_data.items():
values.setdefault(key, value)
if values.get('channel_id'):
custom_channels = self.env['slide.channel'].search([('custom_slide_id', '=', self.id), ('id', '!=', values.get('channel_id'))])
custom_channels.write({'custom_slide_id': False})

res = super(Slide, self).write(values)
if values.get('website_published'):
self.date_published = datetime.datetime.now()
@@ -57,42 +57,40 @@
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</div>
<field name="image" widget="image" class="oe_avatar" options="{'preview_image': 'image_medium'}"/>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name" string="Name"/>
</div>
<h1>
<field name="name" default_focus="1" placeholder="Name"/>
</h1>
<label for="name" class="oe_edit_only" string="Name"/>
<h1><field name="name" default_focus="1" placeholder="Name"/></h1>
</div>
<field name="category_ids" widget="many2many_tags" placeholder="Categories" context="{'default_channel_id': active_id}"
domain="[('channel_id','=', active_id)]"/>
<field name="tag_ids" widget="many2many_tags" placeholder="Tags"/>
<group>
<group>
<field name="visibility" string="Enroll" widget="radio"/>
<field name="category_ids" widget="many2many_tags" placeholder="Categories"
context="{'default_channel_id': active_id}"
domain="[('channel_id','=', active_id)]"/>
<field name="tag_ids" widget="many2many_tags" placeholder="Tags"/>
</group>
</group>
<notebook colspan="4">
<page string="General">
<page string="Description">
<field name="description" colspan="4" nolabel="1"/>
</page>
<page string="Options">
<group>
<group>
<field name="channel_type"/>
<field name="website_id" options="{'no_create': True}" groups="website.group_multi_website"/>
<field name="promote_strategy" widget="radio"/>
<field name="custom_slide_id" class="oe_edit_only" attrs="{'invisible': [('promote_strategy', '!=', 'custom')]}" domain="[('channel_id','=',id), ('website_published','=',True)]"/>
<field name="promoted_slide_id" attrs="{'invisible': [('promote_strategy', '!=', 'custom')]}"/>
</group>
<group>
<field name="upload_group_ids" widget="many2many_tags"/>
<field name="publish_template_id" domain="[('model','=','slide.slide')]"/>
<field name="share_template_id" domain="[('model','=','slide.slide')]"/>
</group>
</group>
<label for="description"/>
<field name="description" colspan="4" nolabel="1"/>
</page>
<page string="Security">
<group>
<field name="upload_group_ids" widget="many2many_tags"/>
<field name="visibility" string="Channel visibility" widget="radio"/>
</group>
<group colspan="4">
<label for="enroll_msg"/>
<field name="enroll_msg" colspan="4" nolabel="1"/>
<label for="enroll_msg"/>
<field name="enroll_msg" colspan="4" nolabel="1"/>
</group>
</page>
<page string="Statistics" groups="base.group_no_one">
Oops, something went wrong.

0 comments on commit 0ec13d2

Please sign in to comment.