# HG changeset patch # User Sylvain Thénault # Date 1280477371 -7200 # Node ID 31776723c0c5a8997de4f41fd735a2837ac5b811 # Parent 9ae260b2d1c44b4e15a70c5f6427634c1a780114 [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 diff -r 9ae260b2d1c4 -r 31776723c0c5 goa/appobjects/components.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 . -"""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' %s' % (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 diff -r 9ae260b2d1c4 -r 31776723c0c5 web/views/startup.py --- 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' %s (%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'[+]' % ( - 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):