def prefill_service_model(organisation): model = open_json_staticfile( os.path.join(MDEDIT_CONFIG_PATH, MDEDIT_SERVICE_MODEL)) data = model.copy() # editor = None # qui est l'éditeur ? default_contact = { # 'individualName': editor.get_full_name(), 'organisationName': organisation.legal_name, 'email': organisation.email, 'phoneVoice': organisation.phone, 'deliveryPoint': organisation.address, 'postalCode': organisation.postcode, 'city': organisation.city} md_contacts = {**default_contact, **{'role': 'author'}} md_data_point_of_contacts = {**default_contact, **{'role': 'owner'}} try: logo = { 'logoDescription': 'logo', 'logoUrl': urljoin(DOMAIN_NAME, organisation.logo.url)} except Exception: pass else: md_contacts.update(logo) md_data_point_of_contacts.update(logo) data['mdContacts'].insert(0, md_contacts) data['dataPointOfContacts'].insert(0, md_data_point_of_contacts) return clean_my_obj(data)
def prefill_dataset_model(dataset): model = open_json_staticfile( os.path.join(MDEDIT_CONFIG_PATH, MDEDIT_DATASET_MODEL)) data = model.copy() editor = dataset.editor organisation = dataset.organisation default_contact = { 'individualName': editor.get_full_name(), 'organisationName': organisation.legal_name, 'email': organisation.email, 'phoneVoice': organisation.phone, 'deliveryPoint': organisation.address, 'postalCode': organisation.postcode, 'city': organisation.city} md_contacts = {**default_contact, **{'role': 'author'}} md_data_point_of_contacts = {**default_contact, **{'role': 'owner'}} try: organisation_logo = { 'logoDescription': 'logo', 'logoUrl': urljoin(DOMAIN_NAME, organisation.logo.url)} except Exception: pass else: md_contacts.update(organisation_logo) md_data_point_of_contacts.update(organisation_logo) data['mdContacts'].insert(0, md_contacts) data['dataPointOfContacts'].insert(0, md_data_point_of_contacts) data['dataTitle'] = dataset.title data['dataAbstract'] = dataset.description if dataset.date_creation: data['dataDates'].insert(0, { 'date': dataset.date_creation.isoformat(), 'dateType': 'creation'}) if dataset.date_publication: data['dataDates'].insert(1, { 'date': dataset.date_publication.isoformat(), 'dateType': 'publication'}) if dataset.date_modification: data['dataDates'].insert(2, { 'date': dataset.date_modification.isoformat(), 'dateType': 'revision'}) data['dataMaintenanceFrequency'] = { 'never': 'notPlanned', # [011] There are no plans to update the data 'asneeded': 'asNeeded', # [009] Data is updated as deemed necessary 'intermittently': 'irregular', # [010] Data is updated in intervals that are uneven in duration 'continuously': 'continual', # [001] Data is repeatedly and frequently updated 'realtime': 'continual', # ??? -> [001] 'daily': 'daily', # [002] Data is updated each day 'weekly': 'weekly', # [003] data is updated on a weekly basis 'fortnightly': 'fortnightly', # [004] data is updated every two weeks 'monthly': 'monthly', # [005] data is updated each month 'quarterly': 'quaterly', # [006] data is updated every three months 'semiannual': 'biannually', # [007] data is updated twice each year 'annual': 'annually' # [008] data is updated every year }.get(dataset.update_frequency, 'unknow') # [012] frequency of maintenance for the data is not known if dataset.keywords: data['dataKeywords'].insert(0, { 'keywords': [kw for kw in dataset.keywords.names()], 'keywordType': 'theme'}) for category in Category.objects.filter(dataset=dataset): iso_topic = category.iso_topic if iso_topic: data['dataTopicCategories'].append(iso_topic) try: data['dataBrowseGraphics'].insert(0, { 'fileName': urljoin(DOMAIN_NAME, dataset.thumbnail.url), # 'fileDescription': 'Imagette', 'fileType': dataset.thumbnail.name.split('.')[-1]}) except Exception: pass resources = Resource.objects.filter(dataset=dataset) for resource in resources: entry = { 'name': resource.title, 'url': '{0}/dataset/{1}/resource/{2}'.format( CKAN_URL, dataset.slug, resource.ckan_id), 'description': resource.description} protocol = resource.format_type.protocol if protocol: entry['protocol'] = protocol data['dataLinkages'].insert(0, entry) return clean_my_obj(data)