[IMP] website: slug method also works with lazy values
Before this commit, the behavior is broken if using lazy values, the condition using isinstance does not work. It's best to use the slug as if given the correct value. Indeed, in odoo, we don't have any other object having `id` as attributes in addition to `seo_name` or `display_name` and not being a recordset and whose slug we want. If there is an error, it is imperative that we provided a tuple (from read). Part-of: odoo/odoo#88276
This commit is contained in:
@@ -89,18 +89,18 @@ def slugify(s, max_length=0, path=False):
|
||||
|
||||
|
||||
def slug(value):
|
||||
if isinstance(value, models.BaseModel):
|
||||
try:
|
||||
if not value.id:
|
||||
raise ValueError("Cannot slug non-existent record %s" % value)
|
||||
# [(id, name)] = value.name_get()
|
||||
identifier, name = value.id, getattr(value, 'seo_name', False) or value.display_name
|
||||
else:
|
||||
except AttributeError:
|
||||
# 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)
|
||||
return f"{slugname}-{identifier}"
|
||||
|
||||
|
||||
# NOTE: as the pattern is used as it for the ModelConverter (ir_http.py), do not use any flags
|
||||
|
||||
Reference in New Issue
Block a user