Skip to content

Commit

Permalink
Merge pull request #316 from opendata-swiss/feat/develop_i14y_harvester
Browse files Browse the repository at this point in the history
Use actions from ckan.plugins.toolkit instead of ckan.logic
  • Loading branch information
kovalch authored Jul 5, 2024
2 parents 0681884 + 9a885ce commit 49e700f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
9 changes: 4 additions & 5 deletions ckanext/switzerland/helpers/backend_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from ckan.lib.helpers import organization_link as organization_link_orig

import ckan.lib.i18n as i18n
import ckan.logic as logic
import ckan.plugins.toolkit as tk
import ckanext.switzerland.helpers.localize_utils as ogdch_localize_utils
from ckanext.switzerland.helpers.frontend_helpers import get_localized_value_for_display # noqa
Expand Down Expand Up @@ -194,16 +193,16 @@ def ogdch_resource_display_name(res):
resource_display_name = get_localized_value_for_display(res.get('name'))
if not resource_display_name:
try:
pkg = logic.get_action('package_show')(
pkg = tk.get_action('package_show')(
{}, {'id': res['package_id']}
)
resource_display_name = get_localized_value_for_display(
pkg.get('title')
)
if not resource_display_name:
return pkg['name']
except (logic.NotFound, logic.ValidationError,
logic.NotAuthorized, AttributeError):
except (tk.ObjectNotFound, tk.ValidationError,
tk.NotAuthorized, AttributeError):
return ""
return resource_display_name

Expand Down Expand Up @@ -284,7 +283,7 @@ def ogdch_get_top_level_organisations():
def ogdch_user_datasets():
context = {u'for_view': True, u'user': g.user, u'auth_user_obj': g.userobj}
data_dict = {u'user_obj': g.userobj, u'include_datasets': True}
user_dict = logic.get_action(u'user_show')(context, data_dict)
user_dict = tk.get_action(u'user_show')(context, data_dict)

return user_dict['datasets']

Expand Down
11 changes: 5 additions & 6 deletions ckanext/switzerland/helpers/frontend_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from collections import OrderedDict

import ckan.lib.i18n as i18n
import ckan.logic as logic
import ckan.plugins.toolkit as tk
from babel import numbers
from ckan.common import _
Expand Down Expand Up @@ -43,12 +42,12 @@ def get_localized_org(org_id=None, include_datasets=False):
if not org_id or org_id is None:
return {}
try:
return logic.get_action('organization_show')(
return tk.get_action('organization_show')(
{'for_view': True},
{'id': org_id, 'include_datasets': include_datasets}
)
except (logic.NotFound, logic.ValidationError,
logic.NotAuthorized, AttributeError):
except (tk.ObjectNotFound, tk.ValidationError,
tk.NotAuthorized, AttributeError):
return {}


Expand Down Expand Up @@ -148,11 +147,11 @@ def get_political_level(political_level):

def get_dataset_by_identifier(identifier):
try:
return logic.get_action('ogdch_dataset_by_identifier')(
return tk.get_action('ogdch_dataset_by_identifier')(
{'for_view': True},
{'identifier': identifier}
)
except logic.NotFound:
except tk.ObjectNotFound:
return None


Expand Down
3 changes: 1 addition & 2 deletions ckanext/switzerland/helpers/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import re

import ckan.plugins.toolkit as tk
from ckan import logic
from ckan.lib.munge import munge_title_to_name

import ckanext.switzerland.helpers.date_helpers as ogdch_date_utils
Expand Down Expand Up @@ -229,7 +228,7 @@ def ogdch_prepare_pkg_dict_for_api(pkg_dict):
# load organization from API to get all fields defined in schema
# by default, CKAN loads organizations only from the database
if pkg_dict['owner_org'] is not None:
pkg_dict['organization'] = logic.get_action('organization_show')(
pkg_dict['organization'] = tk.get_action('organization_show')(
{},
{
'id': pkg_dict['owner_org'],
Expand Down
18 changes: 8 additions & 10 deletions ckanext/switzerland/helpers/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import ckan.lib.navl.dictization_functions as df
import ckan.plugins.toolkit as tk
from ckan.lib.munge import munge_tag
from ckan.logic import NotFound, get_action
from ckan.plugins.toolkit import _, missing

import ckanext.switzerland.helpers.date_helpers as ogdch_date_helpers
Expand Down Expand Up @@ -253,7 +252,7 @@ def validator(key, data, errors, context):
)
identifier_org_slug = identifier_parts[1]
try:
dataset_organization = get_action('organization_show')(
dataset_organization = tk.get_action('organization_show')(
{},
{'id': dataset_owner_org}
)
Expand All @@ -263,21 +262,20 @@ def validator(key, data, errors, context):
'The identifier "{}" does not end with the organisation slug "{}" of the organization it belongs to.' # noqa
.format(identifier, dataset_organization['name'])) # noqa
)
except NotFound:
except tk.ObjectNotFound:
raise df.Invalid(
_('The selected organization was not found.') # noqa
)

try:
dataset_for_identifier = get_action('ogdch_dataset_by_identifier')(
{},
{'identifier': identifier}
)
dataset_for_identifier = \
tk.get_action('ogdch_dataset_by_identifier')(
{}, {'identifier': identifier})
if dataset_id != dataset_for_identifier['id']:
raise df.Invalid(
_('Identifier is already in use, it must be unique.')
)
except NotFound:
except tk.ObjectNotFound:
pass

data[key] = identifier
Expand Down Expand Up @@ -438,10 +436,10 @@ def validator(key, data, errors, context):
context = {}
for package_name in qualified_relations_from_form:
try:
package = get_action('package_show')(
package = tk.get_action('package_show')(
context, {'id': package_name}
)
except NotFound:
except tk.ObjectNotFound:
raise df.Invalid(
_('Dataset {} could not be found .'
.format(package_name))
Expand Down
3 changes: 1 addition & 2 deletions ckanext/switzerland/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ckan.common import OrderedDict
from ckan.lib.base import render_jinja2
from ckan.lib.plugins import DefaultTranslation
from ckan.logic import NotFound
from ckan.model import PACKAGE_NAME_MAX_LENGTH, Activity, Package, Session

import ckanext.switzerland.helpers.backend_helpers as ogdch_backend_helpers
Expand Down Expand Up @@ -780,7 +779,7 @@ def get_activities(self, include_activity_from,
{'id': ogdch_validators.HARVEST_USER}
)
harvest_user_id = harvest_user['id']
except NotFound:
except tk.ObjectNotFound:
raise
activities = \
Session\
Expand Down

0 comments on commit 49e700f

Please sign in to comment.