summaryrefslogtreecommitdiff
path: root/addons/website_slides/controllers
diff options
context:
space:
mode:
authorPatrick Hoste <pko@odoo.com>2020-08-11 09:44:55 +0000
committerThibault Delavallée <tde@odoo.com>2020-08-11 10:22:23 +0000
commitb39f4b6307e00f9f959d6f3bf36041344d13ace6 (patch)
treea44c230cd3d9eaeb38abf3c064bca73c827dc053 /addons/website_slides/controllers
parent8d30e343b15eea4c2010bbb7491cbc61b0636952 (diff)
[REF] website(_sale)_slides(_survey): improve course management and creation
PURPOSE Improve usability of course creation and management in frontend SPECIFICATIONS This commit improves various elements of the eLearning module: * the create 'new course' dialog has been improved with examples and improved placeholders; * allow to create tags directly from course creation modal. Using the add tag button after having created the course is not the only way of managing tags anymore; * the create 'new content' dialog has some explanations on the right side; * add a flag indicating which content has already been viewed in documentation; * changes the text/color of some buttons; LINKS Task ID-2241513 PR #55698
Diffstat (limited to 'addons/website_slides/controllers')
-rw-r--r--addons/website_slides/controllers/main.py66
1 files changed, 43 insertions, 23 deletions
diff --git a/addons/website_slides/controllers/main.py b/addons/website_slides/controllers/main.py
index edad9c10419..916c27869ca 100644
--- a/addons/website_slides/controllers/main.py
+++ b/addons/website_slides/controllers/main.py
@@ -259,6 +259,37 @@ class WebsiteSlides(WebsiteProfile):
session_slide_answer_quiz.pop(str(slide['id']), None)
request.session['slide_answer_quiz'] = json.dumps(session_slide_answer_quiz)
+ # TAG UTILITIES
+ # --------------------------------------------------
+
+ def _create_or_get_channel_tag(self, tag_id, group_id):
+ if not tag_id:
+ return request.env['slide.channel.tag']
+ # handle creation of new channel tag
+ if tag_id[0] == 0:
+ group_id = self._create_or_get_channel_tag_group(group_id)
+ if not group_id:
+ return {'error': _('Missing "Tag Group" for creating a new "Tag".')}
+
+ new_tag = request.env['slide.channel.tag'].create({
+ 'name': tag_id[1]['name'],
+ 'group_id': group_id,
+ })
+ return new_tag
+ return request.env['slide.channel.tag'].browse(tag_id[0])
+
+ def _create_or_get_channel_tag_group(self, group_id):
+ if not group_id:
+ return False
+ # handle creation of new channel tag group
+ if group_id[0] == 0:
+ tag_group = request.env['slide.channel.tag.group'].create({
+ 'name': group_id[1]['name'],
+ })
+ group_id = tag_group.id
+ # use existing channel tag group
+ return group_id[0]
+
# --------------------------------------------------
# SLIDE.CHANNEL MAIN / SEARCH
# --------------------------------------------------
@@ -617,29 +648,9 @@ class WebsiteSlides(WebsiteProfile):
if not can_upload or not can_publish:
return {'error': _('You cannot add tags to this course.')}
- if tag_id:
- # handle creation of new channel tag
- if tag_id[0] == 0:
- if group_id:
- # handle creation of new channel tag group
- if group_id[0] == 0:
- tag_group = request.env['slide.channel.tag.group'].create({
- 'name': group_id[1]['name'],
- })
- group_id = tag_group.id
- # use existing channel tag group
- else:
- group_id = group_id[0]
- else:
- return {'error': _('Missing "Tag Group" for creating a new "Tag".')}
-
- request.env['slide.channel.tag'].create({'name': tag_id[1]['name'],
- 'channel_ids': [channel.id],
- 'group_id': group_id,
- })
- else:
- # use existing channel tag
- request.env['slide.channel.tag'].browse(tag_id[0]).write({'channel_ids': [(4, channel.id, 0)]})
+ tag = self._create_or_get_channel_tag(tag_id, group_id)
+ tag.write({'channel_ids': [(4, channel.id, 0)]})
+
return {'url': "/slides/%s" % (slug(channel))}
@http.route(['/slides/channel/subscribe'], type='json', auth='user', website=True)
@@ -812,6 +823,15 @@ class WebsiteSlides(WebsiteProfile):
return result
# --------------------------------------------------
+ # TAGS SECTION
+ # --------------------------------------------------
+
+ @http.route('/slide_channel_tag/add', type='json', auth='user', methods=['POST'], website=True)
+ def slide_channel_tag_create_or_get(self, tag_id, group_id):
+ tag = self._create_or_get_channel_tag(tag_id, group_id)
+ return {'tag_id': tag.id}
+
+ # --------------------------------------------------
# QUIZ SECTION
# --------------------------------------------------