[index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 30 Jul 2010 10:09:31 +0200
changeset 6041 31776723c0c5
parent 6040 9ae260b2d1c4
child 6047 ee6deb534f57
[index page] refactor add_entity_link: no need to give request, nicer to check perm before calling the method, and use the new create url factory
goa/appobjects/components.py
web/views/startup.py
--- a/goa/appobjects/components.py	Fri Jul 30 10:07:12 2010 +0200
+++ b/goa/appobjects/components.py	Fri Jul 30 10:09:31 2010 +0200
@@ -15,9 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""overrides some base views for cubicweb on google appengine
+"""overrides some base views for cubicweb on google appengine"""
 
-"""
 __docformat__ = "restructuredtext en"
 
 from logilab.mtconverter import xml_escape
@@ -88,7 +87,8 @@
         view = self.vreg.select('views', 'list', req, req.etype_rset(etype))
         url = view.url()
         etypelink = u'&#160;<a href="%s">%s</a>' % (xml_escape(url), label)
-        yield (label, etypelink, self.add_entity_link(eschema, req))
+        if eschema.has_perm(req, 'add'):
+            yield (label, etypelink, self.add_entity_link(etype))
 
 ManageView.entity_types = entity_types_no_count
 
--- a/web/views/startup.py	Fri Jul 30 10:07:12 2010 +0200
+++ b/web/views/startup.py	Fri Jul 30 10:09:31 2010 +0200
@@ -159,15 +159,14 @@
             url = self._cw.build_url(etype)
             etypelink = u'&#160;<a href="%s">%s</a> (%d)' % (
                 xml_escape(url), label, nb)
-            yield (label, etypelink, self.add_entity_link(eschema, req))
+            if eschema.has_perm(req, 'add'):
+                yield (label, etypelink, self.add_entity_link(etype))
 
-    def add_entity_link(self, eschema, req):
-        """creates a [+] link for adding an entity if user has permission to do so"""
-        if not eschema.has_perm(req, 'add'):
-            return u''
+    def add_entity_link(self, etype):
+        """creates a [+] link for adding an entity"""
+        url = self._cw.vreg["etypes"].etype_class(etype).cw_create_url(self._cw)
         return u'[<a href="%s" title="%s">+</a>]' % (
-            xml_escape(self.create_url(eschema.type)),
-            self._cw.__('add a %s' % eschema))
+            xml_escape(url), self._cw.__('add a %s' % etype))
 
 
 class IndexView(ManageView):