Skip to content
Snippets Groups Projects
Commit 2c531ede authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Merge branch '58-remove-tpsh-specific-code' into 'dev'

Remove TPSH-specific code and subject mappings

See merge request !46
parents 33f78478 386fc266
Branches
Tags
2 merge requests!48Merge dev into master,!46Remove TPSH-specific code and subject mappings
Showing
with 275 additions and 315 deletions
......@@ -14,11 +14,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `ckanext.odsh.home` configuration variable.
- The `tag_name_validator` function, responsible for validating tag names, has been removed. Tag names are no longer restricted by any validation checks, allowing for unrestricted input (according [DCAT-AP](https://www.dcat-ap.de/def/dcatde/2.0/spec/#datensatz-schlagwort)).
- Removed `ckanext.odsh.upload_formats` configuration variable. Upload formats are now populated by EU-approved file formats.
- Removed subject mappings and other subject related code used in Transparenzportal SH (TPSH).
### Changed
- Reorganized default mapping and resource files for improved organization and maintenance. Mapping and config files (e.g., file formats, licenses subject mappings, etc.) are now located in `ckanext/odsh/resources/`.
- Reorganized default mapping and resource files for improved organization and maintenance. Mapping and config files (e.g., file formats) are now located in `ckanext/odsh/resources/`.
- Refactor distribution/resource editing form to replace free-text format field with select field populated by EU-approved file formats.
- Reorganized tests and helper TPSH specific code
- Migrated TPSH helpers to `helpers.py`.
- Moved TPSH tests to `tests/` and legacy tests to `tests_wip`.
## [2.0.0] - 2023-06-08
......
......@@ -92,12 +92,10 @@ Parameter | Type | Default | Description
`ckanext.odsh.public_url` | `string` | - | The public URL, e.g., `https://opendata.schleswig-holstein.de`.
`ckanext.odsh.showtestbanner` | `boolean` | `True` | Switches on the banner "test system". Must be `false` for production server.
`ckanext.odsh.language_mapping` | `string` | `/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/resources/language_mapping.json` | Absolute path to language mapping file.
`ckanext.odsh.subject_mapping` | `string` | `/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/resources/subject_mapping.json` | Absolute path to subject mapping file.
`ckanext.odsh.spatial.mapping` | `string` | `/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/resources/schleswig-holstein_geojson.csv` | Absolute path to spatial mapping file. The mapping file is expected to be a tab-separated file with three columns: URI, spatial text, and JSON geometry.
`ckanext.odsh.resource_formats_fallback_filepath` | `string` | `/usr/lib/ckan/default/src/ckanext-odsh/ckanext/odsh/resources/fileformats.rdf` | Absolute path to resource formats fallback file.
`ckanext.odsh.require_at_least_one_category` | `boolean` | `False` | Indicates whether the presence of at least one category is required during validation.
`ckanext.odsh.require_spatial_uri` | `boolean` | `False` | Indicates whether a spatial URI is required for the dataset.
`ckanext.odsh.require_subject` | `boolean` | `True` | Indicates whether a subject is required for a dataset.
`ckanext.odsh.is_optional_temporal_start` | `boolean` | `False` | Indicate whether the `temporal_start` property is considered optional or not during validation.
`ckanext.odsh.download_proxy` | `string` | `None` | Use proxy server to access the web, e.g., `http://1.2.3.4:4123`.
`copy_remote_resources` | `boolean` | `False` | Indicates whether remote resources should be copied when creating a resource.
......@@ -120,13 +118,10 @@ test suite is provided. You can follow the instructions below to run the tests:
```sh
pytest ckanext/odsh/tests/
pytest ckanext/odsh/tests_tpsh/
```
Running these commands will initiate the test suite, which will automatically execute
various test cases and verify the expected behavior of the extension. The tests are
organized into two directories: `tests` and `tests_tpsh`, each containing different
sets of tests.
various test cases and verify the expected behavior of the extension.
### Internationalization
......
......@@ -3075,7 +3075,7 @@ body.filters-modal div.row>aside.secondary.span3 {
}
}
.tpsh-collection-list {
.odsh-collection-list {
list-style-type: none;
}
......
"use strict";
ckan.module('tpsh_toggle_menu', function ($) {
ckan.module('odsh_toggle_menu', function ($) {
return {
initialize: function () {
$.proxyAll(this, /_on/);
......
......@@ -53,7 +53,7 @@ function setSubmitButtonState(isPasswordValid) {
}
ckan.module('tpsh_validate_password', function ($) {
ckan.module('odsh_validate_password', function ($) {
return {
initialize: function () {
$.proxyAll(this, /_on/);
......
......@@ -52,20 +52,20 @@ odsh_popover_script:
contents:
- odsh_popover.js
tpsh_toggle_menu:
odsh_toggle_menu:
filters: rjsmin # preprocessor
output: ckanext-odsh/tpsh_toggle_menu.js
output: ckanext-odsh/odsh_toggle_menu.js
extra:
preload:
- base/main
contents:
- tpsh_toggle_menu.js
- odsh_toggle_menu.js
tpsh_validate_password:
odsh_validate_password:
filters: rjsmin # preprocessor
output: ckanext-odsh/tpsh_validate_password.js
output: ckanext-odsh/odsh_validate_password.js
contents:
- tpsh_validate_password.js
- odsh_validate_password.js
odsh_dataset_map_script:
filters: rjsmin # preprocessor
......@@ -135,8 +135,8 @@ odsh_spatial_query_style:
# - odsh_popover.js
# - odsh_populate_tags.js
# - odsh_spatial_query.js
# - tpsh_toggle_menu.js
# - tpsh_validate_password.js
# - odsh_toggle_menu.js
# - odsh_validate_password.js
# - vendor/jquery-ui-autocomplete/jquery-ui.js
# - vendor/leaflet.draw.js
# - vendor/leaflet.js
......
......@@ -3,7 +3,6 @@ import re
import ckanext.odsh.helpers as helpers_odsh
import datetime
import ckanext.odsh.helpers_tpsh as helpers_tpsh
import ckanext.odsh.collection.helpers as helpers_collection
import ckanext.odsh.uri_store as uri_store
......@@ -48,7 +47,7 @@ class HelperPgkDict(object):
uris_collection_members = self.get_uris_collection_members()
ckan_ids_collection_members = [self.get_id_from_store(uri) for uri in uris_collection_members]
for id_pkg in ckan_ids_collection_members:
helpers_tpsh.add_pkg_to_collection(id_pkg, id_collection)
helpers_odsh.add_pkg_to_collection(id_pkg, id_collection)
log.info('Added package with id {} to collection with id {}'.format(id_pkg, id_collection))
def get_uris_collection_members(self):
......@@ -80,7 +79,7 @@ class HelperPgkDict(object):
id_pkg = self.pkg_dict.get('id')
uri_collection = self.get_collection_uri()
id_collection = uri_store.get_id_from_uri(uri_collection)
helpers_tpsh.add_pkg_to_collection(id_pkg, id_collection)
helpers_odsh.add_pkg_to_collection(id_pkg, id_collection)
log.info('Added package with id {} to collection with id {}'.format(id_pkg, id_collection))
......
......@@ -26,6 +26,10 @@ import ckan.lib.helpers as helpers
import os.path
from collections import OrderedDict
import pkg_resources
import ckan.logic.action.create as create
CKAN_TYPES = {'http://dcat-ap.de/def/datasetTypes/collection': 'collection'}
get_action = logic.get_action
log = logging.getLogger(__name__)
......@@ -371,7 +375,7 @@ def is_within_last_month(date, date_ref=None):
return True
return False
def tpsh_get_all_datasets_belonging_to_collection(context, collection_name):
def get_all_datasets_belonging_to_collection(context, collection_name):
rel_collection_dict = dict({"id": collection_name})
name_list = list()
try:
......@@ -384,14 +388,14 @@ def tpsh_get_all_datasets_belonging_to_collection(context, collection_name):
name_list.append(item_object)
return name_list
def tpsh_get_all_datasets_belonging_to_collection_by_dataset(context, dataset_name):
collection_name = tpsh_get_collection_name_by_dataset(context, dataset_name)
def get_all_datasets_belonging_to_collection_by_dataset(context, dataset_name):
collection_name = get_collection_name_by_dataset(context, dataset_name)
if collection_name:
name_list = tpsh_get_all_datasets_belonging_to_collection(context, collection_name)
name_list = get_all_datasets_belonging_to_collection(context, collection_name)
return name_list
return list()
def tpsh_get_collection_name_by_dataset(context, dataset_name):
def get_collection_name_by_dataset(context, dataset_name):
rel_dataset_dict = dict({"id" : dataset_name})
list_rel_dataset = toolkit.get_action('package_relationships_list')(context, rel_dataset_dict)
if not len(list_rel_dataset):
......@@ -399,7 +403,7 @@ def tpsh_get_collection_name_by_dataset(context, dataset_name):
collection_name = list_rel_dataset[0]['object']
return collection_name
def tpsh_get_successor_and_predecessor_dataset(context, pkg_dict):
def get_successor_and_predecessor_dataset(context, pkg_dict):
dataset_name = pkg_dict.get('name')
siblings_dicts_with_access = _get_siblings_dicts_with_access(context, pkg_dict)
if siblings_dicts_with_access:
......@@ -421,7 +425,7 @@ def tpsh_get_successor_and_predecessor_dataset(context, pkg_dict):
def _get_siblings_dicts_with_access(context, pkg_dict):
dataset_name = pkg_dict.get('name')
list_of_siblings = tpsh_get_all_datasets_belonging_to_collection_by_dataset(context, dataset_name)
list_of_siblings = get_all_datasets_belonging_to_collection_by_dataset(context, dataset_name)
n_siblings = len(list_of_siblings)
if n_siblings>0:
siblings_dicts = [get_package_dict(name) for name in list_of_siblings]
......@@ -445,8 +449,8 @@ def _sort_siblings_by_name_and_date(siblings_dicts):
def get_package_dict(name):
return model.Package.get(name).as_dict()
def tpsh_get_successor_and_predecessor_urls(context, pkg_dict):
successor_name, predecessor_name = tpsh_get_successor_and_predecessor_dataset(context, pkg_dict)
def get_successor_and_predecessor_urls(context, pkg_dict):
successor_name, predecessor_name = get_successor_and_predecessor_dataset(context, pkg_dict)
successor_url, predecessor_url = (
helpers.url_for('dataset.read', id=name)
if name is not None
......@@ -535,3 +539,185 @@ def odsh_load_raw_mdk_sample_dataset():
)
raise
return result
def map_dct_type_to_ckan_type(dct_type):
'''
matches the field dct:type from a harvested rdf file
to the corresponding ckan package type
'''
ckan_type = CKAN_TYPES.get(dct_type)
return ckan_type
def map_ckan_type_to_dct_type(ckan_type):
DCT_TYPES = _revert_dict(CKAN_TYPES)
dct_type = DCT_TYPES.get(ckan_type)
return dct_type
def _revert_dict(d):
d_inverse = {v: k for k, v in d.items()}
return d_inverse
def add_pkg_to_collection(id_pkg, id_collection):
if id_pkg and id_collection:
relationship_dict = {
'subject': id_pkg,
'object': id_collection,
'type': 'child_of',
}
toolkit.get_action('package_relationship_create')(None, relationship_dict)
def correct_missing_relationship(pkg_dict, pkg_relationships_from_model):
'''
This function corrects missing relationship in show package.
Note this fix is only good with one or non relationship.
This error is well known but was not fixed. https://github.com/ckan/ckan/issues/3114
The error causes the deletation of relationships, because package_show is
used in resource_create to get the package.
'''
if pkg_relationships_from_model:
relationship_from_model = pkg_relationships_from_model[0]
relationship_list_from_dict = pkg_dict.get('relationships_as_subject')
type_pkg = pkg_dict.get('type')
needs_update = type_pkg == 'dataset' and not relationship_list_from_dict
if needs_update:
relationship_for_package = {
'__extras': {
'object_package_id': relationship_from_model.object_package_id,
'subject_package_id': relationship_from_model.subject_package_id,
},
'comment': relationship_from_model.subject_package_id,
'id': relationship_from_model.id,
'type': relationship_from_model.type,
}
pkg_dict['relationships_as_subject'].append(relationship_for_package)
return pkg_dict
def get_pkg_relationships_from_model(pkg_dict):
pkg_id = pkg_dict.get('id')
return model.Package.get(pkg_id).get_relationships()
def load_language_mapping():
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
file_path = config.get('ckanext.odsh.language_mapping', extension_path + '/resources/language_mapping.json')
with open(file_path) as language_mapping_json:
LANGUAGE_MAPPING = json.loads(language_mapping_json.read())
return LANGUAGE_MAPPING
def load_json_to_ordered_dict(json_str):
return json.loads(json_str, object_pairs_hook=OrderedDict)
def get_language_of_package(pkg_dict):
LANGUAGE_MAPPING = load_language_mapping()
language_id = _get_language_id(pkg_dict)
if not language_id:
return None
language = LANGUAGE_MAPPING.get(language_id)
return language
def get_language_icon(pkg_dict):
ICONS = {
"http://publications.europa.eu/resource/authority/language/DAN": '/base/images/icon_lang_danish.png',
"http://publications.europa.eu/resource/authority/language/ENG": '/base/images/icon_lang_english.png',
}
language_id = _get_language_id(pkg_dict)
if not language_id:
return None
return ICONS.get(language_id)
def _get_language_id(pkg_dict):
language_id = odsh_extract_value_from_extras(pkg_dict.get('extras'), 'language')
language_id = pkg_dict.get('language')
if not language_id:
language_id = odsh_extract_value_from_extras(
pkg_dict.get('extras'), 'language'
)
if not language_id:
return None
language_id_cleaned = re.sub('[\[\]\"]', '', language_id)
return language_id_cleaned
def get_spatial_for_selection():
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv')
with open(file_path, newline='') as mapping_file:
cr = csv.reader(mapping_file, delimiter="\t")
spatial_mapping = list(cr)
unique_mapping = []
seen_values = set()
for key, value, _ in spatial_mapping:
if value in seen_values:
continue # Skip if the value has already been seen
if "municipalityKey" in key:
unique_mapping.append({'key': key, 'value': value})
else:
# Check if there is a municipality key entry for the value
municipality_entry = next(
(entry for entry in spatial_mapping if entry[1] == value and "municipalityKey" in entry[0]),
None
)
if municipality_entry:
# If a municipality key entry exists, use it instead of the current key
unique_mapping.append({'key': municipality_entry[0], 'value': value})
else:
# Otherwise, use the current key
unique_mapping.append({'key': key, 'value': value})
seen_values.add(value)
unique_mapping.append({'key': '', 'value': ''})
return unique_mapping
def get_language_for_selection():
LANGUAGE_MAPPING = load_language_mapping()
dict_for_select_box = [{'key': key, 'value': LANGUAGE_MAPPING[key]} for key in LANGUAGE_MAPPING]
return dict_for_select_box
def get_package_dict(name):
'''
raises ckan.logic.NotFound if not found
'''
package_dict = toolkit.get_action('package_show')(None, {'id': name})
return package_dict
def size_of_fmt(num, suffix='B'):
for unit in ['',' k',' M',' G',' T',' P',' E',' Z']:
if abs(num) < 1000.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1000.0
return "%.1f%s%s" % (num, 'Y', suffix)
def get_resource_size(resource):
resource_size = resource.get('size')
if resource_size:
return size_of_fmt(resource_size)
def get_address_org(organization):
list_extras = organization.get('extras')
address = dict()
if not list_extras:
return address
for extra in list_extras:
address.update({extra.get('key'):extra.get('value')})
web = address.get('web')
if web and not web.startswith('http'):
web = 'http://' + web
address.update({'web':web})
return address
def get_body_mail(organization, package):
package_name = package.get('name')
url = helpers.url_for('dataset.read', id=package_name, qualified = True)
title = package.get('title')
anrede = "Sehr geehrte Damen und Herren," + "%0D%0A" + "%0D%0A" + "zu folgendem Eintrag habe ich eine Anmerkung/Frage:" + "%0D%0A" + "%0D%0A"
mail_titel = "Titel: " + title + "%0D%0A"
mail_document = "Dokument-ID: " + package_name + "%0D%0A"
mail_url = "URL: " + url + "%0D%0A" + "%0D%0A"
message = mail_titel + mail_document + mail_url + "Mein Kommentar:" + "%0D%0A" + "%0D%0A" + "%0D%0A" + "%0D%0A"
return anrede + message
# encoding: utf-8
import csv
import datetime
import logging
import json
import re
import urllib.request, urllib.error, urllib.parse
from collections import OrderedDict
import subprocess
import os
import pkg_resources
from ckan.common import config
import ckan.lib.helpers as helpers
import ckan.logic.action.create as create
import ckan.model as model
import ckan.plugins.toolkit as toolkit
import ckanext.odsh.helpers as odsh_helpers
log = logging.getLogger(__name__)
CKAN_TYPES = {'http://dcat-ap.de/def/datasetTypes/collection': 'collection'}
def map_dct_type_to_ckan_type(dct_type):
'''
matches the field dct:type from a harvested rdf file
to the corresponding ckan package type
'''
ckan_type = CKAN_TYPES.get(dct_type)
return ckan_type
def map_ckan_type_to_dct_type(ckan_type):
DCT_TYPES = _revert_dict(CKAN_TYPES)
dct_type = DCT_TYPES.get(ckan_type)
return dct_type
def _revert_dict(d):
d_inverse = {v: k for k, v in d.items()}
return d_inverse
def add_pkg_to_collection(id_pkg, id_collection):
if id_pkg and id_collection:
relationship_dict = {
'subject': id_pkg,
'object': id_collection,
'type': 'child_of',
}
toolkit.get_action('package_relationship_create')(None, relationship_dict)
def correct_missing_relationship(pkg_dict, pkg_relationships_from_model):
'''
This function corrects missing relationship in show package.
Note this fix is only good with one or non relationship.
This error is well known but was not fixed. https://github.com/ckan/ckan/issues/3114
The error causes the deletation of relationships, because package_show is
used in resource_create to get the package.
'''
if pkg_relationships_from_model:
relationship_from_model = pkg_relationships_from_model[0]
relationship_list_from_dict = pkg_dict.get('relationships_as_subject')
type_pkg = pkg_dict.get('type')
needs_update = type_pkg == 'dataset' and not relationship_list_from_dict
if needs_update:
relationship_for_package = {
'__extras': {
'object_package_id': relationship_from_model.object_package_id,
'subject_package_id': relationship_from_model.subject_package_id,
},
'comment': relationship_from_model.subject_package_id,
'id': relationship_from_model.id,
'type': relationship_from_model.type,
}
pkg_dict['relationships_as_subject'].append(relationship_for_package)
return pkg_dict
def get_pkg_relationships_from_model(pkg_dict):
pkg_id = pkg_dict.get('id')
return model.Package.get(pkg_id).get_relationships()
def load_language_mapping():
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
file_path = config.get('ckanext.odsh.language_mapping', extension_path + '/resources/language_mapping.json')
with open(file_path) as language_mapping_json:
LANGUAGE_MAPPING = json.loads(language_mapping_json.read())
return LANGUAGE_MAPPING
def load_json_to_ordered_dict(json_str):
return json.loads(json_str, object_pairs_hook=OrderedDict)
def load_subject_mapping():
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
file_path = config.get('ckanext.odsh.subject_mapping', extension_path + '/resources/subject_mapping.json')
with open(file_path) as subject_mapping_json:
SUBJECT_MAPPING = load_json_to_ordered_dict(subject_mapping_json.read())
return SUBJECT_MAPPING
def get_language_of_package(pkg_dict):
LANGUAGE_MAPPING = load_language_mapping()
language_id = _get_language_id(pkg_dict)
if not language_id:
return None
language = LANGUAGE_MAPPING.get(language_id)
return language
def get_language_icon(pkg_dict):
ICONS = {
"http://publications.europa.eu/resource/authority/language/DAN": '/base/images/icon_lang_danish.png',
"http://publications.europa.eu/resource/authority/language/ENG": '/base/images/icon_lang_english.png',
}
language_id = _get_language_id(pkg_dict)
if not language_id:
return None
return ICONS.get(language_id)
def _get_language_id(pkg_dict):
language_id = odsh_helpers.odsh_extract_value_from_extras(pkg_dict.get('extras'), 'language')
language_id = pkg_dict.get('language')
if not language_id:
language_id = odsh_helpers.odsh_extract_value_from_extras(
pkg_dict.get('extras'), 'language'
)
if not language_id:
return None
language_id_cleaned = re.sub('[\[\]\"]', '', language_id)
return language_id_cleaned
def get_spatial_for_selection():
extension_path = pkg_resources.resource_filename('ckanext.odsh', '')
file_path = config.get('ckanext.odsh.spatial.mapping', extension_path + '/resources/schleswig-holstein_geojson.csv')
with open(file_path, newline='') as mapping_file:
cr = csv.reader(mapping_file, delimiter="\t")
spatial_mapping = list(cr)
unique_mapping = []
seen_values = set()
for key, value, _ in spatial_mapping:
if value in seen_values:
continue # Skip if the value has already been seen
if "municipalityKey" in key:
unique_mapping.append({'key': key, 'value': value})
else:
# Check if there is a municipality key entry for the value
municipality_entry = next(
(entry for entry in spatial_mapping if entry[1] == value and "municipalityKey" in entry[0]),
None
)
if municipality_entry:
# If a municipality key entry exists, use it instead of the current key
unique_mapping.append({'key': municipality_entry[0], 'value': value})
else:
# Otherwise, use the current key
unique_mapping.append({'key': key, 'value': value})
seen_values.add(value)
unique_mapping.append({'key': '', 'value': ''})
return unique_mapping
def get_subject_for_selection():
SUBJECT_MAPPING = load_subject_mapping()
dict_for_select_box = [{'key': 'empty', 'value':' '}, ]
dict_for_select_box.extend(
[{'key': key, 'value': SUBJECT_MAPPING[key]} for key in SUBJECT_MAPPING]
)
return dict_for_select_box
def get_language_for_selection():
LANGUAGE_MAPPING = load_language_mapping()
dict_for_select_box = [{'key': key, 'value': LANGUAGE_MAPPING[key]} for key in LANGUAGE_MAPPING]
return dict_for_select_box
def get_package_dict(name):
'''
raises ckan.logic.NotFound if not found
'''
package_dict = toolkit.get_action('package_show')(None, {'id': name})
return package_dict
def size_of_fmt(num, suffix='B'):
for unit in ['',' k',' M',' G',' T',' P',' E',' Z']:
if abs(num) < 1000.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1000.0
return "%.1f%s%s" % (num, 'Y', suffix)
def get_resource_size(resource):
resource_size = resource.get('size')
if resource_size:
return size_of_fmt(resource_size)
def get_address_org(organization):
list_extras = organization.get('extras')
address = dict()
if not list_extras:
return address
for extra in list_extras:
address.update({extra.get('key'):extra.get('value')})
web = address.get('web')
if web and not web.startswith('http'):
web = 'http://' + web
address.update({'web':web})
return address
def get_body_mail(organization, package):
package_name = package.get('name')
url = helpers.url_for('dataset.read', id=package_name, qualified = True)
title = package.get('title')
anrede = "Sehr geehrte Damen und Herren," + "%0D%0A" + "%0D%0A" + "zu folgendem Eintrag habe ich eine Anmerkung/Frage:" + "%0D%0A" + "%0D%0A"
mail_titel = "Titel: " + title + "%0D%0A"
mail_document = "Dokument-ID: " + package_name + "%0D%0A"
mail_url = "URL: " + url + "%0D%0A" + "%0D%0A"
message = mail_titel + mail_document + mail_url + "Mein Kommentar:" + "%0D%0A" + "%0D%0A" + "%0D%0A" + "%0D%0A"
return anrede + message
......@@ -17,7 +17,7 @@ log = logging.getLogger(__name__)
from ckanext.odsh.setup_proxy import setup_proxy, clear_proxy
from ckanext.odsh.collection.helpers import get_collection_id, get_package_dict
from ckanext.odsh.helpers_tpsh import add_pkg_to_collection
from ckanext.odsh.helpers import add_pkg_to_collection
from ckanext.odsh.helpers import odsh_extract_value_from_extras
......@@ -117,7 +117,7 @@ def odsh_user_create(context, data_dict):
raise logic.ValidationError(PASSWORD_ERROR_MESSAGE)
def tpsh_user_update(context, data_dict):
def odsh_user_update(context, data_dict):
password = data_dict.get('password')
if not password:
password = data_dict.get('password1')
......
......@@ -11,8 +11,7 @@ import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
# imports from this extension
import ckanext.odsh.helpers as odsh_helpers
import ckanext.odsh.helpers_tpsh as helpers_tpsh
import ckanext.odsh.helpers as helpers_odsh
import ckanext.odsh.helper_pkg_dict as helper_pkg_dict
from .helper_pkg_dict import HelperPgkDict
import ckanext.odsh.logic.action as action
......@@ -60,7 +59,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
# DCAT
# if toolkit.asbool(toolkit.config.get('ckanext.dcat.enable_rdf_endpoints', True)):
# odsh_helpers.odsh_remove_route(map, 'dcat_catalog')
# helpers_odsh.odsh_remove_route(map, 'dcat_catalog')
# bp_default.add_url_rule('/catalog.<any("xml", "rdf", "n3", "ttl", "jsonld"):_format>', view_func=dcat_view.read_catalog, defaults={'_format': 'xml'}, methods=['GET'])
# Package
......@@ -106,7 +105,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def get_actions(self):
return {'package_create': action.odsh_package_create,
'user_update': action.tpsh_user_update,
'user_update': action.odsh_user_update,
'user_create': action.odsh_user_create,
'resource_create': action.odsh_resource_create, }
......@@ -132,18 +131,18 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
def create_package_schema(self):
schema = super(OdshPlugin, self).create_package_schema()
self._update_schema(schema)
self._tpsh_update_create_or_update_package_schema(schema)
self._update_create_or_update_package_schema(schema)
return schema
def update_package_schema(self):
schema = super(OdshPlugin, self).update_package_schema()
self._update_schema(schema)
self._tpsh_update_create_or_update_package_schema(schema)
self._update_create_or_update_package_schema(schema)
return schema
def show_package_schema(self):
schema = super(OdshPlugin, self).show_package_schema()
self._tpsh_update_show_package_schema(schema)
self._update_show_package_schema(schema)
return schema
def _update_schema(self, schema):
......@@ -175,7 +174,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
schema.update(
{'__extras': [toolkit.get_converter('odsh_validate_extras')]})
def _tpsh_update_create_or_update_package_schema(self, schema):
def _update_create_or_update_package_schema(self, schema):
schema.update({
'language': [
toolkit.get_validator('ignore_missing'),
......@@ -186,7 +185,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
toolkit.get_converter('convert_to_extras')
],
'relatedPackage': [
toolkit.get_validator('tpsh_validate_relatedPackage'),
toolkit.get_validator('validate_relatedPackage'),
toolkit.get_converter('convert_to_extras')
],
'accessibility': [
......@@ -196,7 +195,7 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
})
return schema
def _tpsh_update_show_package_schema(self, schema):
def _update_show_package_schema(self, schema):
schema.update({
'language': [
toolkit.get_converter('convert_from_extras'),
......@@ -248,9 +247,9 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
adds the following key-value-pairs to pkg_dict:
# key: 'is_new', value: True if the dataset has been created within the last month
'''
pkg_dict = helpers_tpsh.correct_missing_relationship(
pkg_dict = helpers_odsh.correct_missing_relationship(
pkg_dict,
helpers_tpsh.get_pkg_relationships_from_model(pkg_dict)
helpers_odsh.get_pkg_relationships_from_model(pkg_dict)
)
self._update_is_new_in_pkg_dict(pkg_dict)
......@@ -298,40 +297,39 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
# extension they belong to, to avoid clashing with functions from
# other extensions.
return {
'odsh_main_groups': odsh_helpers.odsh_main_groups,
'odsh_now': odsh_helpers.odsh_now,
'odsh_group_id_selected': odsh_helpers.odsh_group_id_selected,
'odsh_get_facet_items_dict': odsh_helpers.odsh_get_facet_items_dict,
'odsh_openness_score_dataset_html': odsh_helpers.odsh_openness_score_dataset_html,
'odsh_get_resource_details': odsh_helpers.odsh_get_resource_details,
'odsh_get_resource_views': odsh_helpers.odsh_get_resource_views,
'odsh_get_bounding_box': odsh_helpers.odsh_get_bounding_box,
'odsh_get_spatial_text': odsh_helpers.odsh_get_spatial_text,
'odsh_render_datetime': odsh_helpers.odsh_render_datetime,
'odsh_resource_formats': odsh_helpers.odsh_resource_formats,
'odsh_encodeurl': odsh_helpers.odsh_encodeurl,
'odsh_extract_error': odsh_helpers.odsh_extract_error,
'odsh_extract_error_new': odsh_helpers.odsh_extract_error_new,
'odsh_extract_value_from_extras': odsh_helpers.odsh_extract_value_from_extras,
'odsh_create_checksum': odsh_helpers.odsh_create_checksum,
'presorted_license_options': odsh_helpers.presorted_license_options,
'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets,
'odsh_public_url': odsh_helpers.odsh_public_url,
'odsh_spatial_extends_available': odsh_helpers.spatial_extends_available,
'odsh_public_resource_url': odsh_helpers.odsh_public_resource_url,
'odsh_show_testbanner': odsh_helpers.odsh_show_testbanner,
'tpsh_get_daterange_prettified': helper_pkg_dict.get_daterange_prettified,
'tpsh_get_language_of_package': helpers_tpsh.get_language_of_package,
'get_language_icon': helpers_tpsh.get_language_icon,
'short_name_for_category': odsh_helpers.short_name_for_category,
'get_spatial_for_selection': helpers_tpsh.get_spatial_for_selection,
'get_subject_for_selection': helpers_tpsh.get_subject_for_selection,
'get_language_for_selection': helpers_tpsh.get_language_for_selection,
'tpsh_get_resource_size': helpers_tpsh.get_resource_size,
'tpsh_get_address_org':helpers_tpsh.get_address_org,
'tpsh_get_body_mail':helpers_tpsh.get_body_mail,
'odsh_load_mdk_sample_dataset': odsh_helpers.odsh_load_mdk_sample_dataset,
'odsh_load_raw_mdk_sample_dataset': odsh_helpers.odsh_load_raw_mdk_sample_dataset,
'odsh_main_groups': helpers_odsh.odsh_main_groups,
'odsh_now': helpers_odsh.odsh_now,
'odsh_group_id_selected': helpers_odsh.odsh_group_id_selected,
'odsh_get_facet_items_dict': helpers_odsh.odsh_get_facet_items_dict,
'odsh_openness_score_dataset_html': helpers_odsh.odsh_openness_score_dataset_html,
'odsh_get_resource_details': helpers_odsh.odsh_get_resource_details,
'odsh_get_resource_views': helpers_odsh.odsh_get_resource_views,
'odsh_get_bounding_box': helpers_odsh.odsh_get_bounding_box,
'odsh_get_spatial_text': helpers_odsh.odsh_get_spatial_text,
'odsh_render_datetime': helpers_odsh.odsh_render_datetime,
'odsh_resource_formats': helpers_odsh.odsh_resource_formats,
'odsh_encodeurl': helpers_odsh.odsh_encodeurl,
'odsh_extract_error': helpers_odsh.odsh_extract_error,
'odsh_extract_error_new': helpers_odsh.odsh_extract_error_new,
'odsh_extract_value_from_extras': helpers_odsh.odsh_extract_value_from_extras,
'odsh_create_checksum': helpers_odsh.odsh_create_checksum,
'presorted_license_options': helpers_odsh.presorted_license_options,
'odsh_has_more_facets': helpers_odsh.odsh_has_more_facets,
'odsh_public_url': helpers_odsh.odsh_public_url,
'odsh_spatial_extends_available': helpers_odsh.spatial_extends_available,
'odsh_public_resource_url': helpers_odsh.odsh_public_resource_url,
'odsh_show_testbanner': helpers_odsh.odsh_show_testbanner,
'get_daterange_prettified': helper_pkg_dict.get_daterange_prettified,
'get_language_of_package': helpers_odsh.get_language_of_package,
'get_language_icon': helpers_odsh.get_language_icon,
'short_name_for_category': helpers_odsh.short_name_for_category,
'get_spatial_for_selection': helpers_odsh.get_spatial_for_selection,
'get_language_for_selection': helpers_odsh.get_language_for_selection,
'get_resource_size': helpers_odsh.get_resource_size,
'get_address_org':helpers_odsh.get_address_org,
'get_body_mail':helpers_odsh.get_body_mail,
'odsh_load_mdk_sample_dataset': helpers_odsh.odsh_load_mdk_sample_dataset,
'odsh_load_raw_mdk_sample_dataset': helpers_odsh.odsh_load_raw_mdk_sample_dataset,
}
......
......@@ -8,8 +8,7 @@ from ckanext.dcat.utils import resource_uri
import ckanext.dcatde.dataset_utils as ds_utils
from ckanext.dcatde.profiles import DCATdeProfile, DCATDE, DCAT, DCATDE_1_0, DCATDE_1_0_1
import ckanext.odsh.helpers as odsh_helpers
import ckanext.odsh.helpers_tpsh as helpers_tpsh
import ckanext.odsh.helpers as helpers_odsh
import ckanext.odsh.collection.helpers as helpers_collection
......@@ -49,7 +48,7 @@ class ODSHDCATdeProfile(DCATdeProfile):
def _parse_type(self, dataset_dict, dataset_ref):
dct_type = self._object(dataset_ref, DCT.type)
if dct_type:
ckan_type = helpers_tpsh.map_dct_type_to_ckan_type(str(dct_type))
ckan_type = helpers_odsh.map_dct_type_to_ckan_type(str(dct_type))
dataset_dict.update({'type': ckan_type})
def _parse_references(self, dataset_dict, dataset_ref):
......@@ -114,7 +113,7 @@ class ODSHDCATdeProfile(DCATdeProfile):
Adds reference (Musterdatenkatalog/Musterdatensatz) extra field to
dcat:references.
'''
sample_dataset_uri = odsh_helpers.odsh_extract_value_from_extras(dataset_dict.get('extras'), 'reference')
sample_dataset_uri = helpers_odsh.odsh_extract_value_from_extras(dataset_dict.get('extras'), 'reference')
if sample_dataset_uri:
self.g.set(
(dataset_ref, DCT.references,
......@@ -150,7 +149,7 @@ class ODSHDCATdeProfile(DCATdeProfile):
dct:type
'''
ckan_type = self._get_ckan_type(dataset_dict)
dct_type = helpers_tpsh.map_ckan_type_to_dct_type(ckan_type)
dct_type = helpers_odsh.map_ckan_type_to_dct_type(ckan_type)
if dct_type:
self.g.set(
(dataset_ref, DCT.type,
......
{% block scripts %}
{% asset 'ckanext-odsh/tpsh_toggle_menu' %}
{% asset 'ckanext-odsh/odsh_toggle_menu' %}
{% endblock scripts %}
{% block header_wrapper %}
......@@ -24,7 +24,7 @@
</div>
<h1 class='site-title'> {{ g.site_title }} </h1>
</div>
<div id="menu-button-and-title" data-module="tpsh_toggle_menu">
<div id="menu-button-and-title" data-module="odsh_toggle_menu">
<span class="fa fa-bars"></span>
<h1 class='site-title-mobile'> {{ g.site_title }} </h1>
</div>
......@@ -34,7 +34,7 @@
<div class='row navigation-row'>
<nav class="section navigation">
<ul class="nav nav-pills">
<li class="header-menu-mobile" data-module="tpsh_toggle_menu">
<li class="header-menu-mobile" data-module="odsh_toggle_menu">
<a>{{ _('Menu') }}</a>
<img src="/base/images/icon_close_white.svg" alt="Menü schließen" aria-label="Menü schließen" />
</li>
......
......@@ -134,7 +134,7 @@ Examples:
selected=2011, error=errors.year) }}
#}
{% macro tpsh_select(name, id='', label='', options='', selected='', error='', classes=[], attrs={},
{% macro odsh_select(name, id='', label='', options='', selected='', error='', classes=[], attrs={},
is_required=false) %}
{% set classes = (classes|list) %}
{% do classes.append('control-select') %}
......
......@@ -29,7 +29,7 @@
{% set extras = h.tpsh_get_address_org(data) %}
{% set extras = h.get_address_org(data) %}
{{ form.input_address('person','Ansprechpartner', value= extras.person , index=0, placeholder='', type='text', attrs={}) }}
......
......@@ -9,7 +9,7 @@ Example:
#}
{% set daterange = h.tpsh_get_daterange_prettified(pkg) %}
{% set daterange = h.get_daterange_prettified(pkg) %}
{% set license_attribution_by_text = h.odsh_extract_value_from_extras(pkg.extras, 'licenseAttributionByText') %}
{% block package_info %}
......
......@@ -230,7 +230,7 @@ dataset_is_draft)) %}
{# field language #}
{% set before_selected = data.get('language') or h.odsh_extract_value_from_extras(data.extras, 'language') or 'http://publications.europa.eu/resource/authority/language/DEU' %}
{{ form.tpsh_select('language', label=_('language'), options=h.get_language_for_selection(), selected=before_selected , error=errors.language, is_required=False, classes=['control-full']) }}
{{ form.odsh_select('language', label=_('language'), options=h.get_language_for_selection(), selected=before_selected , error=errors.language, is_required=False, classes=['control-full']) }}
{# field spatial_uri #}
......
......@@ -65,7 +65,7 @@
{% set error_string = _('odsh_resource_format_error_label') if errors.format %}
{% set format_attrs = {'data-module': 'odsh_guessformat', 'data-module-formats':h.odsh_resource_formats(true)} %}
{{ form.tpsh_select('format', id='field-format', label=_('Format'), selected=data.format, options=h.odsh_resource_formats(), is_required=True, error=error_string, attrs=format_attrs, classes=['control-full'])}}
{{ form.odsh_select('format', id='field-format', label=_('Format'), selected=data.format, options=h.odsh_resource_formats(), is_required=True, error=error_string, attrs=format_attrs, classes=['control-full'])}}
{% endblock %}
{% endblock %}
......
......@@ -5,7 +5,7 @@
{% set download = h.odsh_public_resource_url(res) or url %}
{% set rtitle=h.resource_display_name(res) if res.name else ' '%}
{% set resource_size = h.tpsh_get_resource_size(res) %}
{% set resource_size = h.get_resource_size(res) %}
{% set res_format = res.format.replace('_SRVC','') %}
<li class="resource-item" data-id="{{ res.id }}">
......
......@@ -34,7 +34,7 @@ Example:
</div>
<div class="information-organisation">
{% set address = h.tpsh_get_address_org(organization) %}
{% set address = h.get_address_org(organization) %}
{% set street = address.get('street') %}
{% set location = address.get('location') %}
{% set mail = address.get('mail') %}
......@@ -56,7 +56,7 @@ Example:
{% if package %}
{% set package_name = package.get('name') %}
{% set betreff = "Open-Data-Portal Datensatz: "+ package_name%}
{% set body_mail = h.tpsh_get_body_mail(organization, package) %}
{% set body_mail = h.get_body_mail(organization, package) %}
{% else %}
{% set betreff = "Transparenzportal" %}
{% endif %} {# package #}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment