Skip to content

Commit

Permalink
Merge branch 'feature-1698-tag-taxonomies'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Mar 14, 2012
2 parents b9755e9 + 76f5530 commit 497ecb4
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 23 deletions.
41 changes: 41 additions & 0 deletions ckan/lib/create_test_data.py
Expand Up @@ -11,6 +11,8 @@ class CreateTestData(cli.CkanCommand):
create-test-data gov - government style data
create-test-data family - package relationships data
create-test-data user - create a user 'tester' with api key 'tester'
create-test-data vocabs - annakerenina, warandpeace, and some test
vocabularies
'''
summary = __doc__.split('\n')[0]
usage = __doc__
Expand Down Expand Up @@ -51,6 +53,8 @@ def command(self):
self.create_gov_test_data()
elif cmd == 'family':
self.create_family_test_data()
elif cmd == 'vocabs':
self.create_vocabs_test_data()
else:
print 'Command %s not recognized' % cmd
raise NotImplementedError
Expand Down Expand Up @@ -87,6 +91,43 @@ def create_test_user(cls):
model.Session.remove()
cls.user_refs.append(u'tester')

@classmethod
def create_vocabs_test_data(cls):
import ckan.model
CreateTestData.create()
sysadmin_user = ckan.model.User.get('testsysadmin')
annakarenina = ckan.model.Package.get('annakarenina')
warandpeace = ckan.model.Package.get('warandpeace')

# Create a couple of vocabularies.
context = {
'model': ckan.model,
'session': ckan.model.Session,
'user': sysadmin_user.name
}
data_dict = {
'name': 'Genre',
'tags': [{'name': 'Drama'}, {'name': 'Sci-Fi'},
{'name': 'Mystery'}],
}
ckan.logic.action.create.vocabulary_create(context, data_dict)

data_dict = {
'name': 'Actors',
'tags': [{'name': 'keira-knightley'}, {'name': 'jude-law'},
{'name': 'alessio-boni'}],
}
ckan.logic.action.create.vocabulary_create(context, data_dict)

# Add some vocab tags to some packages.
genre_vocab = ckan.model.Vocabulary.get('Genre')
actors_vocab = ckan.model.Vocabulary.get('Actors')
annakarenina.add_tag_by_name('Drama', vocab=genre_vocab)
annakarenina.add_tag_by_name('keira-knightley', vocab=actors_vocab)
annakarenina.add_tag_by_name('jude-law', vocab=actors_vocab)
warandpeace.add_tag_by_name('Drama', vocab=genre_vocab)
warandpeace.add_tag_by_name('alessio-boni', vocab=actors_vocab)

@classmethod
def create_arbitrary(cls, package_dicts, relationships=[],
extra_user_names=[], extra_group_names=[],
Expand Down
66 changes: 43 additions & 23 deletions doc/apiv3.rst
Expand Up @@ -63,9 +63,10 @@ group_list_authz (none)
group_list_available (none)
group_revision_list id
licence_list (none)
tag_list q, all_fields, limit, offset, return_objects
tag_list q, all_fields, limit, offset, return_objects, vocabulary_id
user_list q, order_by
package_relationships_list id, id2, rel
vocabulary_list (none)
package_show id
revision_show id
group_show id
Expand All @@ -74,12 +75,15 @@ user_show id
package_show_rest id
group_show_rest id
tag_show_rest id
vocabulary_show id
package_autocomplete q
tag_autocomplete q, limit
tag_autocomplete q, fields, offset, limit, vocabulary_id
format_autocomplete q, limit
user_autocomplete q, limit
package_search q, fields, facet_by, limit, offset
tag_search q, fields, offset, limit, vocabulary_id
roles_show domain_object, (user), (authorization_group)

====================================== ===========================

new.py:
Expand All @@ -96,6 +100,8 @@ rating_create package, rating
user_create (user keys)
package_create_rest (package keys)
group_create_rest (group keys)
vocabulary_create (vocabulary keys)
tag_create (tag keys)
====================================== ===========================

update.py:
Expand All @@ -114,6 +120,7 @@ package_update_rest (package keys)
group_update_rest (group keys)
user_role_update user OR authorization_group, domain_object, roles
user_role_bulk_update user_roles, domain_object
vocabulary_update (vocabulary keys)
====================================== ===========================

delete.py:
Expand All @@ -124,6 +131,8 @@ Logic Action Parameter keys
package_delete id
package_relationship_delete id, id2, rel
group_delete id
vocabulary_delete id
tag_delete id, vocabulary_id
====================================== ===========================

In case of doubt, refer to the code of the logic actions, which is found in the CKAN source in the ckan/logic/action directory.
Expand All @@ -133,28 +142,28 @@ Object dictionaries

Package:

======================== ====================================== =============
key example value notes
======================== ====================================== =============
id "fd788e57-dce4-481c-832d-497235bf9f78" (Read-only) unique identifier
name "uk-spending" Unique identifier. Should be human readable
title "UK Spending" Human readable title of the dataset
url "http://gov.uk/spend-downloads.html" Home page for the data
version "1.0" Version associated with the data. String format.
author "UK Treasury" Name of person responsible for the data
author_email "contact@treasury.gov.uk" Email address for the person in the 'author' field
maintainer null Name of another person responsible for the data
maintainer_email null Email address for the person in the 'maintainer' field
notes "### About\\r\\n\\r\\nUpdated 1997." Other human readable info about the dataset. Markdown format.
license_id "cc-by" ID of the license this dataset is released under. You can then look up the license ID to get the title.
======================== ====================================================== =============
key example value notes
======================== ====================================================== =============
id "fd788e57-dce4-481c-832d-497235bf9f78" (Read-only) unique identifier
name "uk-spending" Unique identifier. Should be human readable
title "UK Spending" Human readable title of the dataset
url "http://gov.uk/spend-downloads.html" Home page for the data
version "1.0" Version associated with the data. String format.
author "UK Treasury" Name of person responsible for the data
author_email "contact@treasury.gov.uk" Email address for the person in the 'author' field
maintainer null Name of another person responsible for the data
maintainer_email null Email address for the person in the 'maintainer' field
notes "### About\\r\\n\\r\\nUpdated 1997." Other human readable info about the dataset. Markdown format.
license_id "cc-by" ID of the license this dataset is released under. You can then look up the license ID to get the title.
extras []
tags ["government-spending"] List of tags associated with this dataset.
groups ["spending", "country-uk"] List of groups this dataset is a member of.
relationships_as_subject [] List of relationships. The 'type' of the relationship is described in terms of this package being the subject and the related package being the object.
state active May be ``deleted`` or other custom states like ``pending``.
revision_id "f645243a-7334-44e2-b87c-64231700a9a6" (Read-only) ID of the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships).
revision_timestamp "2010-12-21T15:26:17.345502" (Read-only) Time and date when the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships). ISO format. UTC timezone assumed.
======================== ====================================== =============
tags [{"name": "government-spending"}, {"name": "climate"}] List of tags associated with this dataset.
groups [{"name": "spending"}, {"name": "country-uk"}] List of groups this dataset is a member of.
relationships_as_subject [] List of relationships. The 'type' of the relationship is described in terms of this package being the subject and the related package being the object.
state active May be ``deleted`` or other custom states like ``pending``.
revision_id "f645243a-7334-44e2-b87c-64231700a9a6" (Read-only) ID of the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships).
revision_timestamp "2010-12-21T15:26:17.345502" (Read-only) Time and date when the last revision for the core package object was (doesn't include tags, groups, extra fields, relationships). ISO format. UTC timezone assumed.
======================== ====================================================== =============

Package Extra:

Expand Down Expand Up @@ -197,6 +206,7 @@ id "b10871ea-b4ae-4e2e-bec9-a8d8ff357754" (Read-only)
name "country-uk" (Read-only) Add/remove tags from a package or group using update_package or update_group
state "active" (Read-only) Add/remove tags from a package or group using update_package or update_group
revision_timestamp "2009-08-08T12:46:40.920443" (Read-only)
vocabulary_id "Genre" (Read-only) Vocabulary name or id. Optional.
======================== ====================================== =============

user_roles:
Expand All @@ -209,6 +219,16 @@ authorization_group "16f8f7ba-1a97-4d27-95ce-5e8827a0d75f"
roles ['editor', 'admin']
======================== ====================================== =============

Vocabulary:

======================== ===================================================== =============
key example value notes
======================== ===================================================== =============
id "b10871ea-b4ae-4e2e-bec9-a8d8ff357754" (Read-only)
name "Genre"
tags [{"name":"government-spending"}, {"name": "climate"}] List of tags belonging to this vocabulary.
======================== ===================================================== =============

Parameters
==========

Expand Down

0 comments on commit 497ecb4

Please sign in to comment.