def create_dataset(dataset, all_organizations): params = { "title": dataset.title, "name": dataset_title_to_name(dataset.title), "notes": dataset.description, "owner_org": all_organizations[dataset.publishing_organization_key].name, "url": urlparse.urljoin("http://www.gbif.org/dataset/", dataset.uuid), # Having difficulties adding extras to the dataset. # So far, it works IF the extras parameter is not named extras (myextras is good), and a dict # (not a list of dicts) is passed. It is, however, not shown in the web interface later... #'extras': [{'dataset_type': dataset.dataset_type}] "gbif_uuid": dataset.uuid, # A Heavy but perfectly working solution: add the field via a plugin like in the tutorial: # http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html # Then pass the parameter as a first-class one (title, name, ...) (no list of dicts: just a key and value) "dataset_type": dataset.dataset_type, "administrative_contact": dataset.administrative_contact_full, "administrative_contact_name": dataset.administrative_contact_name, "metadata_contact": dataset.metadata_contact, } if dataset.dwca_url: params["dwca_url"] = dataset.dwca_url if dataset.website: params["dataset_website"] = dataset.website r = make_ckan_api_call("api/action/package_create", params) if not r["success"]: raise CKANAPIException({"message": "Impossible to create dataset", "dataset": dataset, "error": r["error"]})
def create_in_ckan(self): # Document is incorrect regarding packages: we need an id parameter, that in fact receive the dataset name... confusing. params = { "name": self.name, "title": self.title, "packages": [{"id": dataset_title_to_name(dataset.title)} for dataset in self.attached_datasets], "image_url": self.logo_url, } r = make_ckan_api_call("api/action/group_create", params) return r["success"]
def create_in_ckan(self): # Document is incorrect regarding packages: we need an id parameter, that in fact receive the dataset name... confusing. params = { 'name': self.name, 'title': self.title, 'packages': [{ 'id': dataset_title_to_name(dataset.title) } for dataset in self.attached_datasets], 'image_url': self.logo_url } try: r = make_ckan_api_call("api/action/group_create", params) return r['success'] except ValueError: #FIXME: why does we sometimes (only in prod...) get a JSONDecodeError at this stage? print("Error decoding JSON") return True
def create_dataset(dataset, all_organizations): params = { 'title': dataset.title, 'name': dataset_title_to_name(dataset.title), 'notes': dataset.description, 'owner_org': all_organizations[dataset.publishing_organization_key].name, 'url': urljoin("http://www.gbif.org/dataset/", dataset.uuid), # Having difficulties adding extras to the dataset. # So far, it works IF the extras parameter is not named extras (myextras is good), and a dict # (not a list of dicts) is passed. It is, however, not shown in the web interface later... #'extras': [{'dataset_type': dataset.dataset_type}] 'gbif_uuid': dataset.uuid, # A Heavy but perfectly working solution: add the field via a plugin like in the tutorial: # http://docs.ckan.org/en/latest/extensions/adding-custom-fields.html # Then pass the parameter as a first-class one (title, name, ...) (no list of dicts: just a key and value) 'dataset_type': dataset.dataset_type, 'administrative_contact': dataset.administrative_contact_full, 'administrative_contact_name': dataset.administrative_contact_name, 'metadata_contact': dataset.metadata_contact, } if dataset.dwca_url: params['dwca_url'] = dataset.dwca_url if dataset.website: params['dataset_website'] = dataset.website r = make_ckan_api_call("api/action/package_create", params) if not r['success']: raise CKANAPIException({ "message": "Impossible to create dataset", "dataset": dataset, "error": r['error'] })
def __init__(self, title, gbif_uuid, id, dwca_url=None, dataset_type=None, description=None, publishing_organization_key=None, administrative_contact_full=None, administrative_contact_name=None, metadata_contact_full=None, metadata_contact_name=None, originator_full=None, originator_name=None, website=None, resources=None, metadata_modified=None, metadata_created=None, maintenance_frequency=None, keywords=None, license_id=None, northbound_lat=None, southbound_lat=None, eastbound_lon=None, westbound_lon=None, geo_desc=None, start_datetime=None, end_datetime=None, occurrences=None, occurrence_count=None, doi=None, doi_gbif=None, study_extent=None, quality_control=None, method_steps=None): self.title = title self.name = dataset_title_to_name(self.title) self.gbif_uuid = gbif_uuid self.id = id self.dwca_url = dwca_url self.dataset_type = dataset_type self.description = description self.publishing_organization_key = publishing_organization_key self.administrative_contact_full = administrative_contact_full self.administrative_contact_name = administrative_contact_name self.metadata_contact_full = metadata_contact_full self.metadata_contact_name = metadata_contact_name self.originator_full = originator_full self.originator_name = originator_name self.website = website self.resources = resources self.metadata_modified = metadata_modified self.metadata_created = metadata_created self.maintenance_frequency = maintenance_frequency self.keywords = keywords self.license_id = license_id self.northbound_lat = northbound_lat self.southbound_lat = southbound_lat self.eastbound_lon = eastbound_lon self.westbound_lon = westbound_lon self.geo_desc = geo_desc self.start_datetime = start_datetime self.end_datetime = end_datetime self.occurrences = occurrences self.occurrence_count = occurrence_count self.doi = doi self.doi_gbif = doi_gbif self.study_extent = study_extent self.quality_control = quality_control self.method_steps = method_steps