def process_metadata(result): created = False dataset = None try: the_id = result['dataset_id'] dataset = DataSet.objects.get(blackrock_id=the_id) except DataSet.DoesNotExist: dataset = DataSet() created = True original_state = dict(dataset.__dict__) values = process_fieldnames(result) dataset = process_dataset_meta_fields(dataset, values) dataset.location = process_location(values) save_if_created(created, dataset) for field in dataset._meta.many_to_many: if field.name in list(values.keys()): related_model = apps.et_model("portal", field.name) for v in values[field.name]: if field.name == 'url': v = settings.CDRS_SOLR_FILEURL + v related_obj, temp_created = \ related_model.objects.get_or_create(name=v.strip()) dataset.__getattribute__(field.name).add(related_obj) dataset.audience.add(Audience.objects.get(name='Research')) save_if_dirty(original_state, dataset) return created
def process_metadata(result): created = False dataset = None try: the_id = result['dataset_id'] dataset = DataSet.objects.get(blackrock_id=the_id) except DataSet.DoesNotExist: dataset = DataSet() created = True original_state = dict(dataset.__dict__) values = process_fieldnames(result) dataset = process_dataset_meta_fields(dataset, values) dataset.location = process_location(values) save_if_created(created, dataset) for field in dataset._meta.many_to_many: if field.name in list(values.keys()): related_model = apps.et_model("portal", field.name) for v in values[field.name]: if field.name == 'url': v = settings.CDRS_SOLR_FILEURL + v related_obj, temp_created = \ related_model.objects.get_or_create(name=v.strip()) dataset.__getattribute__(field.name).add(related_obj) dataset.audience.add(Audience.objects.get(name='Research')) save_if_dirty(original_state, dataset) return created
def process_metadata(result): created = False dataset = None try: the_id = result['dataset_id'] dataset = DataSet.objects.get(blackrock_id=the_id) except DataSet.DoesNotExist: dataset = DataSet() created = True original_state = dict(dataset.__dict__) values = process_fieldnames(result) for field in dataset._meta.fields: if field.name in values.keys(): if isinstance(field, DateField): value = process_date(values[field.name][0]) else: value = values[field.name][0] dataset.__setattr__(field.name, value) dataset.location = process_location(values) if created: dataset.save() for field in dataset._meta.many_to_many: if field.name in values.keys(): related_model = get_model("portal", field.name) for v in values[field.name]: if field.name == 'url': v = settings.CDRS_SOLR_FILEURL + v related_obj, temp_created = \ related_model.objects.get_or_create(name=v.strip()) dataset.__getattribute__(field.name).add(related_obj) dataset.audience.add(Audience.objects.get(name='Research')) if _is_dirty(original_state, dict(dataset.__dict__)): dataset.save() return created
def process_metadata(result): created = False dataset = None try: the_id = result['dataset_id'] dataset = DataSet.objects.get(blackrock_id=the_id) except DataSet.DoesNotExist: dataset = DataSet() created = True original_state = dict(dataset.__dict__) values = process_fieldnames(result) for field in dataset._meta.fields: if field.name in values.keys(): if isinstance(field, DateField): value = process_date(values[field.name][0]) else: value = values[field.name][0] dataset.__setattr__(field.name, value) dataset.location = process_location(values) if created: dataset.save() for field in dataset._meta.many_to_many: if field.name in values.keys(): related_model = get_model("portal", field.name) for v in values[field.name]: if field.name == 'url': v = settings.CDRS_SOLR_FILEURL + v related_obj, temp_created = \ related_model.objects.get_or_create(name=v.strip()) dataset.__getattribute__(field.name).add(related_obj) dataset.audience.add(Audience.objects.get(name='Research')) if _is_dirty(original_state, dict(dataset.__dict__)): dataset.save() return created