# HG changeset patch # User Sylvain Thénault # Date 1244221460 -7200 # Node ID af33833d757155b06b856314e45310d03dfeeee1 # Parent 7ef12c03447cd337f08eafb48b58f1391755c8a3 absolute_url / build_url refactoring to avoid potential name clash diff -r 7ef12c03447c -r af33833d7571 __init__.py --- a/__init__.py Fri Jun 05 15:09:20 2009 +0200 +++ b/__init__.py Fri Jun 05 19:04:20 2009 +0200 @@ -109,11 +109,16 @@ # url generation methods ################################################## - def build_url(self, method, base_url=None, **kwargs): + def build_url(self, *args, **kwargs): """return an absolute URL using params dictionary key/values as URL parameters. Values are automatically URL quoted, and the publishing method to use may be specified or will be guessed. """ + # use *args since we don't want first argument to be "anonymous" to + # avoid potential clash with kwargs + assert len(args) == 1, 'only 0 or 1 non-named-argument expected' + method = args[0] + base_url = kwargs.pop('base_url', None) if base_url is None: base_url = self.base_url() if '_restpath' in kwargs: diff -r 7ef12c03447c -r af33833d7571 appobject.py --- a/appobject.py Fri Jun 05 15:09:20 2009 +0200 +++ b/appobject.py Fri Jun 05 19:04:20 2009 +0200 @@ -204,11 +204,18 @@ controller = 'view' - def build_url(self, method=None, **kwargs): + def build_url(self, *args, **kwargs): """return an absolute URL using params dictionary key/values as URL parameters. Values are automatically URL quoted, and the publishing method to use may be specified or will be guessed. """ + # use *args since we don't want first argument to be "anonymous" to + # avoid potential clash with kwargs + if args: + assert len(args) == 1, 'only 0 or 1 non-named-argument expected' + method = args[0] + else: + method = None # XXX I (adim) think that if method is passed explicitly, we should # not try to process it and directly call req.build_url() if method is None: diff -r 7ef12c03447c -r af33833d7571 entity.py --- a/entity.py Fri Jun 05 15:09:20 2009 +0200 +++ b/entity.py Fri Jun 05 19:04:20 2009 +0200 @@ -373,8 +373,15 @@ return self.vreg.render(vid, self.req, rset=self.rset, row=self.row, col=self.col, **kwargs) - def absolute_url(self, method=None, **kwargs): + def absolute_url(self, *args, **kwargs): """return an absolute url to view this entity""" + # use *args since we don't want first argument to be "anonymous" to + # avoid potential clash with kwargs + if args: + assert len(args) == 1, 'only 0 or 1 non-named-argument expected' + method = args[0] + else: + method = None # in linksearch mode, we don't want external urls else selecting # the object for use in the relation is tricky # XXX search_state is web specific