def import_file(file_, template_id):
    template = ArticleTemplate.objects.get(id=template_id)
    layout_builder = LayoutBuilder(template.get_description_path())
    content_mapper = ContentMapper(template.get_sintax_path())
    pdf_extractor = PdfExtractor(file_, False)
    content_map = extract_content(pdf_extractor, layout_builder, content_mapper)
    article_import = ArticleImport()
    article_import.template = template
    article_import.save()
    file_name = str(article_import.id)
    create_abstract_file(file_name, content_map['abstract'])
    create_pdf_file(file_name, file_)
    create_text_file(file_name, content_map)
    article_info = {}
    article_info['article_import_id'] = article_import.id
    article_info['title'] = content_map['title']
    article_info['authors'] = content_map['authors']
    article_info['abstract'] = content_map['abstract']
    article_info['keywords'] = content_map['keywords'] if 'keywords' in content_map else []
    article_info['references'] = content_map['references'] if 'references' in content_map else []
    return article_info
def import_manually_db(article_info):
    article_import_id = article_info.get('article_import_id')
    if article_import_id:
        article_import = ArticleImport.objects.get(id=article_import_id)
    else:
        article_import = ArticleImport()
        article_import.save()
    file_name = str(article_import.id)
    create_abstract_file(file_name, article_info['abstract'])
    article = import_db(article_info)
    article_import.article = article
    article_import.save()
    return