stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 13 Aug 2009 09:59:35 +0200
changeset 2798 9c650701cb17
parent 2797 de0fcdb65e30
child 2799 b703639614e7
child 2800 31c3a045e04d
stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
appobject.py
req.py
web/form.py
web/views/embedding.py
--- a/appobject.py	Thu Aug 13 09:49:21 2009 +0200
+++ b/appobject.py	Thu Aug 13 09:59:35 2009 +0200
@@ -327,31 +327,6 @@
         return self.vreg[__registry].render(__vid, self.req, __fallback_oid,
                                             rset=rset, **kwargs)
 
-    # url generation methods ##################################################
-
-    controller = 'view'
-
-    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:
-            method = self.controller
-            if method == 'view' and self.req.from_controller() == 'view' and \
-                   not '_restpath' in kwargs:
-                method = self.req.relative_path(includeparams=False) or 'view'
-        return self.req.build_url(method, **kwargs)
-
     # deprecated ###############################################################
 
     @classproperty
@@ -382,6 +357,10 @@
     def get_cache(self, cachename):
         return self.req.get_cache(cachename)
 
+    @deprecated('[3.5] use req.build_url')
+    def build_url(self, *args, **kwargs):
+        return self.req.build_url(*args, **kwargs)
+
     @deprecated('[3.5] use rset.limited_rql')
     def limited_rql(self):
         return self.rset.limited_rql()
--- a/req.py	Thu Aug 13 09:49:21 2009 +0200
+++ b/req.py	Thu Aug 13 09:59:35 2009 +0200
@@ -132,8 +132,18 @@
         """
         # 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]
+        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:
+            if self.from_controller() == 'view' and not '_restpath' in kwargs:
+                method = self.relative_path(includeparams=False) or 'view'
+            else:
+                method = 'view'
         base_url = kwargs.pop('base_url', None)
         if base_url is None:
             base_url = self.base_url()
--- a/web/form.py	Thu Aug 13 09:49:21 2009 +0200
+++ b/web/form.py	Thu Aug 13 09:59:35 2009 +0200
@@ -16,7 +16,6 @@
 class FormViewMixIn(object):
     """abstract form view mix-in"""
     category = 'form'
-    controller = 'edit'
     http_cache_manager = httpcache.NoHTTPCacheManager
     add_to_breadcrumbs = False
 
@@ -79,7 +78,6 @@
 
     domid = 'entityForm'
     category = 'form'
-    controller = 'edit'
     http_cache_manager = httpcache.NoHTTPCacheManager
     add_to_breadcrumbs = False
 
--- a/web/views/embedding.py	Thu Aug 13 09:49:21 2009 +0200
+++ b/web/views/embedding.py	Thu Aug 13 09:59:35 2009 +0200
@@ -98,14 +98,13 @@
                   & score_entity(entity_has_embedable_url))
 
     title = _('embed')
-    controller = 'embed'
 
     def url(self, row=0):
         entity = self.rset.get_entity(row, 0)
         url = urljoin(self.req.base_url(), entity.embeded_url())
         if self.req.form.has_key('rql'):
-            return self.build_url(url=url, rql=self.req.form['rql'])
-        return self.build_url(url=url)
+            return self.build_url('embed', url=url, rql=self.req.form['rql'])
+        return self.build_url('embed', url=url)