Commit 72fd97ca authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[views] Add actions to trigger synchronization to CKAN instance on entity

Closes #4869952.
parent 5ab8c18d8056
......@@ -20,3 +20,12 @@ msgstr "Link to CKAN dataset"
# (no object form for final or symmetric relation types)
msgid "ctxcomponents_ckanpublish.goto-ckan-dataset_description"
msgstr ""
msgid "synchronization to CKAN failed: "
msgstr ""
msgid "synchronization to CKAN successfully completed"
msgstr ""
msgid "synchronize to CKAN"
msgstr ""
......@@ -20,3 +20,12 @@ msgstr "Lien vers le jeu de données CKAN"
# (no object form for final or symmetric relation types)
msgid "ctxcomponents_ckanpublish.goto-ckan-dataset_description"
msgstr ""
msgid "synchronization to CKAN failed: "
msgstr "échec de la synchronisation vers CKAN : "
msgid "synchronization to CKAN successfully completed"
msgstr "synchronisation vers CKAN réussie"
msgid "synchronize to CKAN"
msgstr "synchroniser vers CKAN"
......@@ -18,10 +18,13 @@
from logilab.mtconverter import xml_escape
from cubicweb.predicates import score_entity
from cubicweb.web import component
from cubicweb.predicates import score_entity, adaptable
from cubicweb.web import component, action, Redirect
from cubicweb.view import EntityView
from cubes.ckanpublish.utils import ckan_post, ckan_buildurl
from cubes.ckanpublish.sobjects import CKANSyncError
from cubes.ckanpublish.utils import (ckan_post, ckan_buildurl,
ckan_instance_configured, CKANPostError)
_ = unicode
......@@ -56,3 +59,67 @@ class GotoCKANDatasetComponent(component.EntityCtxComponent):
url = ckan_buildurl(self._cw.vreg.config,
'dataset/' + xml_escape(r['name']))
w(u'<a target=_blank href="%s">%s</a>' % (url, xml_escape(url)))
class SyncDatasetToCKANMixin(object):
"""Mixin for dataset-like entity synchronization to CKAN instance."""
__regid__ = 'ckanpublish.sync_dataset_to_ckan'
__select__ = adaptable('ICKANDataset') & ckan_instance_configured()
class SyncDatasetToCKANAction(SyncDatasetToCKANMixin, action.Action):
"""Trigger synchronization of a dataset-like entity to the CKAN instance.
"""
title = _('synchronize to CKAN')
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__)
class SyncDatasetToCKANView(SyncDatasetToCKANMixin, EntityView):
"""Handle synchronization of a dataset-like entity to the CKAN instance.
"""
def entity_call(self, entity):
try:
self._cw.call_service('ckanpublish.sync_dataset', eid=entity.eid)
except (CKANSyncError, CKANPostError) as exc:
msg = self._cw._('synchronization to CKAN failed: ' + str(exc))
else:
msg = self._cw._('synchronization to CKAN successfully completed')
raise Redirect(entity.absolute_url(__message=msg))
class SyncResourceToCKANMixin(object):
"""Mixin for dataset resource-like entity synchronization to CKAN
instance.
"""
__regid__ = 'ckanpublish.sync_dataset_resource_to_ckan'
__select__ = adaptable('ICKANResource') & ckan_instance_configured()
class SyncResourceToCKANAction(SyncResourceToCKANMixin, action.Action):
"""Trigger synchronization of a dataset resource-like entity to the CKAN
instance.
"""
title = _('synchronize to CKAN')
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__)
class SyncResourceToCKANView(SyncResourceToCKANMixin, EntityView):
"""Handle synchronization of dataset resource-like entity to the CKAN
instance.
"""
def entity_call(self, entity):
try:
self._cw.call_service('ckanpublish.sync_resource', eid=entity.eid)
except (CKANSyncError, CKANPostError) as exc:
msg = self._cw._('synchronization to CKAN failed: ' + str(exc))
else:
msg = self._cw._('synchronization to CKAN successfully completed')
raise Redirect(entity.absolute_url(__message=msg))
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