diff options
| author | qmo-odoo <qmo@odoo.com> | 2019-12-30 08:17:23 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-03-26 15:57:43 +0000 |
| commit | 12c6d77e7f4ebdbe099ce35c7c7dbd326e33dd50 (patch) | |
| tree | 36b4d70d6c7a342ae1619c93daec03d90b5b4998 /addons/website_slides/models | |
| parent | 843caa270c7d13e6c81ef8f077e469bd9746a2cf (diff) | |
[FIX] website_slides: fix slide reordering in frontend
This commit fixes the reordering of slides on upload or drag and drop
in frontend. This issue was due to the fact that in a previous commit
(c4eba6f) uncategorized slides were moved to the bottom of the list,
which broke the reordering after drag and drop.
Indeed we use the dom order itself to reorder the slides with a simple rpc
call to dataset/resequence. Instead we revert part of the previous fix
to display uncategorized slides at the top. It allows to be coherent with
resequence and with backend behavior that displays uncategorized at the
top of the list.
Another issue was that, on slide upload, in the controller, we used
the category_id on the slide (which seems to not always be correct at
this stage) instead of the one given by the javascript. This caused the slide
to not be uploaded in the right section.
This commit also adds some margin to the categories in frontend for training
courses. Otherwise uncategorized slides are too close to the first category.
Task ID 2090927
X-original-commit: 7bd042d6e20c44558b90641409a6e3f8fa8000ed
Diffstat (limited to 'addons/website_slides/models')
| -rw-r--r-- | addons/website_slides/models/slide_channel.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 214a2025f2c..cb6ea814a18 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -593,13 +593,26 @@ class Channel(models.Model): def _get_categorized_slides(self, base_domain, order, force_void=True, limit=False, offset=False): """ Return an ordered structure of slides by categories within a given - base_domain that must fulfill slides. """ + base_domain that must fulfill slides. As a course structure is based on + its slides sequences, uncategorized slides must have the lowest sequences. + + Example + * category 1 (sequence 1), category 2 (sequence 3) + * slide 1 (sequence 0), slide 2 (sequence 2) + * course structure is: slide 1, category 1, slide 2, category 2 + * slide 1 is uncategorized, + * category 1 has one slide : Slide 2 + * category 2 is empty. + + Backend and frontend ordering is the same, uncategorized first. It + eases resequencing based on DOM / displayed order, notably when + drag n drop is involved. """ self.ensure_one() all_categories = self.env['slide.slide'].sudo().search([('channel_id', '=', self.id), ('is_category', '=', True)]) all_slides = self.env['slide.slide'].sudo().search(base_domain, order=order) category_data = [] - # First add all categories by natural order + # Prepare all categories by natural order for category in all_categories: category_slides = all_slides.filtered(lambda slide: slide.category_id == category) if not category_slides and not force_void: @@ -610,15 +623,17 @@ class Channel(models.Model): 'total_slides': len(category_slides), 'slides': category_slides[(offset or 0):(limit + offset or len(category_slides))], }) - # Then add uncategorized slides + + # Add uncategorized slides in first position uncategorized_slides = all_slides.filtered(lambda slide: not slide.category_id) if uncategorized_slides or force_void: - category_data.append({ + category_data.insert(0, { 'category': False, 'id': False, 'name': _('Uncategorized'), 'slug_name': _('Uncategorized'), 'total_slides': len(uncategorized_slides), 'slides': uncategorized_slides[(offset or 0):(offset + limit or len(uncategorized_slides))], }) + return category_data def _resequence_slides(self, slide, force_category=False): |
