minor refactoring of absolute_url() stable
authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
Fri, 22 May 2009 01:30:20 +0200
branchstable
changeset 1904 e23536d29231
parent 1903 c30034fe074f
child 1905 9c96dd7cc624
minor refactoring of absolute_url()
entity.py
--- a/entity.py	Fri May 22 01:29:35 2009 +0200
+++ b/entity.py	Fri May 22 01:30:20 2009 +0200
@@ -379,7 +379,7 @@
         # XXX search_state is web specific
         if getattr(self.req, 'search_state', ('normal',))[0] == 'normal':
             kwargs['base_url'] = self.metainformation()['source'].get('base-url')
-        if method is None or method == 'view':
+        if method in (None, 'view'):
             try:
                 kwargs['_restpath'] = self.rest_path(kwargs.get('base_url'))
             except TypeError:
@@ -404,11 +404,10 @@
                 # make sure url is not ambiguous
                 rql = 'Any COUNT(X) WHERE X is %s, X %s %%(value)s' % (
                     etype, mainattr)
-                if value is not None:
-                    nbresults = self.req.execute(rql, {'value' : value})[0][0]
-                    if nbresults != 1: # ambiguity?
-                        mainattr = 'eid'
-                        path += '/eid'
+                nbresults = self.req.execute(rql, {'value' : value})[0][0]
+                if nbresults != 1: # ambiguity?
+                    mainattr = 'eid'
+                    path += '/eid'
         if mainattr == 'eid':
             if use_ext_eid:
                 value = self.metainformation()['extid']