Skip to content
Snippets Groups Projects
Commit 742f4237 authored by anonymous's avatar anonymous
Browse files

munges title to name for every created dataset

parent 1e2b4c77
Branches
Tags
No related merge requests found
import logging
from ckan.logic.action.create import package_create
import ckan.model as model
log = logging.getLogger(__name__)
def odsh_package_create(context, data_dict):
log.debug('in ODSH package_create')
munge_increment_name(data_dict)
return package_create(context, data_dict)
def munge_increment_name(data_dict):
log.debug('IN MUNGE')
from ckan.lib.munge import munge_title_to_name
name_base = name = munge_title_to_name(data_dict['title'])
pkg = model.Package.get(name)
i = 0
while pkg:
i += 1
name = name_base + str(i)
pkg = model.Package.get(name)
log.debug('name: %s' % name)
data_dict['name'] = name
...@@ -11,6 +11,7 @@ import ckan.model as model ...@@ -11,6 +11,7 @@ import ckan.model as model
from ckanext.odsh.lib.uploader import ODSHResourceUpload from ckanext.odsh.lib.uploader import ODSHResourceUpload
import ckan.lib.helpers as helpers import ckan.lib.helpers as helpers
import helpers as odsh_helpers import helpers as odsh_helpers
import ckanext.odsh.logic.action as action
from itertools import count from itertools import count
from routes.mapper import SubMapper from routes.mapper import SubMapper
...@@ -298,6 +299,12 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -298,6 +299,12 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
plugins.implements(plugins.IDatasetForm) plugins.implements(plugins.IDatasetForm)
plugins.implements(plugins.IValidators) plugins.implements(plugins.IValidators)
plugins.implements(plugins.IPackageController, inherit=True) plugins.implements(plugins.IPackageController, inherit=True)
plugins.implements(plugins.IActions)
# IActions
def get_actions(self):
return {'package_create': action.odsh_package_create}
# IConfigurer # IConfigurer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment