[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
This commit is contained in:
Romain Derie
2019-10-02 07:13:26 +00:00
parent c8c8413e3e
commit 9b38bcec12
12 changed files with 24 additions and 46 deletions
+8 -6
View File
@@ -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(),
@@ -159,12 +159,12 @@
<li t-if="not translatable" id="edit-page-menu">
<a data-action="edit" href="#"><span class="fa fa-pencil mr-2"/>Edit</a>
</li>
<li t-if="'website_published' in main_object.fields_get() and main_object._name != 'website.page'">
<li t-if="edit_in_backend or ('website_published' in main_object.fields_get() and main_object._name != 'website.page')">
<a role="button" class="btn btn-primary btn-sm dropdown-toggle css_edit_dynamic" data-toggle="dropdown">
<span class="sr-only">Toggle Dropdown</span>
</a>
<div class="dropdown-menu" role="menu">
<a role="menuitem" style="text-align: left;" t-attf-href="/web#return_label=Website&amp;view_type=form&amp;model=#{main_object._name}&amp;id=#{main_object.id}&amp;action=#{action}&amp;menu_id=#{menu or main_object.env.ref('website.menu_website_configuration').id}"
<a role="menuitem" style="text-align: left;" t-attf-href="/web#return_label=Website&amp;view_type=form&amp;model=#{main_object._name}&amp;id=#{main_object.id}&amp;action=#{action}&amp;menu_id=#{backend_menu_id}"
class="dropdown-item" title='Edit in backend' id="edit-in-backend">Edit in backend</a>
</div>
</li>
+1
View File
@@ -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)
+3
View File
@@ -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
+1 -4
View File
@@ -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/<model("forum.forum"):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
# --------------------------------------------------
+1 -30
View File
@@ -58,7 +58,7 @@
<h1 class="s_title_thin o_default_snippet_text text-center"><t t-esc="forum.name"></t></h1>
</div>
</div>
<div t-if="is_public_user and not forum_welcome_message" class="forum_intro">
<div t-if="editable or (is_public_user and not forum_welcome_message)" t-att-class="'css_non_editable_mode_hidden' if editable else 'forum_intro'">
<div t-field="forum.welcome_message"/>
</div>
</div>
@@ -150,16 +150,6 @@
<li class="nav-item">
<a t-attf-href="/forum/#{ slug(forum) }/faq" t-attf-class="nav-link #{header.get('is_guidelines') and 'active'}">About</a>
</li>
<span class="navbar-text" groups="base.group_erp_manager">|</span>
<li class="nav-item dropdown mx-auto" groups="base.group_erp_manager">
<a class="nav-link dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
<i class="fa fa-cog" role="img"/> Settings
</a>
<div class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<a role="menuitem" tabindex="-1" t-attf-href="/forum/#{slug(forum)}/edit_welcome_message?enable_editor=1" class="dropdown-item">Design Welcome Message</a>
<a role="menuitem" tabindex="-1" t-attf-href="/web#id=#{forum.id}&amp;view_type=form&amp;model=forum.forum" class="dropdown-item">Edit Forum in the backend</a>
</div>
</li>
</ul>
<!-- Mobile -->
@@ -231,25 +221,6 @@
</div>
</template>
<!-- Template use to edit the welcome_message -->
<template id="edit_welcome_message">
<t t-call="website.layout">
<section t-attf-class="s_cover parallax s_parallax_is_fixed py-3 #{forum.image_1920 and 'bg-black-50' or 'o_wforum_forum_card_bg text-white'}" data-scroll-background-ratio="1">
<span t-if="forum.image_1920" class="s_parallax_bg oe_img_bg oe_custom_bg" t-attf-style="background-image: url('#{website.image_url(forum, 'image_1920')}'); background-position: center;"/>
<div class="container">
<div class="row s_nb_column_fixed">
<div class="col-lg-12 s_title" data-name="Title">
<h1 class="s_title_thin o_default_snippet_text text-center"><t t-esc="forum.name"></t></h1>
</div>
</div>
<div class="forum_intro">
<div t-field="forum.welcome_message"/>
</div>
</div>
</section>
</t>
</template>
<!-- Display a post -->
<template id="display_post_question_block">
<div class="o_wforum_index_entry_title">
@@ -96,6 +96,7 @@ class WebsiteSlides(WebsiteProfile):
values = {
# slide
'slide': slide,
'main_object': slide,
'most_viewed_slides': most_viewed_slides,
'related_slides': related_slides,
'previous_slide': previous_slide,
@@ -394,6 +395,7 @@ class WebsiteSlides(WebsiteProfile):
values = {
'channel': channel,
'main_object': channel,
'active_tab': kw.get('active_tab', 'home'),
# search
'search_category': category,
@@ -301,6 +301,9 @@ class Channel(models.Model):
base_url = channel.get_base_url()
channel.website_url = '%s/slides/%s' % (base_url, slug(channel))
def get_backend_menu_id(self):
return self.env.ref('website_slides.website_slides_menu_root').id
def _compute_action_rights(self):
user_karma = self.env.user.karma
for channel in self:
@@ -362,6 +362,9 @@ class Slide(models.Model):
url = '%s/slides/slide/%s' % (base_url, slug(slide))
slide.website_url = url
def get_backend_menu_id(self):
return self.env.ref('website_slides.website_slides_menu_root').id
@api.depends('channel_id.can_publish')
def _compute_can_publish(self):
for record in self:
@@ -110,8 +110,6 @@
<t t-set="body_classname" t-value="'o_wslides_body'"/>
<t t-call="website.layout">
<div id="wrap" t-attf-class="wrap mt-0">
<t t-set="main_object" t-value="channel"/>
<div t-attf-class="o_wslides_course_header o_wslides_gradient position-relative text-white pb-md-0 pt-2 pt-md-5 #{'pb-3' if channel.channel_type == 'training' else 'o_wslides_course_doc_header pb-5'}">
<t t-call="website_slides.course_nav"/>
@@ -5,7 +5,6 @@
<template id="slide_main" name="Slide Detailed View">
<t t-set="body_classname" t-value="'o_wslides_body'"/>
<t t-call="website.layout">
<t t-set="main_object" t-value="slide"/>
<div id="wrap" class="wrap o_wslides_wrap">
<div class="o_wslides_lesson_header o_wslides_gradient position-relative text-white pb-0 pt-2 pt-md-5">
<t t-call="website_slides.course_nav">
@@ -7,7 +7,6 @@
<link rel="canonical" t-att-href="slide.website_url" />
</t>
<t t-call="website.layout">
<t t-set="main_object" t-value="slide"/>
<div class="o_wslides_fs_main d-flex flex-column font-weight-light"
t-att-data-channel-id="slide.channel_id.id"
t-att-data-channel-enroll="slide.channel_id.enroll"