Skip to main content

No project description provided

Project description

Tests

ckanext-collection

Tools for building interfaces for data collections using declarative style.

This extension simplifies describing series of items, such as datasets from search page, users registered on portal, rows of CSV file, tables in DB, etc. Once you defined the way of fetching items from data source, you'll get generic interface for pagination, search and displaying data in any format: HTML page, CSV document, JSON list, or any other custom format that you can describe.

Read the documentation for a full user guide.

Quickstart

Install the extension

pip install ckanext-collection

Add collection to the ckan.plugins setting in your CKAN config file

Define the collection

from ckan import model
from ckanext.collection.shared import collection, data, columns, serialize


## collection of all resources from DB
class MyCollection(collection.Collection):
    DataFactory = data.ModelData.with_attributes(model=model.Resource)
    # `names` controls names of fields exported by serializer
    # further in this guide
    ColumnsFactory = columns.Columns.with_attributes(names=["name", "size"])

## collection of all packages available via search API
class MyCollection(collection.Collection):
    DataFactory = data.ApiSearchData.with_attributes(action="package_search")
    ColumnsFactory = columns.Columns.with_attributes(names=["name", "title"])

## collection of all records from CSV file
class MyCollection(collection.Collection):
    DataFactory = data.CsvFileData.with_attributes(source="/path/to/file.csv")
    ColumnsFactory = columns.Columns.with_attributes(names=["a", "b"])

Initialize collection object and work with data:

# collection with first page of results(1st-10th items)
col = MyCollection()
items = list(col)

# collection with third page of results(21st-30th items)
col = MyCollection("", {"page": 3})
items = list(col)


# alternatively, read all the items into memory at once, without pagination.
# It may be quite expensive operation depending on number of items
col = MyCollection()
items = list(col.data)

# or get the slice of data from 8th till 12th
items = list(col.data[8:12])

# check total number of items in collection
print(col.data.total)

Serialize data using Serializer service:

# JSON string
serializer = serialize.JsonSerializer(col)

# or CSV string
serializer = serialize.CsvSerializer(col)

# or python list of dictionaries
serializer = serialize.DictListSerializer(col)


print(serializer.serialize())

License

AGPL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ckanext_collection-0.2.0.tar.gz (84.7 kB view details)

Uploaded Source

Built Distribution

ckanext_collection-0.2.0-py3-none-any.whl (102.3 kB view details)

Uploaded Python 3

File details

Details for the file ckanext_collection-0.2.0.tar.gz.

File metadata

  • Download URL: ckanext_collection-0.2.0.tar.gz
  • Upload date:
  • Size: 84.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for ckanext_collection-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e37ae5e2d649c07a122ed0be77e95a609e99ce3b20123b804c12fa3f9cfd9b03
MD5 606dbb9a1a4106cb81230427ea65ba45
BLAKE2b-256 23b8a7c29dfc01d205446814981e3771596e03db82ae67b378081209891e5c6b

See more details on using hashes here.

File details

Details for the file ckanext_collection-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ckanext_collection-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44edd7fdec35512eb4632c7baf2d2f2f0abacd703d28dcdba2d11a52c7e7d521
MD5 7884b6e8a759366d04ddef392c2a88f0
BLAKE2b-256 0c344097cf2437c14a80231f9a01144365182d0970fc331f497a3bbbdc398e7a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page