[PATCH 2 of 2 saem] Backport fix for cubicweb #17074195

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Apr 21 16:11:54 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1492779366 -7200
#      Fri Apr 21 14:56:06 2017 +0200
# Node ID 5da2a03b4feedde9319f2e156baeab34ceeb7934
# Parent  cabb03fa400a48fee1228860e65c1b9da2ab6d30
# Available At http://hg.logilab.org/review/cubes/saem_ref
#              hg pull http://hg.logilab.org/review/cubes/saem_ref -r 5da2a03b4fee
Backport fix for cubicweb #17074195

to avoid vanishing of the '+' button to add some entity after facets filtering.

Closes extranet #18229045

diff --git a/cubicweb_saem_ref/site_cubicweb.py b/cubicweb_saem_ref/site_cubicweb.py
--- a/cubicweb_saem_ref/site_cubicweb.py
+++ b/cubicweb_saem_ref/site_cubicweb.py
@@ -216,5 +216,93 @@ def is_hook_category_activated(self, cat
     if self._hooks_mode is session.HOOKS_DENY_ALL:
         return category in self._hooks_categories
     return category not in self._hooks_categories
 
 
+# avoid disappearance of navtop components (https://www.cubicweb.org/17074195)
+
+from logilab.mtconverter import xml_escape  # noqa
+from cubicweb.uilib import js  # noqa
+from cubicweb.utils import UStringIO, json_dumps, js_href  # noqa
+from cubicweb.web import component  # noqa
+from cubicweb.web.views import ajaxcontroller, basetemplates, facets  # noqa
+
+
+ at monkeypatch(facets.FilterBox)
+def _get_context(self):
+    view = self.cw_extra_kwargs.get('view')
+    context = getattr(view, 'filter_box_context_info', lambda: None)()
+    if context:
+        rset, vid, divid, paginate = context
+    else:
+        rset = self.cw_rset
+        vid, divid = None, 'contentmain'
+        paginate = view and view.paginable
+    return rset, vid, divid, paginate
+
+
+ at monkeypatch(component.NavigationComponent)
+def ajax_page_url(self, **params):
+    divid = params.setdefault('divid', 'contentmain')
+    params['rql'] = self.cw_rset.printable_rql()
+    return js_href("$(%s).loadxhtml(AJAX_PREFIX_URL, %s, 'get', 'swap')" % (
+        json_dumps('#' + divid), component.js.ajaxFuncArgs('view', params)))
+
+
+ at monkeypatch(basetemplates.TheMainTemplate)
+def content_column(self, view, content_cols):
+    w = self.w
+    w(u'<div id="main-center" class="%(prefix)s%(col)s" role="main">' % {
+        'prefix': self.twbs_col_cls, 'col': content_cols})
+    components = self._cw.vreg['components']
+    self.content_components(view, components)
+    w(u'<div id="pageContent">')
+    self.content_header(view)
+    vtitle = self._cw.form.get('vtitle')
+    if vtitle:
+        w(u'<div class="vtitle">%s</div>\n' % xml_escape(vtitle))
+    self.state_header()
+    self.content_navrestriction_components(view, components)
+    w(u'<div id="contentmain">\n')
+    nav_html = UStringIO()
+    if view and not view.handle_pagination:
+        view.paginate(w=nav_html.write)
+    w(nav_html.getvalue())
+    view.render(w=w)
+    w(nav_html.getvalue())
+    w(u'</div>\n')  # closes id=contentmain
+    self.content_footer(view)
+    w(u'</div>\n')  # closes div#pageContent
+    w(u'</div>\n')  # closes div.%(prefix)s-%(col)s
+
+
+ at monkeypatch(ajaxcontroller.AjaxFunction)
+def _call_view(self, view, paginate=False, **kwargs):
+    divid = self._cw.form.get('divid')
+    # we need to call pagination before with the stream set
+    try:
+        stream = view.set_stream()
+    except AttributeError:
+        stream = UStringIO()
+        kwargs['w'] = stream.write
+        assert not paginate
+    if divid == 'contentmain':
+        # ensure divid isn't reused by the view (e.g. table view)
+        del self._cw.form['divid']
+        # mimick main template behaviour
+        paginate = True
+    if divid == 'contentmain':
+        stream.write(u'<div id="contentmain">')
+    nav_html = UStringIO()
+    if paginate and not view.handle_pagination:
+        view.paginate(w=nav_html.write)
+    stream.write(nav_html.getvalue())
+    view.render(**kwargs)
+    stream.write(nav_html.getvalue())
+    if divid == 'contentmain':
+        stream.write(u'</div>')
+    extresources = self._cw.html_headers.getvalue(skiphead=True)
+    if extresources:
+        stream.write(u'<div class="ajaxHtmlHead">\n')
+        stream.write(extresources)
+        stream.write(u'</div>\n')
+    return stream.getvalue()


More information about the saem-devel mailing list