forked from itpp-labs/misc-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
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
310064a
commit f4e133f
Showing
5 changed files
with
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Page redirections | ||
================= | ||
|
||
The module allows configure redirections rules. E.g. | ||
|
||
contactus.php -> /page/website.contactus | ||
|
||
Tested on Odoo 8.0 ea60fed97af1c139e4647890bf8f68224ea1665b |
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 @@ | ||
import website_redirect_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,12 @@ | ||
{ | ||
'name': "Page redirections", | ||
'version': '1.0.0', | ||
'author': 'Ivan Yelizariev', | ||
'category': 'Custom', | ||
'website': 'https://yelizariev.github.io', | ||
'depends': ['website'], | ||
'data': [ | ||
'website_redirect_views.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from openerp import api, models, fields, SUPERUSER_ID | ||
from openerp.http import request | ||
import fnmatch | ||
import werkzeug.utils | ||
|
||
class website_redirect(models.Model): | ||
_name = 'website.redirect' | ||
|
||
_order = 'sequence,id' | ||
|
||
name = fields.Char('Name') | ||
active = fields.Boolean('Active', default=True) | ||
sequence = fields.Integer('Sequence') | ||
domain = fields.Char('Domain Name', placeholder='odoo.com', help='keep empty to apply rules for any domain') | ||
|
||
rule_ids = fields.One2many('website.redirect.rule', 'redirect_id', string='Rules') | ||
|
||
class website_redirect(models.Model): | ||
_name = 'website.redirect.rule' | ||
|
||
_order = 'sequence,id' | ||
sequence = fields.Integer('Sequence') | ||
pattern = fields.Char('From', help='Unix shell-style wildcards. Check https://docs.python.org/2/library/fnmatch.html for details') | ||
target = fields.Char('To') | ||
redirect_id = fields.Many2one('website.redirect') | ||
|
||
class ir_http(models.AbstractModel): | ||
_inherit = 'ir.http' | ||
|
||
def _dispatch(self): | ||
host = request.httprequest.environ.get('HTTP_HOST', '').split(':')[0] | ||
www, _, h = host.partition('.') | ||
if www == 'www': | ||
host = h | ||
path = request.httprequest.path | ||
print 'path', path | ||
redirect_ids = self.pool['website.redirect'].search(request.cr, SUPERUSER_ID, []) | ||
for redirect in self.pool['website.redirect'].browse(request.cr, SUPERUSER_ID, redirect_ids): | ||
if redirect.domain and redirect.domain != host: | ||
continue | ||
|
||
for rule in redirect.rule_ids: | ||
if fnmatch.fnmatch(path, rule.pattern): | ||
code = 302 | ||
return werkzeug.utils.redirect(rule.target, code) | ||
return super(ir_http, self)._dispatch() |
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,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp><data> | ||
|
||
<record model="ir.ui.view" id="view_website_redirect_form"> | ||
<field name="name">website.redirect.form</field> | ||
<field name="model">website.redirect</field> | ||
<field name="type">form</field> | ||
<field name="arch" type="xml"> | ||
<form string="Redirection"> | ||
<sheet> | ||
<div class="oe_title"> | ||
<label for="name" class="oe_edit_only"/> | ||
<h1> | ||
<field name="name"/> | ||
</h1> | ||
</div> | ||
<group> | ||
<field name="domain"/> | ||
<field name="active"/> | ||
</group> | ||
<notebook> | ||
<page string="Rules"> | ||
<field name="rule_ids"> | ||
<tree editable="bottom"> | ||
<field name="sequence" widget="handle"/> | ||
<field name="pattern"/> | ||
<field name="target"/> | ||
</tree> | ||
</field> | ||
</page> | ||
</notebook> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="view_website_redirect_tree" model="ir.ui.view"> | ||
<field name="name">website.redirect.tree</field> | ||
<field name="model">website.redirect</field> | ||
<field name="arch" type="xml"> | ||
<tree string="Redirections"> | ||
<field name="sequence" widget="handle"/> | ||
<field name="name"/> | ||
<field name="domain"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record id="action_website_redirect" model="ir.actions.act_window"> | ||
<field name="name">Redirections</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">website.redirect</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">tree,form</field> | ||
</record> | ||
|
||
|
||
<menuitem id="menu_website_redirect" parent="base.menu_config" | ||
sequence="90" action="action_website_redirect"/> | ||
|
||
|
||
</data></openerp> |