diff --git a/ckanext/csvwmapandtransform/action.py b/ckanext/csvwmapandtransform/action.py index 0eec949..f51e3b5 100644 --- a/ckanext/csvwmapandtransform/action.py +++ b/ckanext/csvwmapandtransform/action.py @@ -338,17 +338,6 @@ def csvwmapandtransform_hook(context, data_dict): context, {"id": resource_dict["package_id"]} ) - # for plugin in p.PluginImplementations(xloader_interfaces.IXloader): - # plugin.after_upload(context, resource_dict, dataset_dict) - - # toolkit.get_action('resource_create_default_resource_views')( - # context, - # { - # 'resource': resource_dict, - # 'package': dataset_dict, - # 'create_datastore_views': True, - # }) - # Check if the uploaded file has been modified in the meantime if resource_dict.get("last_modified") and metadata.get("task_created"): try: diff --git a/ckanext/csvwmapandtransform/plugin.py b/ckanext/csvwmapandtransform/plugin.py index abd6888..5c62a10 100644 --- a/ckanext/csvwmapandtransform/plugin.py +++ b/ckanext/csvwmapandtransform/plugin.py @@ -11,20 +11,19 @@ log = __import__("logging").getLogger(__name__) -DEFAULT_FORMATS = os.environ.get("CSVWMAPANDTRANSFORM_FORMATS","").lower().split() +DEFAULT_FORMATS = os.environ.get("CSVWMAPANDTRANSFORM_FORMATS", "").lower().split() if not DEFAULT_FORMATS: DEFAULT_FORMATS = [ "json", "turtle", - "text/turtle" - "n3", + "text/turtle" "n3", "nt", "hext", "trig", "longturtle", "xml", "json-ld", - "ld+json" + "ld+json", ] @@ -37,7 +36,6 @@ class CsvwMapAndTransformPlugin(plugins.SingletonPlugin, DefaultTranslation): plugins.implements(plugins.IActions) plugins.implements(plugins.IAuthFunctions) plugins.implements(plugins.IBlueprint) - # IConfigurer @@ -49,60 +47,64 @@ def update_config(self, config_): # IResourceUrlChange def notify(self, resource: model.Resource): - context: Context = {'ignore_auth': True} - resource_dict = toolkit.get_action(u'resource_show')( - context, { - u'id': resource.id, - } + context: Context = {"ignore_auth": True} + resource_dict = toolkit.get_action("resource_show")( + context, + { + "id": resource.id, + }, ) self._sumbit_transform(resource_dict) # IResourceController - def after_resource_create( - self, context: Context, resource_dict: dict[str, Any]): + if not toolkit.check_ckan_version("2.10"): - self._sumbit_transform(resource_dict) + def after_create(self, context, resource_dict): + self.after_resource_create(context, resource_dict) + + # def before_show(self, resource_dict): + # self.before_resource_show(resource_dict) - def after_update( - self, context: Context, resource_dict: dict[str, Any]): + def after_update(self, context: Context, resource_dict: dict[str, Any]): + self._sumbit_transform(resource_dict) + def after_resource_create(self, context: Context, resource_dict: dict[str, Any]): self._sumbit_transform(resource_dict) - def _sumbit_transform(self, resource_dict: dict[str, Any]): - context = { - u'model': model, - u'ignore_auth': True, - u'defer_commit': True - } - format=resource_dict.get('format',None) + context = {"model": model, "ignore_auth": True, "defer_commit": True} + format = resource_dict.get("format", None) submit = ( format - and format.lower() in DEFAULT_FORMATS and "-joined" not in resource_dict['url'] + and format.lower() in DEFAULT_FORMATS + and "-joined" not in resource_dict["url"] ) log.debug( - u'Submitting resource {0} with format {1}'.format(resource_dict['id'],format) + - u' to csvwmapandtransform_transform' + "Submitting resource {0} with format {1}".format( + resource_dict["id"], format ) - + + " to csvwmapandtransform_transform" + ) + if not submit: return - + try: log.debug( - u'Submitting resource {0}'.format(resource_dict['id']) + - u' to csvwmapandtransform_transform' + "Submitting resource {0}".format(resource_dict["id"]) + + " to csvwmapandtransform_transform" ) - toolkit.get_action('csvwmapandtransform_transform')(context,{'id': resource_dict['id']}) - + toolkit.get_action("csvwmapandtransform_transform")( + context, {"id": resource_dict["id"]} + ) + except toolkit.ValidationError as e: # If RDFConverter is offline want to catch error instead # of raising otherwise resource save will fail with 500 log.critical(e) pass - # ITemplateHelpers def get_helpers(self): @@ -113,7 +115,7 @@ def get_helpers(self): def get_actions(self): actions = action.get_actions() return actions - + # IBlueprint def get_blueprint(self): @@ -123,4 +125,3 @@ def get_blueprint(self): def get_auth_functions(self): return auth.get_auth_functions() -