[pyramid] Try "eid" first when retrieving a subresource of ETypeResource
So that Pyramid traversal works as existing CubicWeb URL publishing.
--- a/cubicweb/pyramid/resources.py Tue Nov 15 12:20:02 2016 +0100
+++ b/cubicweb/pyramid/resources.py Tue Nov 15 11:44:05 2016 +0100
@@ -64,8 +64,17 @@
self.cls = vreg['etypes'].etype_class(self.etype)
def __getitem__(self, value):
- attrname = self.cls.cw_rest_attr_info()[0]
- return EntityResource(self.request, self.cls, attrname, value)
+ # Try eid first, then rest attribute as for URL path evaluation
+ # mecanism in cubicweb.web.views.urlpublishing.
+ for attrname in ('eid', self.cls.cw_rest_attr_info()[0]):
+ resource = EntityResource(self.request, self.cls, attrname, value)
+ try:
+ rset = resource.rset
+ except HTTPNotFound:
+ continue
+ if rset.rowcount:
+ return resource
+ raise KeyError(value)
@reify
def rset(self):