[IMP] website: improve pagemanager to be multi website compliant

Now we can see which specific page override wich page when page are sorted by url.

Co-authored-by: Derie Romain <rde@odoo.com>
Co-authored-by: Kersten Jérémy <jke@odoo.com>
This commit is contained in:
Jeremy Kersten
2018-08-13 19:51:32 +02:00
co-authored by Derie Romain
parent ff26b20a48
commit a45bb90fac
8 changed files with 98 additions and 70 deletions
+8 -6
View File
@@ -224,25 +224,27 @@ class Website(Home):
'name': {'label': _('Sort by Name'), 'order': 'name'},
}
# default sortby order
sort_order = searchbar_sortings.get(sortby, 'name')['order']
sort_order = searchbar_sortings.get(sortby, 'name')['order'] + ', website_id desc'
domain = request.website.website_domain()
if search:
domain += ['|', ('name', 'ilike', search), ('url', 'ilike', search)]
pages_count = Page.search_count(domain)
pages = Page.search(domain, order=sort_order)
if sortby != 'url':
pages = pages.filtered(pages._is_most_specific_page)
pages_count = len(pages)
step = 50
pager = portal_pager(
url="/website/pages",
url_args={'sortby': sortby},
total=pages_count,
page=page,
step=50
step=step
)
pages = Page.search(domain, order=sort_order, limit=50, offset=pager['offset'])
# only include pages if they are the most specific one available
pages = pages.filtered(pages._is_most_specific_page)
pages = pages[(page - 1) * step:page * step]
values = {
'pager': pager,
+5 -8
View File
@@ -119,14 +119,11 @@ class Http(models.AbstractModel):
req_page = request.httprequest.path
page_domain = [('url', '=', req_page)] + request.website.website_domain()
published_domain = page_domain + [('website_published', '=', True)]
pages = request.env['website.page'].search(published_domain, order='website_id')
if not pages:
# Since there are no published pages, try to find a page
# that could potentially be published.
unpublished_domain = page_domain + [('website_published', '=', False)]
pages = request.env['website.page'].search(unpublished_domain, order='website_id')
published_domain = page_domain
# need to bypass website_published, to apply is_most_specific
# filter later if not publisher
pages = request.env['website.page'].sudo().search(published_domain, order='website_id')
pages = pages.filtered(pages._is_most_specific_page)
if not request.website.is_publisher():
pages = pages.filtered('is_visible')
+10 -9
View File
@@ -791,13 +791,10 @@ class Page(models.Model):
return most_specific_page == page_to_test
@api.model
def get_page_info(self, id, website_id):
item = self.search_read(
domain=[('id', '=', id)] + self.env['website'].website_domain(website_id),
fields=['id', 'name', 'url', 'website_published', 'website_indexed', 'date_publish', 'menu_ids', 'is_homepage', 'website_id'],
limit=1
def get_page_info(self, id):
return self.browse(id).read(
['id', 'name', 'url', 'website_published', 'website_indexed', 'date_publish', 'menu_ids', 'is_homepage', 'website_id'],
)
return item
@api.multi
def get_view_identifier(self):
@@ -845,16 +842,20 @@ class Page(models.Model):
# Edits via the page manager shouldn't trigger the COW
# mechanism and generate new pages. The user manages page
# visibility manually with is_published here.
page.with_context(no_cow=True).write({
w_vals = {
'key': page_key,
'name': data['name'],
'url': url,
'is_published': data['website_published'],
'website_id': website.id if data['restrict_to_current_website'] else False,
'website_id': False if data['share_page_info'] else website.id,
'website_indexed': data['website_indexed'],
'date_publish': data['date_publish'] or None,
'is_homepage': data['is_homepage'],
})
}
# toggle is hidden to prevent user to unshare a page
if 'share_page_info' in data:
w_vals['website_id'] = False if data['share_page_info'] else website.id
page.with_context(no_cow=True).write(w_vals)
# Create redirect if needed
if data['create_redirect']:
+2 -2
View File
@@ -81,7 +81,7 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({
defs.push(this._rpc({
model: 'website.page',
method: 'get_page_info',
args: [this.page_id, context.website_id],
args: [this.page_id],
context: context,
}).then(function (page) {
page[0].url = _.str.startsWith(page[0].url, '/') ? page[0].url.substring(1) : page[0].url;
@@ -220,7 +220,7 @@ var PagePropertiesDialog = weWidgets.Dialog.extend({
is_menu: this.$('#is_menu').prop('checked'),
is_homepage: this.$('#is_homepage').prop('checked'),
website_published: this.$('#is_published').prop('checked'),
restrict_to_current_website: this.$('#restrict_to_current_website').prop('checked'),
share_page_info: this.$('#share_page_info').prop('checked'),
create_redirect: this.$('#create_redirect').prop('checked'),
redirect_type: this.$('#redirect_type').val(),
website_indexed: this.$('#is_indexed').prop('checked'),
+12 -4
View File
@@ -468,11 +468,19 @@ body .modal {
background-color: $o-brand-odoo;
color: white;
}
td > a.fa {
margin-left: 5px;
color: $o-brand-odoo;
td, th {
padding: 0.45rem;
}
td {
> a.fa {
margin-left: 5px;
color: $o-brand-odoo;
}
.text-muted {
opacity: 0.5;
}
}
.fa-check, .fa-eye-slash {
color: $o-brand-primary;
color: #00a09d;
}
}
@@ -88,26 +88,26 @@
</div>
</div>
<div role="tabpanel" id="advances_page_info" class="tab-pane fade">
<div class="form-group row">
<label class="col-form-label col-md-3" for="is_menu">Show in Top Menu</label>
<div class="col-md-2">
<div class="form-group">
<label class="control-label col-md-5" for="is_menu">Show in Top Menu</label>
<div class="col-sm-2">
<label class="o_switch" for="is_menu" >
<input type="checkbox" t-att-checked="widget.page.menu_ids.length > 0 ? true : undefined" id="is_menu"/>
<span/>
</label>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-md-3" for="is_homepage">Use as Homepage</label>
<div class="col-md-2">
<div class="form-group">
<label class="control-label col-md-5" for="is_homepage">Use as Homepage</label>
<div class="col-sm-2">
<label class="o_switch" for="is_homepage" >
<input type="checkbox" t-att-checked="widget.page.is_homepage ? true : undefined" id="is_homepage"/>
<span/>
</label>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-md-3" for="is_indexed">
<div class="form-group">
<label class="control-label col-md-5" for="is_indexed">
Indexed
<i class="fa fa-question-circle-o" title="Hide this page from search results" role="img" aria-label="Info"></i>
</label>
@@ -118,33 +118,33 @@
</label>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-md-3" for="is_published">Publish</label>
<div class="col-md-2">
<div class="form-group">
<label class="control-label col-md-5" for="is_published">Publish</label>
<div class="col-sm-2">
<label class="o_switch js_publish_btn" for="is_published">
<input type="checkbox" t-att-checked="widget.page.website_published ? true : undefined" id="is_published"/>
<span/>
</label>
</div>
</div>
<div class="form-group" id="website_restriction">
<div t-if='widget.page.website_id' class="form-group" id="website_restriction">
<!-- TODO hide with multi-website group -->
<label class="control-label col-md-3" for="restrict_to_current_website">
Restrict to current website
<i class="fa fa-question-circle-o" title="When enabled, this page is only accessible through the current website" role="img" aria-label="Info"></i>
<label class="control-label col-md-5" for="share_page_info">
Share this page
<i class="fa fa-question-circle-o" title="When enabled, this page will be shared between all the websites. This change is not reversible."></i>
</label>
<div class="col-md-2">
<a>
<label class="o_switch" for="restrict_to_current_website" >
<input type="checkbox" t-att-checked="widget.page.website_id ? true : undefined" id="restrict_to_current_website"/>
<label class="o_switch" for="share_page_info" >
<input type="checkbox" t-att-checked="widget.page.website_id ? undefined : true" id="share_page_info"/>
<span/>
</label>
</a>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3" for="date_publish">Publishing Date</label>
<div class="col-md-9">
<label class="control-label col-md-5" for="date_publish">Publishing Date</label>
<div class="col-sm-7">
<div class='input-group date' id='date_publish_container'>
<input type='text' class="form-control" name="date_publish" id="date_publish" />
<div class="input-group-append">
+41 -21
View File
@@ -1089,33 +1089,27 @@ Sitemap: <t t-esc="url_root"/>sitemap.xml
</div>
</t>
<div t-if="pages" class="table-responsive">
<table class="table table-hover o_my_status_table">
<table class="table table-hover">
<thead>
<tr class="active">
<tr>
<th>Name</th>
<th>Url</th>
<th class="col-lg-1 text-center"><i title="Is the page included in the main menu?" role="img" aria-label="Is the page included in the main menu?" class="fa fa-thumb-tack"></i></th>
<th class="col-lg-1 text-center"><i title="Is the page published?" role="img" aria-label="Is the page published?" class="fa fa-eye"></i></th>
<th class="col-lg-1 text-center"><i title="Is the page indexed by search engines?" role="img" aria-label="Is the page indexed by search engines?" class="fa fa-globe"></i></th>
<th class="col-md-3 col-lg-2"></th>
<th class="text-center"><i title="Is the page included in the main menu?" class="fa fa-thumb-tack"></i></th>
<th class="text-center"><i title="Is the page published?" class="fa fa-eye"></i></th>
<th class="text-center"><i title="Is the page indexed by search engines?" class="fa fa-globe"></i></th>
<th style='width:140px;'></th>
</tr>
</thead>
<t t-foreach="pages" t-as="page">
<tr>
<td><i t-if="page.is_homepage" class="fa fa-home" role="img" aria-label="Home" title="Home"></i> <span style="word-break: break-all;" t-esc="page.name"/></td>
<td><a style="word-break: break-all;" t-attf-href="{{page.url}}"><t t-esc="page.url"/></a></td>
<td class="text-center"><i t-att-class="'fa fa-check' if page.menu_ids else 'fa fa-times text-muted'" role="img" t-att-aria-label="'Checked' if page.menu_ids else 'Not checked'" t-att-title="'Checked' if page.menu_ids else 'Not checked'"></i></td>
<t t-set='date_formatted'><t t-options='{"widget": "date"}' t-esc="page.date_publish"/></t>
<td class="text-center"><i t-att-title="not page.is_visible and page.website_published and 'This page will be visible on ' + date_formatted" role="img" t-att-aria-label="not page.is_visible and page.website_published and 'This page will be visible on ' + date_formatted" t-att-class="'fa fa-check' if page.is_visible and page.website_published else 'fa fa-eye-slash' if not page.is_visible and page.website_published else 'fa fa-times text-muted'"></i></td>
<td class="text-center"><i t-att-class="'fa fa-check' if page.website_indexed else 'fa fa-times text-muted'" role="img" t-att-aria-label="'Checked' if page.website_indexed else 'Not checked'" t-att-title="'Checked' if page.website_indexed else 'Not checked'"></i></td>
<td class="text-right">
<a class="mr4 fa fa-cog js_page_properties" t-att-data-id="page.id" href="#" title="Manage this page" aria-label="Manage this page"></a>
<a class="mr4 fa fa-pencil-square-o" t-attf-href="/web#id=#{page.view_id.id}&amp;view_type=form&amp;model=ir.ui.view" title="Edit code in backend" aria-label="Edit code in backend"></a>
<a class="mr4 fa fa-clone js_clone_page" t-att-data-id="page.id" href="#" title="Clone this page" aria-label="Clone this page"></a>
<a class="fa fa-trash js_delete_page" t-att-data-id="page.id" href="#" title="Delete this page" aria-label="Delete this page"></a>
</td>
</tr>
<t t-set='prev_page' t-value='False' />
<t t-set='page' t-value='pages[0]' />
<t t-foreach="pages[1:]" t-as="next_page">
<t t-call='website.one_page_line'/>
<t t-set='prev_page' t-value='page' />
<t t-set='page' t-value='next_page' />
</t>
<t t-set='next_page' t-value='False'/>
<t t-call='website.one_page_line' />
</table>
</div>
<div t-if="pager" class="o_portal_pager text-center">
@@ -1126,6 +1120,32 @@ Sitemap: <t t-esc="url_root"/>sitemap.xml
</t>
</template>
<template id="one_page_line">
<t t-set='specific_page' t-value="page.website_id" />
<t t-set='final_page' t-value="(next_page and page.url != next_page.url) or not next_page or specific_page"/>
<tr t-att-style='not final_page and "color:#999"'>
<td>
<t t-if='specific_page and prev_page and prev_page.url == page.url and not prev_page.website_id'><i class="fa fa-level-up fa-rotate-90 ml32 mr4"></i></t>
<i t-else="1" class="fa fa-globe mr4" t-att-style='specific_page and "visibility:hidden;"' />
<i t-if="page.is_homepage" class="fa fa-home" title="Home"></i> <span t-esc="page.name"/>
</td>
<td><a t-if='final_page' t-attf-href="{{page.url}}"><t t-esc="page.url"/></a></td>
<td class="text-center"><i t-att-class="'fa fa-check' if page.menu_ids else 'fa fa-times text-muted'" t-att-title="'Checked' if page.menu_ids else 'Not checked'"></i></td>
<t t-set='date_formatted'><t t-options='{"widget": "date"}' t-esc="page.date_publish"/></t>
<td class="text-center">
<i t-att-title="not page.is_visible and page.website_published and 'This page will be visible on ' + date_formatted"
t-att-class="'fa fa-check' if page.is_visible and page.website_published else 'fa fa-eye-slash' if not page.is_visible and page.website_published else 'fa fa-times text-muted'"></i>
</td>
<td class="text-center"><i t-att-class="'fa fa-check' if page.website_indexed else 'fa fa-times text-muted'" t-att-title="'Checked' if page.website_indexed else 'Not checked'"></i></td>
<td class="text-right" style="white-space:nowrap;">
<a class="mr4 fa fa-cog js_page_properties" t-att-data-id="page.id" href="#" title="Manage this page"></a>
<a class="mr4 fa fa-pencil-square-o" t-attf-href="/web#id=#{page.view_id.id}&amp;view_type=form&amp;model=ir.ui.view" title="Edit code in backend"></a>
<a class="mr4 fa fa-clone js_clone_page" t-att-data-id="page.id" href="#" title="Clone this page"></a>
<a class="fa fa-trash js_delete_page" t-att-data-id="page.id" href="#" title="Delete this page"></a>
</td>
</tr>
</template>
<template id="default_homepage">
<div id="wrap" class="oe_structure oe_empty">
<div class="item image_text oe_img_bg active">
+1 -1
View File
@@ -156,7 +156,7 @@
<field name="name">website.page.list</field>
<field name="model">website.page</field>
<field name="arch" type="xml">
<tree string="Website Pages">
<tree string="Website Pages" default_order="name">
<field name="name"/>
<field name="url"/>
<field name="website_indexed"/>