From 2d760a4f3e4cd6165368378cf3fe816c973b3ad7 Mon Sep 17 00:00:00 2001 From: "matteo.tognini" Date: Fri, 21 Jul 2023 11:13:25 +0200 Subject: [PATCH] [IMP]Pre commit stuff --- website_rewrite_absolute_url/README.rst | 0 website_rewrite_absolute_url/__init__.py | 2 +- website_rewrite_absolute_url/__manifest__.py | 18 ++++---- .../models/website_rewrite.py | 41 ++++++++++++------- .../readme/DESCRIPTION.rst | 2 +- website_rewrite_absolute_url/readme/USAGE.rst | 2 +- .../views/website_rewrite.xml | 6 +-- 7 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 website_rewrite_absolute_url/README.rst diff --git a/website_rewrite_absolute_url/README.rst b/website_rewrite_absolute_url/README.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_rewrite_absolute_url/__init__.py b/website_rewrite_absolute_url/__init__.py index a466ab6017..31660d6a96 100644 --- a/website_rewrite_absolute_url/__init__.py +++ b/website_rewrite_absolute_url/__init__.py @@ -1,3 +1,3 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from . import models \ No newline at end of file +from . import models diff --git a/website_rewrite_absolute_url/__manifest__.py b/website_rewrite_absolute_url/__manifest__.py index b3a210a644..61e270ca1d 100644 --- a/website_rewrite_absolute_url/__manifest__.py +++ b/website_rewrite_absolute_url/__manifest__.py @@ -1,14 +1,14 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Rewrite rules with absolute url', - 'version': '16.0.1.0.0', - 'category': 'base', - 'summary': 'Rewrite rules with absolute url', - 'author': 'Nextev, Odoo Community Association (OCA)', + "name": "Rewrite rules with absolute url", + "version": "16.0.1.0.0", + "category": "base", + "summary": "Rewrite rules with absolute url", + "author": "Nextev, Odoo Community Association (OCA)", "website": "https://github.com/OCA/website", - 'license': 'AGPL-3', - 'depends': ['website'], - 'data': ['views/website_rewrite.xml'], - 'installable': True + "license": "AGPL-3", + "depends": ["website"], + "data": ["views/website_rewrite.xml"], + "installable": True, } diff --git a/website_rewrite_absolute_url/models/website_rewrite.py b/website_rewrite_absolute_url/models/website_rewrite.py index fef78b68eb..e03f975c2a 100644 --- a/website_rewrite_absolute_url/models/website_rewrite.py +++ b/website_rewrite_absolute_url/models/website_rewrite.py @@ -1,36 +1,49 @@ import re + import werkzeug -from odoo import models, fields, api, _ +from odoo import _, api, fields, models from odoo.exceptions import ValidationError class WebsiteRewrite(models.Model): - _inherit = 'website.rewrite' - + _inherit = "website.rewrite" + absolute_url = fields.Boolean("Is absolute url") - @api.constrains('url_to', 'url_from', 'redirect_type') + @api.constrains("url_to", "url_from", "redirect_type") def _check_url_to(self): for rewrite in self: - if rewrite.redirect_type in ['301', '302', '308']: + if rewrite.redirect_type in ["301", "302", "308"]: if not rewrite.url_to: raise ValidationError(_('"URL to" can not be empty.')) - elif not rewrite.absolute_url and not rewrite.url_to.startswith('/'): - raise ValidationError(_('"URL to" must start with a leading slash.')) - for param in re.findall('/<.*?>', rewrite.url_from): + elif not rewrite.absolute_url and not rewrite.url_to.startswith("/"): + raise ValidationError( + _('"URL to" must start with a leading slash.') + ) + for param in re.findall("/<.*?>", rewrite.url_from): if param not in rewrite.url_to: - raise ValidationError(_('"URL to" must contain parameter %s used in "URL from".') % param) - for param in re.findall('/<.*?>', rewrite.url_to): + raise ValidationError( + _('"URL to" must contain parameter %s used in "URL from".') + % param + ) + for param in re.findall("/<.*?>", rewrite.url_to): if param not in rewrite.url_from: - raise ValidationError(_('"URL to" cannot contain parameter %s which is not used in "URL from".') % param) + raise ValidationError( + _( + '"URL to" cannot contain parameter %s which is not used in "URL from".' + ) + % param + ) try: - converters = self.env['ir.http']._get_converters() - routing_map = werkzeug.routing.Map(strict_slashes=False, converters=converters) + converters = self.env["ir.http"]._get_converters() + routing_map = werkzeug.routing.Map( + strict_slashes=False, converters=converters + ) if not rewrite.absolute_url: rule = werkzeug.routing.Rule(rewrite.url_to) routing_map.add(rule) else: routing_map.bind(rewrite.url_to) except ValueError as e: - raise ValidationError(_('"URL to" is invalid: %s') % e) \ No newline at end of file + raise ValidationError(_('"URL to" is invalid: %s') % e) diff --git a/website_rewrite_absolute_url/readme/DESCRIPTION.rst b/website_rewrite_absolute_url/readme/DESCRIPTION.rst index 04901afe44..c00f504abd 100644 --- a/website_rewrite_absolute_url/readme/DESCRIPTION.rst +++ b/website_rewrite_absolute_url/readme/DESCRIPTION.rst @@ -1 +1 @@ -This module allows to add absolute url redirects. \ No newline at end of file +This module allows to add absolute url redirects. diff --git a/website_rewrite_absolute_url/readme/USAGE.rst b/website_rewrite_absolute_url/readme/USAGE.rst index c88771b6e4..3f0e79638e 100644 --- a/website_rewrite_absolute_url/readme/USAGE.rst +++ b/website_rewrite_absolute_url/readme/USAGE.rst @@ -1,3 +1,3 @@ Website > Configuration >  Redirects -To add an absolute url redirect first check "Is absolute url" and then add it on "Url to" \ No newline at end of file +To add an absolute url redirect first check "Is absolute url" and then add it on "Url to" diff --git a/website_rewrite_absolute_url/views/website_rewrite.xml b/website_rewrite_absolute_url/views/website_rewrite.xml index 1d859a1e5b..f73de51da9 100644 --- a/website_rewrite_absolute_url/views/website_rewrite.xml +++ b/website_rewrite_absolute_url/views/website_rewrite.xml @@ -1,12 +1,12 @@ - + rewrite.absolute.url website.rewrite - + - +