Example #1
0
def download_article(request, article_index):
    article = Article.objects.get(id=article_index)
    ArticleDownload.add_download(article)
    file_manager = ArticleFilesManager(article_index)
    filepath = file_manager.get_pdf_file_path()
    wrapper = FileWrapper(file(filepath))
    response = HttpResponse(wrapper, content_type='text/plain')
    response['Content-Disposition'] = 'attachment; filename="%s"' % (str(article.id) + '.pdf')
    response['Content-Length'] = os.path.getsize(filepath)
    return response
Example #2
0
def article_details(request, article_index):
    template = loader.get_template('search/article_details.html')
    article = Article.objects.get(id=article_index)
    try:
        article_import = ArticleImport.objects.get(article_id=article_index)
        article_template = article_import.template
        files_manager = ArticleFilesManager(article_import.id)
        abstract_path = files_manager.get_abstract_file_path()
        af = file(abstract_path, 'r+')
        abstract = af.read() if af is not None else None
        af.close()
    except Exception as e:
        abstract = None
        article_import = None
        article_template = None
    authors = article.authors.all()
    references = article.article.all()
    referenced_times = article.reference.all().count()
    article_themes = ArticleTheme.objects.filter(article=article)
    themes_map = {}
    for article_theme in article_themes:
        if article_theme.extraction_type not in themes_map:
            themes_map[article_theme.extraction_type] = []
        themes_map[article_theme.extraction_type].append(article_theme.theme)
    iaas = InstitutionAuthorArticle.objects.filter(article=article)
    institutions = [iaa.institution for iaa in iaas]
    as_sugest = ArticleSugestedArticle.objects.filter(article=article)
    sugested_articles= [a_sugest.sugested_article for a_sugest in as_sugest]
    sugested_themes = ArticleSugestedTheme.objects.filter(article=article)
    number_downloads = ArticleDownload.get_download_count(article)
    number_likes = ArticleLike.get_likes_count(article)
    context = RequestContext(request, {'article': article,
                                       'authors': authors,
                                       'article_template': article_template,
                                       'references': references,
                                       'institutions': institutions,
                                       'abstract': abstract,
                                       'themes_map': themes_map.iteritems(),
                                       'referenced_times': referenced_times,
                                       'article_import': article_import,
                                       'sugested_articles': sugested_articles,
                                       'sugested_themes': sugested_themes,
                                       'number_downloads': number_downloads,
                                       'number_likes': number_likes,
                                       'maps_api': settings.MAPS_API
                                       })
    return HttpResponse(template.render(context))