Skip to content

Commit fdbe7c3

Browse files
committed
[IMP] slugify deprecation
1 parent 2bfa7bb commit fdbe7c3

File tree

11 files changed

+75
-0
lines changed

11 files changed

+75
-0
lines changed

odoo_module_migrate/migration_scripts/migrate_170_180.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,42 @@ def replace_user_has_groups(
100100
logger.error(f"Error processing file {file}: {str(e)}")
101101

102102

103+
def replace_slugify(
104+
logger, module_path, module_name, manifest_path, migration_steps, tools
105+
):
106+
files_to_process = tools.get_files(module_path, (".py"))
107+
108+
for file in files_to_process:
109+
try:
110+
content = tools._read_content(file)
111+
content = re.sub(
112+
r"from\s+odoo\.addons\.http_routing\.models\.ir_http\s+import\s+slugify\b.*\n",
113+
"",
114+
content,
115+
)
116+
# process in controller (*.py) file are using request
117+
has_request = "request" in content
118+
if has_request:
119+
content = re.sub(
120+
r"""(?<!request\.)\bslugify\(([^)]+)\)""",
121+
r"""request.env["ir.http"]._slugify(\1)""",
122+
content,
123+
)
124+
else:
125+
content = re.sub(
126+
r"""\bslugify\(([^)]+)\)""",
127+
r"""self.env["ir.http"]._slugify(\1)""",
128+
content,
129+
)
130+
tools._write_content(file, content)
131+
except Exception as e:
132+
logger.error(f"Error processing file {file}: {str(e)}")
133+
134+
103135
class MigrationScript(BaseMigrationScript):
104136
_GLOBAL_FUNCTIONS = [
105137
replace_tree_with_list_in_views,
106138
replace_chatter_blocks,
107139
replace_user_has_groups,
140+
replace_slugify,
108141
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import models
2+
from . import controllers
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from odoo import http
2+
from odoo.http import request
3+
4+
5+
class MainController(http.Controller):
6+
@http.route("/home/main", type="http", auth="public", website=True)
7+
def redirect_to_main(self):
8+
partner_name = request.env["ir.http"]._slugify(request.env.user.partner_id.name)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import res_partner
2+
from . import website
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from odoo import api, models
2+
3+
4+
class Website(models.Model):
5+
_inherit = "website"
6+
7+
@api.model
8+
def example_method_use_slugify(self, page_name):
9+
return "/" + self.env["ir.http"]._slugify(page_name, max_length=1024, path=True)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import models
2+
from . import controllers
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from odoo import http
2+
from odoo.addons.http_routing.models.ir_http import slugify
3+
from odoo.http import request
4+
5+
6+
class MainController(http.Controller):
7+
@http.route("/home/main", type="http", auth="public", website=True)
8+
def redirect_to_main(self):
9+
partner_name = slugify(request.env.user.partner_id.name)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
from . import res_partner
2+
from . import website

0 commit comments

Comments
 (0)