Skip to content
Snippets Groups Projects
Commit d13590e2 authored by anonymous's avatar anonymous
Browse files
parents 27a1258b f1175ea4
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
...@@ -10,6 +10,7 @@ from ckan.common import OrderedDict ...@@ -10,6 +10,7 @@ from ckan.common import OrderedDict
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 routes.mapper import SubMapper from routes.mapper import SubMapper
from pylons import config from pylons import config
...@@ -76,6 +77,12 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -76,6 +77,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
......
...@@ -11,20 +11,6 @@ error=error_string, classes=['control-full'], attrs={'data-module': 'slug-previe ...@@ -11,20 +11,6 @@ error=error_string, classes=['control-full'], attrs={'data-module': 'slug-previe
is_required=true,placeholder=_('Enter title')) }} is_required=true,placeholder=_('Enter title')) }}
{% endblock %} {% endblock %}
{% block package_basic_fields_url %}
{% if(dataset_is_draft)%}
{% set prefix = h.url_for(controller='package', action='read', id='') %}
{% set domain = h.url_for(controller='package', action='read', id='', qualified=true) %}
{% set domain = domain|replace("http://", "")|replace("https://", "") %}
{% set attrs = {'data-module': 'slug-preview-slug', 'data-module-prefix': domain, 'data-module-placeholder': '<dataset>'}
%}
<!-- field name/url -->
{{ form.prepend('name', id='field-name', label=_('URL'), prepend=prefix,
value=data.name, error=errors.name, attrs=attrs, is_required=true) }}
{% endif %}
{% endblock %}
<!-- field notes --> <!-- field notes -->
{% block package_basic_fields_description %} {% block package_basic_fields_description %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment