[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
--- 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' <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' <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):