-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e8c205
commit 2d760a4
Showing
7 changed files
with
42 additions
and
29 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
raise ValidationError(_('"URL to" is invalid: %s') % e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
This module allows to add absolute url redirects. | ||
This module allows to add absolute url redirects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
To add an absolute url redirect first check "Is absolute url" and then add it on "Url to" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters