From 9b38bcec1269f0e72606e774f5e1f5f4a78baa89 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 2 Sep 2019 09:09:16 +0000 Subject: [PATCH] [IMP] website, website_*: improve edit in backend feature *base, website_blog, website_event, website_forum, website_slides With this commit: 1. It is now possible to add the 'Edit in backend' entry in the frontend navbar for any desired model, not only the ones which have the published mixin. It will simply redirect to the main_object form view. This commit add it to Forum and Blog. 2. When clicking on 'Edit in backend', it is now possible to land on another module than Website. That's especially useful for events and slides which are not directly related to the website module as they have their own module. 3. Remove the custom Edit in backend from the forum homepage (fa-cog). Opportunity was also taken to remove the 'edit welcome message'. It will now be editable through the editor (welcome message will appear in edit mode). Thus we got rid of the custom edit welcome message controller and views. Closes #36325 --- addons/website/models/ir_ui_view.py | 14 +++++---- .../views/website_navbar_templates.xml | 4 +-- addons/website_blog/controllers/main.py | 1 + addons/website_event/models/event.py | 3 ++ addons/website_forum/controllers/main.py | 5 +-- addons/website_forum/views/website_forum.xml | 31 +------------------ addons/website_slides/controllers/main.py | 2 ++ addons/website_slides/models/slide_channel.py | 3 ++ addons/website_slides/models/slide_slide.py | 3 ++ .../views/website_slides_templates_course.xml | 2 -- .../views/website_slides_templates_lesson.xml | 1 - ...ite_slides_templates_lesson_fullscreen.xml | 1 - 12 files changed, 24 insertions(+), 46 deletions(-) diff --git a/addons/website/models/ir_ui_view.py b/addons/website/models/ir_ui_view.py index 070b885bc64..7c92478d231 100644 --- a/addons/website/models/ir_ui_view.py +++ b/addons/website/models/ir_ui_view.py @@ -312,9 +312,13 @@ class View(models.Model): new_context = dict(self._context, inherit_branding=True) elif request.env.user.has_group('website.group_website_publisher'): new_context = dict(self._context, inherit_branding_auto=True) - # Fallback incase main_object dont't inherit 'website.seo.metadata' - if values and 'main_object' in values and not hasattr(values['main_object'], 'get_website_meta'): - values['main_object'].get_website_meta = lambda: {} + if values and 'main_object' in values: + func = getattr(values['main_object'], 'get_backend_menu_id', False) + values['backend_menu_id'] = func and func() or self.env.ref('website.menu_website_configuration').id + + # Fallback incase main_object dont't inherit 'website.seo.metadata' + if not hasattr(values['main_object'], 'get_website_meta'): + values['main_object'].get_website_meta = lambda: {} if self._context != new_context: self = self.with_context(new_context) @@ -333,9 +337,6 @@ class View(models.Model): translatable = editable and self._context.get('lang') != request.env['ir.http']._get_default_lang().code editable = not translatable and editable - if 'main_object' not in qcontext: - qcontext['main_object'] = self - cur = Website.get_current_website() if self.env.user.has_group('website.group_website_publisher') and self.env.user.has_group('website.group_multi_website'): qcontext['multi_website_websites_current'] = {'website_id': cur.id, 'name': cur.name, 'domain': cur._get_http_domain()} @@ -353,6 +354,7 @@ class View(models.Model): qcontext.update(dict( self._context.copy(), + main_object=self, website=request.website, url_for=url_for, res_company=request.website.company_id.sudo(), diff --git a/addons/website/views/website_navbar_templates.xml b/addons/website/views/website_navbar_templates.xml index 72cbab468de..37d3ada9b50 100644 --- a/addons/website/views/website_navbar_templates.xml +++ b/addons/website/views/website_navbar_templates.xml @@ -159,12 +159,12 @@
  • Edit
  • -
  • +
  • Toggle Dropdown
  • diff --git a/addons/website_blog/controllers/main.py b/addons/website_blog/controllers/main.py index 0d691bc427c..5d8279c22ba 100644 --- a/addons/website_blog/controllers/main.py +++ b/addons/website_blog/controllers/main.py @@ -158,6 +158,7 @@ class WebsiteBlog(http.Controller): if blog: values['main_object'] = blog + values['edit_in_backend'] = True values['blog_url'] = QueryURL('', ['blog', 'tag'], blog=blog, tag=tag, date_begin=date_begin, date_end=date_end) else: values['blog_url'] = QueryURL('/blog', ['tag'], date_begin=date_begin, date_end=date_end) diff --git a/addons/website_event/models/event.py b/addons/website_event/models/event.py index ac9cb12dafb..d75decb3e1d 100644 --- a/addons/website_event/models/event.py +++ b/addons/website_event/models/event.py @@ -161,3 +161,6 @@ class Event(models.Model): res['default_twitter']['twitter:card'] = 'summary' res['default_meta_description'] = self.subtitle return res + + def get_backend_menu_id(self): + return self.env.ref('event.event_main_menu').id diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 435e894db58..cd647d394bc 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -136,6 +136,7 @@ class WebsiteForum(WebsiteProfile): values = self._prepare_user_values(forum=forum, searches=post, header={'ask_hide': not forum.active}) values.update({ 'main_object': tag or forum, + 'edit_in_backend': not tag, 'question_ids': question_ids, 'question_count': question_count, 'pager': pager, @@ -187,10 +188,6 @@ class WebsiteForum(WebsiteProfile): }) return request.render("website_forum.tag", values) - @http.route('/forum//edit_welcome_message', auth="user", website=True) - def edit_welcome_message(self, forum, **kw): - return request.render("website_forum.edit_welcome_message", {'forum': forum}) - # Questions # -------------------------------------------------- diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index c6f6f1e27e5..20d464c86c5 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -58,7 +58,7 @@

    -
    +
    @@ -150,16 +150,6 @@ - | - @@ -231,25 +221,6 @@
    - - -