Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
749e1a67987f
Commit
2ac74d5a
authored
Sep 22, 2011
by
Sylvain Thénault
Browse files
[entity] rename Entity._rest_attr_info into cw_rest_attr_info (closes #1942759)
parent
9bbf83f68bcc
Changes
3
Hide whitespace changes
Inline
Side-by-side
doc/3.14.rst
View file @
749e1a67
...
...
@@ -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.
entity.py
View file @
749e1a67
...
...
@@ -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'
:
...
...
web/views/urlpublishing.py
View file @
749e1a67
...
...
@@ -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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment