[PATCH 04 of 14 skos] Get rid of views monkeypatches for cubicweb < 3.23

Denis Laxalde denis.laxalde at logilab.fr
Mon Feb 19 12:27:55 CET 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1519029671 -3600
#      Mon Feb 19 09:41:11 2018 +0100
# Node ID 122c25215752cd97767500b65d48524e9d62826b
# Parent  a9ce01e708389b58922425baf6a56d0c074e2b82
Get rid of views monkeypatches for cubicweb < 3.23

Related to #17133718.

diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -19,10 +19,6 @@ import sys
 
 from six import text_type, binary_type
 
-import cubicweb
-
-CW_VERSION = tuple(map(int, cubicweb.__version__.split('.')[:2]))
-
 
 def register_skos_concept_rdf_list_mapping(reg):
     """Register minimal SKOS mapping at the concept level (for use in
diff --git a/views/__init__.py b/views/__init__.py
--- a/views/__init__.py
+++ b/views/__init__.py
@@ -16,7 +16,6 @@
 """cubicweb-skos views"""
 
 from copy import copy
-from functools import partial
 
 from logilab.common.decorators import cachedproperty
 from rql.utils import uquote
@@ -34,7 +33,7 @@ from cubicweb.web import (action, compon
 from cubicweb.web.views import (actions, autoform, editcontroller, formrenderers, uicfg,
                                 ibreadcrumbs, forms, tabs, cwsources, treeview, baseviews)
 
-from cubes.skos import CW_VERSION, to_unicode, lcsv
+from cubes.skos import to_unicode, lcsv
 from cubes.skos.entities import CSVIndentationError, CSVDecodeError
 
 
@@ -566,77 +565,3 @@ class SKOSSourceFormRenderer(formrendere
             'Please specify <b>an arbitrary short name</b> for the data source and '
             '<b>one or more URL from which RDF data may be retrieved</b>.')))
         super(SKOSSourceFormRenderer, self).render(w, form, values)
-
-
-# https://www.cubicweb.org/ticket/5474286 ##########################################################
-
-if CW_VERSION < (3, 22):
-
-    class CWSourceSyncAction(action.Action):
-        __regid__ = 'cw.source-sync'
-        __select__ = (action.Action.__select__ & match_user_groups('managers')
-                      & one_line_rset() & is_instance('CWSource')
-                      & score_entity(lambda x: x.name != 'system'))
-        title = _('synchronize')
-        category = 'mainactions'
-        order = 20
-
-        def url(self):
-            entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
-            return entity.absolute_url(vid=self.__regid__)
-
-if CW_VERSION < (3, 23):
-    # asynchronous source synchronization from the UI (https://www.cubicweb.org/ticket/10468967) ###
-
-    from cubicweb.server import Service  # noqa
-
-    class SourceSynchronizationService(Service):
-        """Force synchronization of a datafeed source. Actual synchronization is done
-        asynchronously, this will simply create and return the entity which will hold the import
-        log.
-        """
-        __regid__ = 'source-sync'
-        __select__ = Service.__select__ & match_user_groups('managers')
-
-        def call(self, source_eid):
-            source = self._cw.entity_from_eid(source_eid)
-            import_log = self._cw.create_entity('CWDataImport', cw_import_of=source)
-            self._cw.commit()  # commit the import log creation before starting the synchronize task
-
-            def _synchronize_source(repo, source_eid, import_log_eid):
-                with repo.internal_cnx() as cnx:
-                    source = repo.sources_by_eid[source_eid]
-                    source.pull_data(cnx, force=True, import_log_eid=import_log_eid)
-
-            sync = partial(_synchronize_source, self._cw.repo, source_eid, import_log.eid)
-            self._cw.repo.threaded_task(sync)
-            return import_log.eid
-
-    class CWSourceSyncView(EntityView):
-        __regid__ = 'cw.source-sync'
-        __select__ = (match_user_groups('managers')
-                      & one_line_rset() & is_instance('CWSource')
-                      & score_entity(lambda x: x.name != 'system'))
-
-        title = _('synchronize')
-
-        def entity_call(self, entity):
-            import_log_eid = self._cw.call_service('source-sync', source_eid=entity.eid)
-            msg = self._cw._('Synchronization has been requested, refresh this page in a few '
-                             'minutes.')
-            import_log = self._cw.entity_from_eid(import_log_eid)
-            url = import_log.absolute_url(__message=msg)
-            raise Redirect(url)
-
-
-def registration_callback(vreg):
-    if CW_VERSION == (3, 22):
-        from cubicweb.sobjects import services
-        vreg.register_all(globals().values(), __name__,
-                          (CWSourceSyncView, SourceSynchronizationService))
-        vreg.register_and_replace(CWSourceSyncView,
-                                  cwsources.CWSourceSyncView)
-        vreg.register_and_replace(SourceSynchronizationService,
-                                  services.SourceSynchronizationService)
-    else:
-        vreg.register_all(globals().values(), __name__)



More information about the saem-devel mailing list