Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] slugify deprecation #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions odoo_module_migrate/migration_scripts/migrate_170_180.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,42 @@ def replace_user_has_groups(
logger.error(f"Error processing file {file}: {str(e)}")


def replace_slugify(
logger, module_path, module_name, manifest_path, migration_steps, tools
):
files_to_process = tools.get_files(module_path, (".py",))

for file in files_to_process:
try:
content = tools._read_content(file)
content = re.sub(
r"from\s+odoo\.addons\.http_routing\.models\.ir_http\s+import\s+slugify\b.*\n",
"",
content,
)
# process in controller (*.py) file are using request
has_request = "request" in content
if has_request:
content = re.sub(
r"""(?<!request\.)\bslugify\(([^)]+)\)""",
r"""request.env["ir.http"]._slugify(\1)""",
content,
)
else:
content = re.sub(
r"""\bslugify\(([^)]+)\)""",
r"""self.env["ir.http"]._slugify(\1)""",
content,
)
tools._write_content(file, content)
except Exception as e:
logger.error(f"Error processing file {file}: {str(e)}")


class MigrationScript(BaseMigrationScript):
_GLOBAL_FUNCTIONS = [
replace_tree_with_list_in_views,
replace_chatter_blocks,
replace_user_has_groups,
replace_slugify,
]
1 change: 1 addition & 0 deletions tests/data_result/module_170_180/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import controllers
1 change: 1 addition & 0 deletions tests/data_result/module_170_180/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
8 changes: 8 additions & 0 deletions tests/data_result/module_170_180/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import http
from odoo.http import request


class MainController(http.Controller):
@http.route("/home/main", type="http", auth="public", website=True)
def redirect_to_main(self):
partner_name = request.env["ir.http"]._slugify(request.env.user.partner_id.name)
1 change: 1 addition & 0 deletions tests/data_result/module_170_180/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import res_partner
from . import website
9 changes: 9 additions & 0 deletions tests/data_result/module_170_180/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import api, models


class Website(models.Model):
_inherit = "website"

@api.model
def example_method_use_slugify(self, page_name):
return "/" + self.env["ir.http"]._slugify(page_name, max_length=1024, path=True)
1 change: 1 addition & 0 deletions tests/data_template/module_170/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import controllers
1 change: 1 addition & 0 deletions tests/data_template/module_170/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
9 changes: 9 additions & 0 deletions tests/data_template/module_170/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import http
from odoo.addons.http_routing.models.ir_http import slugify
from odoo.http import request


class MainController(http.Controller):
@http.route("/home/main", type="http", auth="public", website=True)
def redirect_to_main(self):
partner_name = slugify(request.env.user.partner_id.name)
1 change: 1 addition & 0 deletions tests/data_template/module_170/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import res_partner
from . import website
10 changes: 10 additions & 0 deletions tests/data_template/module_170/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import api, models
from odoo.addons.http_routing.models.ir_http import slugify


class Website(models.Model):
_inherit = "website"

@api.model
def example_method_use_slugify(self, page_name):
return "/" + slugify(page_name, max_length=1024, path=True)
Loading