# HG changeset patch # User Sylvain Thénault # Date 1280477232 -7200 # Node ID 9ae260b2d1c44b4e15a70c5f6427634c1a780114 # Parent 6e84db1b3e44dbc42df4979d3249009ee66c07d8 [facet] refactor bookmark this search link creation: check perm before calling the method, and use the new create url factory diff -r 6e84db1b3e44 -r 9ae260b2d1c4 web/views/facets.py --- a/web/views/facets.py Fri Jul 30 10:02:31 2010 +0200 +++ b/web/views/facets.py Fri Jul 30 10:07:12 2010 +0200 @@ -97,9 +97,9 @@ return if vid is None: vid = req.form.get('vid') - if self.bk_linkbox_template: - self.display_bookmark_link(rset) w = self.w + if self.bk_linkbox_template and req.vreg.schema['Bookmark'].has_perm(req, 'add'): + w(self.bookmark_link(rset)) w(u'
' % ( divid, xml_escape(json_dumps([divid, vid, paginate, self.facetargs()])))) w(u'
') @@ -113,22 +113,22 @@ wdg.render(w=self.w) w(u'
\n
\n') - def display_bookmark_link(self, rset): - eschema = self._cw.vreg.schema.eschema('Bookmark') - if eschema.has_perm(self._cw, 'add'): - bk_path = 'rql=%s' % self._cw.url_quote(rset.printable_rql()) - if self._cw.form.get('vid'): - bk_path += '&vid=%s' % self._cw.url_quote(self._cw.form['vid']) - bk_path = 'view?' + bk_path - bk_title = self._cw._('my custom search') - linkto = 'bookmarked_by:%s:subject' % self._cw.user.eid - bk_add_url = self._cw.build_url('add/Bookmark', path=bk_path, title=bk_title, __linkto=linkto) - bk_base_url = self._cw.build_url('add/Bookmark', title=bk_title, __linkto=linkto) - bk_link = u'%s' % ( - xml_escape(bk_base_url), - xml_escape(bk_add_url), - self._cw._('bookmark this search')) - self.w(self.bk_linkbox_template % bk_link) + def bookmark_link(self, rset): + req = self._cw + bk_path = u'rql=%s' % req.url_quote(rset.printable_rql()) + if req.form.get('vid'): + bk_path += u'&vid=%s' % req.url_quote(req.form['vid']) + bk_path = u'view?' + bk_path + bk_title = req._('my custom search') + linkto = u'bookmarked_by:%s:subject' % req.user.eid + bkcls = req.vreg['etypes'].etype_class('Bookmark') + bk_add_url = bkcls.cw_create_url(req, path=bk_path, title=bk_title, + __linkto=linkto) + bk_base_url = bkcls.cw_create_url(req, title=bk_title, __linkto=linkto) + bk_link = u'%s' % ( + xml_escape(bk_base_url), xml_escape(bk_add_url), + req._('bookmark this search')) + return self.bk_linkbox_template % bk_link def get_facets(self, rset, rqlst, mainvar): return self._cw.vreg['facets'].poss_visible_objects(