Skip to content

Commit

Permalink
playing around with scheming extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Mar 23, 2023
1 parent 6c9c6de commit aa1735d
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 2 deletions.
42 changes: 41 additions & 1 deletion ckan/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,44 @@ RUN if ! [ /usr/share/zoneinfo/${TZ} -ef /etc/localtime ]; then \

# Copy ckan.ini and images to container
COPY ckan.ini /srv/app/ckan.ini
COPY images/muc_2.png /srv/app/src/ckan/ckan/public/base/images/muc_2.png
COPY images/muc_2.png /srv/app/src/ckan/ckan/public/base/images/muc_2.png



# Install any extensions needed by your CKAN instance
# - Make sure to add the plugins to CKAN__PLUGINS in the .env file
# - Also make sure all extra configuration options are added to the CKAN config file (ckan.ini)
# This can be done by creating an overriding start_ckan_dev_development.sh file:
# (https://github.com/ckan/ckan-docker-base/blob/main/ckan-2.9/dev/setup/start_ckan_development.sh) ie: updating the 'ckan config-tool' lines
# For more on config-tool please see https://docs.ckan.org/en/latest/maintaining/cli.html#config-tool-tool-for-editing-options-in-a-ckan-config-file
# or using Crudini (https://github.com/pixelb/crudini)
#
# For instance:
#
### XLoader ###
#RUN pip3 install -e 'git+https://github.com/ckan/ckanext-xloader.git@master#egg=ckanext-xloader' && \
# pip3 install -r ${APP_DIR}/src/ckanext-xloader/requirements.txt && \
# pip3 install -U requests[security]

### Harvester ###
#RUN pip3 install -e 'git+https://github.com/ckan/ckanext-harvest.git@master#egg=ckanext-harvest' && \
# pip3 install -r ${APP_DIR}/src/ckanext-harvest/pip-requirements.txt
# will also require gather_consumer and fetch_consumer processes running (please see https://github.com/ckan/ckanext-harvest)

### Scheming ###
#RUN pip3 install -e 'git+https://github.com/ckan/ckanext-scheming.git@master#egg=ckanext-scheming'
RUN pip3 install -e 'git+https://github.com/ckan/ckanext-scheming.git@master#egg=ckanext-scheming'
COPY extensions/camel_photos.yaml /srv/app/src/ckanext-scheming/ckanext/scheming/camel_photos.yaml
COPY extensions/add_dataset.html /srv/app/src/ckan/ckan/templates/snippets/add_dataset.html
### Pages ###
#RUN pip3 install -e git+https://github.com/ckan/ckanext-pages.git#egg=ckanext-pages

### DCAT ###
#RUN pip3 install -e git+https://github.com/ckan/[email protected]#egg=ckanext-dcat && \
# pip3 install -r https://raw.githubusercontent.com/ckan/ckanext-dcat/v0.0.6/requirements.txt

# Clone the extension(s) your are writing for your own project in the `src` folder
# to get them mounted in this image at runtime

# Apply any patches needed to CKAN core or any of the built extensions (not the
# runtime mounted ones)
10 changes: 9 additions & 1 deletion ckan/ckan.ini
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ ckan.cors.origin_allow_all = false
ckan.cors.origin_whitelist =

## Plugins Settings ############################################################
ckan.plugins = envvars image_view text_view recline_view datastore datapusher
ckan.plugins = envvars image_view text_view recline_view datastore datapusher scheming_datasets
ckan.resource_proxy.timeout = 5

## ckanext-scheming ##############################
# module-path:file to schemas being used
scheming.dataset_schemas = ckanext.scheming:camel_photos.yaml
ckanext.scheming:ckan_dataset.yaml
ckanext.scheming:ckan_formpages.yaml
# will try to load "spatialx_schema.yaml" and "spatialxy_schema.yaml"
# as dataset schemas

## Front-End Settings ##########################################################
ckan.site_title = Data Catalog by LHM - title
ckan.site_description = Data Catalog by LHM - description
Expand Down
37 changes: 37 additions & 0 deletions ckan/extensions/add_dataset.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{# Adds 'Add Dataset' button #}

{% set dataset_type = dataset_type if dataset_type else h.default_package_type() %}
{% set link_label = h.humanize_entity_type('package', dataset_type, 'add link') or _("Add Dataset Standard") %}
{% set route_name = dataset_type ~ '.new' %}

{% if group %}
{% link_for link_label, named_route=route_name, group=group, class_='btn btn-primary', icon='plus-square' %}
{% else %}
{% link_for link_label, named_route=route_name, class_='btn btn-primary', icon='plus-square' %}
{% endif %}


{# Adds 'Add Camel-Photo' button #}

{% set dataset_type = dataset_type if dataset_type else h.default_package_type() %}
{% set link_label = h.humanize_entity_type('package', dataset_type, 'add link') or _("Add Dataset Camel") %}
{% set route_name = "camel-photos" ~ '.new' %}

{% if group %}
{% link_for link_label, named_route=route_name, group=group, class_='btn btn-primary', icon='plus-square' %}
{% else %}
{% link_for link_label, named_route=route_name, class_='btn btn-primary', icon='plus-square' %}
{% endif %}


{# Adds 'Add ckan_formpages' button #}

{% set dataset_type = dataset_type if dataset_type else h.default_package_type() %}
{% set link_label = h.humanize_entity_type('package', dataset_type, 'add link') or _("Add Dataset Formpages") %}
{% set route_name = "formpages" ~ '.new' %}

{% if group %}
{% link_for link_label, named_route=route_name, group=group, class_='btn btn-primary', icon='plus-square' %}
{% else %}
{% link_for link_label, named_route=route_name, class_='btn btn-primary', icon='plus-square' %}
{% endif %}
81 changes: 81 additions & 0 deletions ckan/extensions/camel_photos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
scheming_version: 2
dataset_type: camel-photos
about_url: http://example.com/the-camel-photos-schema


dataset_fields:

- field_name: title
label: Title
preset: title
form_placeholder: eg. Larry, Peter, Susan

- field_name: name
label: URL
preset: dataset_slug
form_placeholder: eg. camel-no-5

- field_name: humps
label: Humps
validators: ignore_missing int_validator
form_placeholder: eg. 2

- field_name: category
label: Category
help_text: Make and model
help_inline: true
preset: select
choices:
- value: bactrian
label: Bactrian Camel
- value: hybrid
label: Hybrid Camel
- value: f2hybrid
label: F2 Hybrid Camel
- value: snowwhite
label: Snow-white Dromedary
- value: black
label: Black Camel

- field_name: personality
label: Personality
preset: multiple_checkbox
choices:
- value: friendly
label: Often friendly
- value: jealous
label: Jealous of others
- value: spits
label: Tends to spit

- field_name: other
label:
en: Other information
output_validators: ignore_missing

- field_name: owner_org
label: Organization
preset: dataset_organization


resource_fields:

- field_name: url
label: Photo
preset: resource_url_upload
form_placeholder: http://example.com/my-camel-photo.jpg
upload_label: Photo

- field_name: camels_in_photo
label: Camels in Photo
validators: ignore_missing int_validator
form_placeholder: eg. 2

- field_name: others_in_photo
label: Other Thing in Photo
output_validators: ignore_missing

- field_name: datetime
label: Date Taken
label_time: Time Taken
preset: datetime

0 comments on commit aa1735d

Please sign in to comment.