-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
a74c1d2
commit 14ffb4b
Showing
16 changed files
with
793 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
===================== | ||
Website Page Redirect | ||
===================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:3eaca071ad228aab0540926070c564d408d2868cd41e0dc43a59d67aba5e5e68 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github | ||
:target: https://github.com/OCA/website/tree/17.0/website_page_redirect | ||
:alt: OCA/website | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/website-17-0/website-17-0-website_page_redirect | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to configure an redirect for specific website pages. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To configure a redirect for the page, you need to: | ||
|
||
1. Go to *Website > Site > Pages* | ||
2. Open the page of interest | ||
3. Check the *Redirect* checkbox | ||
4. Configure the *Redirect URL* field | ||
5. Configure the *Redirect Method* and related fields | ||
6. Save the page | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_page_redirect%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* CorporateHub | ||
|
||
Contributors | ||
------------ | ||
|
||
- ``CorporateHub <https://corporatehub.eu/>``\ \_\_ | ||
|
||
- Alexey Pelykh [email protected] | ||
|
||
Maintainers | ||
----------- | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-alexey-pelykh| image:: https://github.com/alexey-pelykh.png?size=40px | ||
:target: https://github.com/alexey-pelykh | ||
:alt: alexey-pelykh | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-alexey-pelykh| | ||
|
||
This module is part of the `OCA/website <https://github.com/OCA/website/tree/17.0/website_page_redirect>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2024 CorporateHub (https://corporatehub.eu) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 CorporateHub (https://corporatehub.eu) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Website Page Redirect", | ||
"summary": "Redirect page to another URL", | ||
"category": "Website", | ||
"version": "17.0.1.0.0", | ||
"author": "CorporateHub, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/website", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"website", | ||
], | ||
"data": [ | ||
"views/website_layout.xml", | ||
"views/website_page.xml", | ||
], | ||
"installable": True, | ||
"maintainers": ["alexey-pelykh"], | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2024 CorporateHub (https://corporatehub.eu) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import ir_http | ||
from . import website_page |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2024 CorporateHub (https://corporatehub.eu) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import logging | ||
|
||
from markupsafe import Markup | ||
from odoo import http, models | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class IrHttp(models.AbstractModel): | ||
_inherit = "ir.http" | ||
|
||
@classmethod | ||
def _serve_page(cls): | ||
response = super()._serve_page() | ||
|
||
# In case there was no matching page or the response is not a Markup, | ||
# or it's not a visible page, or it's a redirect page. | ||
logger.error("Response: %s", response) | ||
if not response \ | ||
or not isinstance(response, Markup) \ | ||
or getattr(response, "status_code", 0) != 200: | ||
return response | ||
|
||
# Get the page that was just served | ||
page = ( | ||
http.request.env["website.page"] | ||
.sudo() | ||
.search( | ||
[("url", "=", http.request.httprequest.path)], | ||
order="website_id asc", | ||
limit=1, | ||
) | ||
) | ||
if not page: | ||
logger.error("Served page found for URL %s", http.request.httprequest.path) | ||
return response | ||
|
||
logger.error("Page: %s", page) | ||
if not page.is_redirect or page.redirect_method != "http": | ||
return response | ||
return http.request.redirect( | ||
page.redirect_url, | ||
code=int(page.redirect_http_code) if page.redirect_http_code else 301, | ||
local=page.redirect_url.lower().startswith("http"), | ||
) |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Copyright 2024 CorporateHub (https://corporatehub.eu) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class WebsitePage(models.Model): | ||
_inherit = "website.page" | ||
|
||
is_redirect = fields.Boolean( | ||
string="Redirect", | ||
help="If checked, this page will redirect to another URL.", | ||
) | ||
redirect_url = fields.Char( | ||
string="Redirect URL", | ||
help="URL to redirect to when this page is accessed.", | ||
) | ||
redirect_method = fields.Selection( | ||
selection=[ | ||
("http", "HTTP"), | ||
("meta", "Meta Refresh"), | ||
("js", "JavaScript"), | ||
], | ||
default="http", | ||
help="Method to use for the redirect.", | ||
) | ||
redirect_http_code = fields.Selection( | ||
selection=[ | ||
("301", "301 Moved Permanently"), | ||
("302", "302 Found"), | ||
("303", "303 See Other"), | ||
("307", "307 Temporary Redirect"), | ||
("308", "308 Permanent Redirect"), | ||
], | ||
string="Redirect HTTP Code", | ||
default="301", | ||
help="HTTP status code to use for the redirect.", | ||
) | ||
redirect_delay = fields.Integer( | ||
default=0, | ||
help=( | ||
"Delay before redirect (in seconds) for Meta-Refresh and JavaScript" | ||
" redirect methods." | ||
), | ||
) | ||
redirect_js_code = fields.Text( | ||
compute="_compute_redirect_js_code", | ||
string="Redirect JavaScript Code", | ||
) | ||
|
||
@api.depends("redirect_url", "redirect_delay", "redirect_method") | ||
def _compute_redirect_js_code(self): | ||
for page in self: | ||
if page.redirect_method != "js": | ||
page.redirect_js_code = "" | ||
continue | ||
page.redirect_js_code = ( | ||
"setTimeout(" | ||
f" function() {{ window.location.replace('{page.redirect.url}'); }}," | ||
f" {page.redirect_delay * 1000}," | ||
");" | ||
) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
To configure a redirect for the page, you need to: | ||
|
||
1. Go to *Website \> Site \> Pages* | ||
2. Open the page of interest | ||
3. Check the *Redirect* checkbox | ||
4. Configure the *Redirect URL* field | ||
5. Configure the *Redirect Method* and related fields | ||
6. Save the page |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* `CorporateHub <https://corporatehub.eu/>`__ | ||
|
||
* Alexey Pelykh <[email protected]> | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
This module allows to configure an redirect for specific website pages. |
Oops, something went wrong.