コード例 #1
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))
コード例 #2
0
def article_like(request, article_index):
    user = request.user
    article = Article.objects.get(id=article_index)
    if ArticleLike.has_liked(article, user):
        ArticleLike.dislike(article, user)
        likes_text = 'like'
    else:
        ArticleLike.like(article, user)
        likes_text = 'dislike'
    likes_count = str(ArticleLike.get_likes_count(article))
    return JsonResponse({
        'likes_text': likes_text,
        'likes_count': likes_count,
    })