From 7b81df3747337736de4d03decafe56197945a2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 7 Feb 2019 15:37:43 +0000 Subject: [PATCH] [REF] website_slides: remove promoted slide feature, add image and channel_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. --- addons/website_slides/controllers/main.py | 9 +-- .../data/website_slides_demo.xml | 1 - addons/website_slides/models/slide_channel.py | 33 +++----- addons/website_slides/models/slide_slide.py | 4 +- .../views/slide_channel_views.xml | 42 +++++----- .../views/website_slides_templates.xml | 81 +++++++------------ 6 files changed, 63 insertions(+), 107 deletions(-) diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py index e99e5f035f4..3ea51a7395e 100644 --- a/addons/website_slides/controllers/main.py +++ b/addons/website_slides/controllers/main.py @@ -148,6 +148,7 @@ class WebsiteSlides(http.Controller): '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 @@ class WebsiteSlides(http.Controller): '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 @@ class WebsiteSlides(http.Controller): return request.redirect('/web/login?redirect=/slides/slide/%s' % (slide.id)) return request.render("website.403") - @http.route('''/slides/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): diff --git a/addons/website_slides/data/website_slides_demo.xml b/addons/website_slides/data/website_slides_demo.xml index 6fef184dcdd..5bc27b8198f 100644 --- a/addons/website_slides/data/website_slides_demo.xml +++ b/addons/website_slides/data/website_slides_demo.xml @@ -256,7 +256,6 @@ Discover Odoo Inventory: https://www.odoo.com/page/warehouse custom - diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 11ee28cc3f9..cad83a33b7e 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -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 @@ class ChannelUsersRelation(models.Model): 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 @@ class Channel(models.Model): 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 @@ class Channel(models.Model): ('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 @@ class Channel(models.Model): 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 @@ class Channel(models.Model): 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 diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py index c49042d8547..908513c5da8 100644 --- a/addons/website_slides/models/slide_slide.py +++ b/addons/website_slides/models/slide_slide.py @@ -259,9 +259,7 @@ class Slide(models.Model): 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() diff --git a/addons/website_slides/views/slide_channel_views.xml b/addons/website_slides/views/slide_channel_views.xml index 70fc407e590..3200409f8e5 100644 --- a/addons/website_slides/views/slide_channel_views.xml +++ b/addons/website_slides/views/slide_channel_views.xml @@ -57,42 +57,40 @@ +
-
-
-

- -

+
- - + + + + + + + - + + + + + - - + - - - - - - - diff --git a/addons/website_slides/views/website_slides_templates.xml b/addons/website_slides/views/website_slides_templates.xml index a4aec0f8358..97ebb4fe59d 100644 --- a/addons/website_slides/views/website_slides_templates.xml +++ b/addons/website_slides/views/website_slides_templates.xml @@ -39,8 +39,12 @@