[view] deprecate create_url in favor of a cw_create_url class method on entity classes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 30 Jul 2010 10:02:31 +0200
changeset 6039 6e84db1b3e44
parent 6033 09db6f4619c9
child 6040 9ae260b2d1c4
[view] deprecate create_url in favor of a cw_create_url class method on entity classes also kill view's output_url_builder method, unused anywhere...
entities/__init__.py
view.py
web/views/bookmark.py
web/views/editforms.py
--- a/entities/__init__.py	Wed Jul 28 16:31:32 2010 +0200
+++ b/entities/__init__.py	Fri Jul 30 10:02:31 2010 +0200
@@ -35,6 +35,11 @@
     __regid__ = 'Any'
     __implements__ = ()
 
+    @classmethod
+    def cw_create_url(cls, req, **kwargs):
+        """ return the url of the entity creation form for this entity type"""
+        return req.build_url('add/%s' % cls.__regid__, **kwargs)
+
     # meta data api ###########################################################
 
     def dc_title(self):
--- a/view.py	Wed Jul 28 16:31:32 2010 +0200
+++ b/view.py	Fri Jul 30 10:02:31 2010 +0200
@@ -319,21 +319,11 @@
             clabel = vtitle
         return u'%s (%s)' % (clabel, self._cw.property_value('ui.site-title'))
 
-    def output_url_builder( self, name, url, args ):
-        self.w(u'<script language="JavaScript"><!--\n' \
-               u'function %s( %s ) {\n' % (name, ','.join(args) ) )
-        url_parts = url.split("%s")
-        self.w(u' url="%s"' % url_parts[0] )
-        for arg, part in zip(args, url_parts[1:]):
-            self.w(u'+str(%s)' % arg )
-            if part:
-                self.w(u'+"%s"' % part)
-        self.w('\n document.window.href=url;\n')
-        self.w('}\n-->\n</script>\n')
-
+    @deprecated('[3.10] use vreg["etypes"].etype_class(etype).cw_create_url(req)')
     def create_url(self, etype, **kwargs):
         """ return the url of the entity creation form for a given entity type"""
-        return self._cw.build_url('add/%s' % etype, **kwargs)
+        return self._cw.vreg["etypes"].etype_class(etype).cw_create_url(
+            self._cw, **kwargs)
 
     def field(self, label, value, row=True, show_label=True, w=None, tr=True, table=False):
         """read-only field"""
--- a/web/views/bookmark.py	Wed Jul 28 16:31:32 2010 +0200
+++ b/web/views/bookmark.py	Fri Jul 30 10:02:31 2010 +0200
@@ -115,7 +115,8 @@
             path = req.relative_path()
             # XXX if vtitle specified in params, extract it and use it as default value
             # for bookmark's title
-            url = self.create_url(self.etype, __linkto=linkto, path=path)
+            url = req.vreg['etypes'].etype_class('Bookmark').cw_create_url(
+                req, __linkto=linkto, path=path)
             boxmenu.append(self.mk_action(req._('bookmark this page'), url,
                                           category='manage', id='bookmark'))
             if rset:
--- a/web/views/editforms.py	Wed Jul 28 16:31:32 2010 +0200
+++ b/web/views/editforms.py	Fri Jul 30 10:02:31 2010 +0200
@@ -169,7 +169,9 @@
 
     def url(self):
         """return the url associated with this view"""
-        return self.create_url(self._cw.form.get('etype'))
+        req = self._cw
+        return req.vreg["etypes"].etype_class(req.form['etype']).cw_create_url(
+            req)
 
     def submited_message(self):
         """return the message that will be displayed on successful edition"""