This question has been flagged
1 Reply
6890 Views

Hi All,

Does any has idea about slug and slugify methods?

Located at

odoo/ addons/website/models/website.py   Line : 123

I just to override this method to handle 1 exception in this method

If anyone has already use this method or any idea about it, would be really appreciated.


Best Regards,
Anil Kesariya




Avatar
Discard
Author Best Answer

Hi All,

I've found solution

Here is the solution which i was looking for.


from odoo import models
from odoo.exceptions import AccessError
import odoo
from odoo.addons.website.models.website import slugify

def my_slug(value):
if isinstance(value, models.BaseModel):
if isinstance(value.id, models.NewId):
raise ValueError("Cannot slug non-existent record %s" % value)
# [(id, name)] = value.name_get()
# identifier, name = value.id, value.display_name
identifier = value.id
try:
name = value.display_name
except AccessError:
print "This page is not accessible.... custom method.."
# To do return new template with message
else:
# assume name_search result tuple
identifier, name = value

slugname = slugify(name or '').strip().strip('-')
if not slugname:
return str(identifier)
return "%s-%d" % (slugname, identifier)


def new_to_url(self, value):
return my_slug(value)

odoo.addons.website.models.ir_http.ModelConverter.to_url = new_to_url

Rgds,

Anil

Avatar
Discard