def create_document(task: ExtendedTask, uri: str, project_id, run_detect_field_values): with file_access_handler.get_local_fn(uri) as (fn, file_name): task.task.title = 'Load Document: {0}'.format(uri) task.log_extra = {'log_document_name': uri} with open(fn, encoding='utf-8') as data_file: data = json.loads(data_file.read()) project = Project.objects.get(pk=project_id) document_type = project.type document = Document( name=file_name, project=project, document_type=document_type, metadata={'parsed_by': None} ) LoadDocumentWithFields.load_doc(task, document, data, run_detect_field_values)
def create_document(task: ExtendedTask, uri: str, project_id, run_detect_field_values): file_storage = get_file_storage() with file_storage.get_document_as_local_fn(uri) as (fn, file_name): task.task.title = 'Load Document: {0}'.format(uri) task.log_extra = {'log_document_name': uri} with open(fn, encoding='utf-8') as data_file: data = json.loads(data_file.read()) project = Project.objects.get(pk=project_id) document_type = project.type document = Document( name=file_name, project=project, document_type=document_type, ) LoadDocumentWithFields.load_doc(task=task, document=document, field_values_alias_to_value=data, run_detect_field_values=run_detect_field_values)