Commit 2ac74d5a authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[entity] rename Entity._rest_attr_info into cw_rest_attr_info (closes #1942759)

parent 9bbf83f68bcc
......@@ -23,3 +23,9 @@ API changes in cubicweb 3.14
- client code use direct access to one of those methods on an entity (no code
known to do that)
* `Entity._rest_attr_info` class method has been renamed to
`Entity.cw_rest_attr_info`
No backward compat yet since this is a protected method an no code is known to
use it outside cubicweb itself.
......@@ -345,14 +345,25 @@ class Entity(AppObject):
@classmethod
@cached
def _rest_attr_info(cls):
def cw_rest_attr_info(cls):
"""this class method return an attribute name to be used in URL for
entities of this type and a boolean flag telling if its value should be
checked for uniqness.
The attribute returned is, in order of priority:
* class's `rest_attr` class attribute
* an attribute defined as unique in the class'schema
* 'eid'
"""
mainattr, needcheck = 'eid', True
if cls.rest_attr:
mainattr = cls.rest_attr
needcheck = not cls.e_schema.has_unique_values(mainattr)
else:
for rschema in cls.e_schema.subject_relations():
if rschema.final and rschema != 'eid' and cls.e_schema.has_unique_values(rschema):
if rschema.final and rschema != 'eid' \
and cls.e_schema.has_unique_values(rschema):
mainattr = str(rschema)
needcheck = False
break
......@@ -544,7 +555,7 @@ class Entity(AppObject):
def rest_path(self, use_ext_eid=False): # XXX cw_rest_path
"""returns a REST-like (relative) path for this entity"""
mainattr, needcheck = self._rest_attr_info()
mainattr, needcheck = self.cw_rest_attr_info()
etype = str(self.e_schema)
path = etype.lower()
if mainattr != 'eid':
......
......@@ -174,7 +174,7 @@ class RestPathEvaluator(URLPathEvaluator):
except KeyError:
raise PathDontMatch()
else:
attrname = cls._rest_attr_info()[0]
attrname = cls.cw_rest_attr_info()[0]
value = req.url_unquote(parts.pop(0))
return self.handle_etype_attr(req, cls, attrname, value)
return self.handle_etype(req, cls)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment