Skip to content

Commit

Permalink
some ckan version dependend changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hanke committed Feb 29, 2024
1 parent 4528460 commit 7b5886c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 45 deletions.
11 changes: 0 additions & 11 deletions ckanext/csvwmapandtransform/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
69 changes: 35 additions & 34 deletions ckanext/csvwmapandtransform/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]


Expand All @@ -37,7 +36,6 @@ class CsvwMapAndTransformPlugin(plugins.SingletonPlugin, DefaultTranslation):
plugins.implements(plugins.IActions)
plugins.implements(plugins.IAuthFunctions)
plugins.implements(plugins.IBlueprint)


# IConfigurer

Expand All @@ -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):
Expand All @@ -113,7 +115,7 @@ def get_helpers(self):
def get_actions(self):
actions = action.get_actions()
return actions

# IBlueprint

def get_blueprint(self):
Expand All @@ -123,4 +125,3 @@ def get_blueprint(self):

def get_auth_functions(self):
return auth.get_auth_functions()

0 comments on commit 7b5886c

Please sign in to comment.