Commit bdd92d63 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Get rid of views monkeypatches for cubicweb < 3.23

Related to #17133718.
parent a9ce01e70838
......@@ -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
......
......@@ -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, component, formfields as ff, formwidgets as fw
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(formrenderers.FormRenderer):
'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__)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment