[FIX] website: fix website page properties
The goal of this commit is to add some fixes on page properties dialog after the Owl REF [1]. - XML: use default form view style (remove </group>). - Move the '/' back into the non editable part of the URL. - Prevent python code from creating a different URL (and optionally setting "website.rewrite" record for it) when the new URL is the same as the initial one after slugify. - 'useAutofocus()' on the first page properties field. [1]: https://github.com/odoo/odoo/commit/61a9d7bd2abc6081b321a51d329f9e85209215e5 task-2687506 closes odoo/odoo#102869 X-original-commit: 1165dfcd4fd5677d14f3d3329ad7c62be847b31a Signed-off-by: Romain Derie (rde) <rde@odoo.com>
This commit is contained in:
@@ -121,7 +121,8 @@ class Page(models.Model):
|
||||
page = self.browse(int(page_id))
|
||||
copy_param = dict(name=page_name or page.name, website_id=self.env['website'].get_current_website().id)
|
||||
if page_name:
|
||||
copy_param['url'] = self.get_valid_page_url(page_name)
|
||||
url = '/' + slugify(page_name, max_length=1024, path=True)
|
||||
copy_param['url'] = self.env['website'].get_unique_path(url)
|
||||
|
||||
new_page = page.copy(copy_param)
|
||||
# Should not clone menu if the page was cloned from one website to another
|
||||
@@ -158,17 +159,16 @@ class Page(models.Model):
|
||||
|
||||
# If URL has been edited, slug it
|
||||
if 'url' in vals:
|
||||
url = vals['url']
|
||||
url = vals['url'] or ''
|
||||
redirect_old_url = redirect_type = None
|
||||
# TODO This should be done another way after the backend/frontend merge
|
||||
if isinstance(url, dict):
|
||||
redirect_old_url = url.get('redirect_old_url')
|
||||
redirect_type = url.get('redirect_type')
|
||||
url = url.get('url')
|
||||
if not url.startswith('/'):
|
||||
url = '/' + url
|
||||
url = '/' + slugify(url, max_length=1024, path=True)
|
||||
if page.url != url:
|
||||
url = self.get_valid_page_url(url, website_id)
|
||||
url = self.env['website'].with_context(website_id=website_id).get_unique_path(url)
|
||||
page.menu_ids.write({'url': url})
|
||||
if redirect_old_url:
|
||||
self.env['website.rewrite'].create({
|
||||
@@ -271,10 +271,6 @@ class Page(models.Model):
|
||||
results = results.filtered(lambda result: filter_page(search, result, results))
|
||||
return results, count
|
||||
|
||||
def get_valid_page_url(self, page_url, website_id=False):
|
||||
url = '/' + slugify(page_url, max_length=1024, path=True)
|
||||
return self.env['website'].with_context(website_id=website_id).get_unique_path(url)
|
||||
|
||||
def action_page_debug_view(self):
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import {PageDependencies} from '@website/components/dialog/page_properties';
|
||||
import {standardFieldProps} from '@web/views/fields/standard_field_props';
|
||||
import {useInputField} from '@web/views/fields/input_field_hook';
|
||||
import {useService} from '@web/core/utils/hooks';
|
||||
import {useAutofocus, useService} from '@web/core/utils/hooks';
|
||||
import {Switch} from '@website/components/switch/switch';
|
||||
import {registry} from '@web/core/registry';
|
||||
import {formatChar} from '@web/views/fields/formatters';
|
||||
@@ -16,15 +16,17 @@ const {Component, useState, onWillStart} = owl;
|
||||
*/
|
||||
class PageUrlField extends Component {
|
||||
setup() {
|
||||
this.orm = useService('orm');
|
||||
this.serverUrl = `${window.location.origin}/`;
|
||||
this.pageUrl = this.fieldURL;
|
||||
|
||||
this.state = useState({
|
||||
redirect_old_url: false,
|
||||
url: this.props.value,
|
||||
url: this.pageUrl,
|
||||
redirect_type: '301',
|
||||
});
|
||||
useInputField({getValue: () => this.props.value.url || this.props.value});
|
||||
|
||||
this.serverUrl = window.location.origin;
|
||||
this.pageUrl = this.props.value;
|
||||
useInputField({getValue: () => this.fieldURL});
|
||||
}
|
||||
|
||||
get enableRedirect() {
|
||||
@@ -36,6 +38,11 @@ class PageUrlField extends Component {
|
||||
this.updateValues();
|
||||
}
|
||||
|
||||
get fieldURL() {
|
||||
const value = this.props.value;
|
||||
return (value.url !== undefined ? value.url : value).replace(/^\//g, '');
|
||||
}
|
||||
|
||||
updateValues() {
|
||||
// HACK: update redirect data from the URL field.
|
||||
// TODO: remove this and use a transient model with redirect fields.
|
||||
@@ -73,6 +80,7 @@ class PageNameField extends Component {
|
||||
this.pageName = this.props.value;
|
||||
this.supportedMimetypes = {};
|
||||
|
||||
useAutofocus({refName: 'input'});
|
||||
onWillStart(() => this.onWillStart());
|
||||
}
|
||||
|
||||
|
||||
@@ -37,29 +37,17 @@
|
||||
<page string="Name">
|
||||
<group class="mt-4">
|
||||
<field name="name" string="Page Name" widget="page_name" placeholder="e.g. Home Page"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="website_id" invisible="1"/>
|
||||
<field name="url" string="Page URL" widget="page_url" required="True"/>
|
||||
<field name="url" string="Page URL" widget="page_url"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Publish">
|
||||
<group class="mt-4">
|
||||
<field name="is_in_menu" string="Show in Top Menu" widget="boolean_toggle"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="is_homepage" string="Use as Homepage" widget="boolean_toggle"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="website_indexed" string="Indexed" widget="boolean_toggle" help="Hide this page from search results"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="is_published" string="Published" widget="boolean_toggle"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_publish" widget="datetime"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="visibility"/>
|
||||
<field name="visibility_password_display" attrs="{'invisible': [('visibility', '!=', 'password')], 'required': [('visibility', '=', 'password')]}" password="True" string="Password"/>
|
||||
<field name="groups_id" attrs="{'invisible': [('visibility', '!=', 'restricted_group')]}" string="Authorized Groups" widget="many2many_tags"/>
|
||||
|
||||
Reference in New Issue
Block a user