[PATCH saem_ref] [pkg] Allow cubicweb>=3.26

Denis Laxalde denis.laxalde at logilab.fr
Tue Feb 6 11:10:45 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1517819246 -3600
#      Mon Feb 05 09:27:26 2018 +0100
# Node ID a2ec2f49ecb7e7e4cfc3a0a92e04e3850e24af0b
# Parent  efb428324c9ccd7658beefa40db97ffa3fe33568
# EXP-Topic cw-upgrade
[pkg] Allow cubicweb>=3.26

We need a draft changeset from cubicweb-seda as there's also an upper
bound on cubicweb there.

We can thus drop a couple of monkeypatches now that respective
developments are in cubicweb 3.26:

* https://www.cubicweb.org/ticket/17074195
* https://www.cubicweb.org/ticket/17074119

diff --git a/cubicweb_saem_ref/__pkginfo__.py b/cubicweb_saem_ref/__pkginfo__.py
--- a/cubicweb_saem_ref/__pkginfo__.py
+++ b/cubicweb_saem_ref/__pkginfo__.py
@@ -15,7 +15,7 @@ description = "Référenciel de Système
 web = 'http://www.cubicweb.org/project/%s' % distname
 
 __depends__ = {
-    'cubicweb[pyramid]': '>= 3.25.0, < 3.26.0',
+    'cubicweb[pyramid]': '>= 3.26.0',
     'cubicweb-squareui': None,
     'cubicweb-eac': '>= 0.6.0, < 0.7.0',
     'cubicweb-seda': '>= 0.13.0, < 0.14.0',
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
@@ -182,118 +182,3 @@ def negotiated_language(self):
     # force french language with a browser configured in english.
     # This is currently the easiest way to force the language of an instance.
     return 'fr'
-
-
-####################################################################################################
-# temporary monkey-patches #########################################################################
-####################################################################################################
-
-# avoid disappearance of navtop components (https://www.cubicweb.org/17074195)
-# other part lies in views/patches.py
-
-from cubicweb.utils import json_dumps, js_href  # noqa
-from cubicweb.web import component  # noqa
-
-
- 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)))
-
-
-# Fixed rql reqwrite (https://www.cubicweb.org/ticket/17074119)
-
-from cubicweb.rqlrewrite import RQLRewriter, n, remove_solutions  # noqa
-
-
-def need_exists(node):
-    """Return true if the given node should be wrapped in an `Exists` node.
-
-    This is true when node isn't already an `Exists` or `Not` node, nor a
-    `And`/`Or` of `Exists` or `Not` nodes.
-    """
-    if isinstance(node, (n.Exists, n.Not)):
-        return False
-    if isinstance(node, (n.Or, n.And)):
-        return need_exists(node.children[0]) or need_exists(node.children[1])
-    return True
-
-
- at monkeypatch(RQLRewriter)
-def _inserted_root(self, new):
-    if need_exists(new):
-        new = n.Exists(new)
-    return new
-
-
- at monkeypatch(RQLRewriter)
-def remove_ambiguities(self, snippets, newsolutions):
-    # the snippet has introduced some ambiguities, we have to resolve them
-    # "manually"
-    variantes = self.build_variantes(newsolutions)
-    if not variantes:
-        return newsolutions
-    # insert "is" where necessary
-    varexistsmap = {}
-    self.removing_ambiguity = True
-    for (erqlexpr, varmap, oldvarname), etype in variantes[0].items():
-        varname = self.rewritten[(erqlexpr, varmap, oldvarname)]
-        var = self.select.defined_vars[varname]
-        exists = var.references()[0].scope
-        exists.add_constant_restriction(var, 'is', etype, 'etype')
-        varexistsmap[varmap] = exists
-    # insert ORED exists where necessary
-    for variante in variantes[1:]:
-        self.insert_snippets(snippets, varexistsmap)
-        for key, etype in variante.items():
-            varname = self.rewritten[key]
-            try:
-                var = self.select.defined_vars[varname]
-            except KeyError:
-                # not a newly inserted variable
-                continue
-            exists = var.references()[0].scope
-            exists.add_constant_restriction(var, 'is', etype, 'etype')
-    # recompute solutions
-    self.compute_solutions()
-    # clean solutions according to initial solutions
-    return remove_solutions(self.solutions, self.select.solutions,
-                            self.select.defined_vars)
-
-
- at monkeypatch(RQLRewriter)
-def build_variantes(self, newsolutions):
-    variantes = set()
-    for sol in newsolutions:
-        variante = []
-        for key, var_name in self.rewritten.items():
-            var = self.select.defined_vars[var_name]
-            # skip variable which are only in a NOT EXISTS (mustn't be splitted)
-            if len(var.stinfo['relations']) == 1 and isinstance(var.scope.parent, n.Not):
-                continue
-            # skip variable whose type is already explicitly specified
-            if var.stinfo['typerel']:
-                continue
-            variante.append((key, sol[var_name]))
-        if variante:
-            variantes.add(tuple(variante))
-
-    # rebuild variantes as dict
-    variantes = [dict(v) for v in variantes]
-    # remove variable which have always the same type
-    for key in self.rewritten:
-        it = iter(variantes)
-        try:
-            etype = next(it)[key]
-        except StopIteration:
-            continue
-        for variante in it:
-            if variante[key] != etype:
-                break
-        else:
-            for variante in variantes:
-                del variante[key]
-
-    return variantes
diff --git a/cubicweb_saem_ref/views/patches.py b/cubicweb_saem_ref/views/patches.py
--- a/cubicweb_saem_ref/views/patches.py
+++ b/cubicweb_saem_ref/views/patches.py
@@ -40,88 +40,6 @@ def render(self, registry, oid, eid=None
     return self._call_view(viewobj, **ajaxcontroller.optional_kwargs(renderargs))
 
 
-# avoid disappearance of navtop components (https://www.cubicweb.org/17074195) #####################
-# other part lies in site_cubicweb.py
-
-from logilab.common.decorators import monkeypatch  # noqa
-from logilab.mtconverter import xml_escape  # noqa
-from cubicweb.utils import UStringIO  # 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(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()
-
-
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (render,))
     vreg.register_and_replace(render, ajaxcontroller.render)
diff --git a/dev-requirements.txt b/dev-requirements.txt
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,3 +1,4 @@
 mock
 pytest
 webtest
+http://hg.logilab.org/review/cubes/seda/archive/e611c3939f24.tar.bz2#egg=cubicweb-seda


More information about the saem-devel mailing list