Skip to content

Commit

Permalink
Merge pull request #12 from GSA/bugfix/tag-validation-datagov
Browse files Browse the repository at this point in the history
Update package schema for tags
  • Loading branch information
nickumia-reisys authored Oct 6, 2021
2 parents 36981c3 + 964c652 commit 9354d52
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ckanext/spatial/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import ckantoolkit as tk

from ckan import plugins as p
from ckan import logic

from ckan.lib.helpers import json
from ckan.lib.navl.validators import not_empty

if tk.check_ckan_version(min_version="2.9.0"):
from ckanext.spatial.plugin.flask_plugin import (
Expand Down Expand Up @@ -72,12 +74,41 @@ def prettify(field_name):
summary[tk._(prettify(key))] = error[0]
return summary

class SpatialMetadata(p.SingletonPlugin):

class SpatialMetadata(p.SingletonPlugin, tk.DefaultDatasetForm):

p.implements(p.IPackageController, inherit=True)
p.implements(p.IConfigurable, inherit=True)
p.implements(p.IConfigurer, inherit=True)
p.implements(p.ITemplateHelpers, inherit=True)
p.implements(p.IDatasetForm, inherit=True)

# Need to modify the schema to match import
# function that customizes tag validation
def create_package_schema(self):
# let's grab the default schema from CKAN
schema = logic.schema.default_create_package_schema()
schema['tags'].update({
'name': [not_empty, six.text_type]
})
return schema

def update_package_schema(self):
# let's grab the default schema from CKAN
schema = logic.schema.default_update_package_schema()
schema['tags'].update({
'name': [not_empty, six.text_type]
})
log.error('Trying to update package schema %s' % schema['tags'])
return schema

def is_fallback(self):
return True

def package_types(self):
# This plugin doesn't handle any special package types, it just
# customizes tag validation (see above)
return []

def configure(self, config):
from ckanext.spatial.model.package_extent import setup as setup_model
Expand Down

0 comments on commit 9354d52

Please sign in to comment.