예제 #1
0
파일: views.py 프로젝트: scieloorg/opac
def article_detail(url_seg, url_seg_issue, url_seg_article, lang_code=''):

    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _('Issue não encontrado'))

    article = controllers.get_article_by_issue_article_seg(issue.iid, url_seg_article)

    if not article:
        abort(404, _('Artigo não encontrado'))

    if lang_code not in article.languages:
        # Se não tem idioma na URL mostra o artigo no idioma original.
        lang_code = article.original_language

    if not article.is_public:
        abort(404, ARTICLE_UNPUBLISH + _(article.unpublish_reason))

    if not article.issue.is_public:
        abort(404, ISSUE_UNPUBLISH + _(article.issue.unpublish_reason))

    if not article.journal.is_public:
        abort(404, JOURNAL_UNPUBLISH + _(article.journal.unpublish_reason))

    journal = article.journal
    issue = article.issue

    articles = controllers.get_articles_by_iid(issue.iid, is_public=True)

    article_list = [_article for _article in articles]

    previous_article = utils.get_prev_article(article_list, article)
    next_article = utils.get_next_article(article_list, article)

    if article.htmls:
        try:
            html = [html for html in article.htmls if html['lang'] == lang_code]
        except IndexError as e:
            abort(404, _('Artigo não encontrado'))
    else:
        html = None

    context = {
        'next_article': next_article,
        'previous_article': previous_article,
        'article': article,
        'journal': journal,
        'issue': issue,
        'html': html[0] if html else None,
        'pdfs': article.pdfs,
        'article_lang': lang_code
    }

    return render_template("article/detail.html", **context)
예제 #2
0
    def test_get_prev_article(self):
        """
        Teste da função utils.get_prev_article().
        """

        article1 = utils.makeOneArticle({'order': '1', })
        article2 = utils.makeOneArticle({'order': '2', })
        article3 = utils.makeOneArticle({'order': '3', })

        # criando uma lista de artigos ordenada
        articles = [article1, article2, article3]

        prev_article = wutils.get_prev_article(articles, article2)

        self.assertEqual(prev_article, article1)
예제 #3
0
    def test_get_prev_article_when_first_article(self):
        """
        Teste da função utils.get_prev_article(), quando é o primeiro artigo
        deve retorna None.
        """

        article1 = utils.makeOneArticle({'order': '1', })
        article2 = utils.makeOneArticle({'order': '2', })
        article3 = utils.makeOneArticle({'order': '3', })

        # criando uma lista de artigos ordenada
        articles = [article1, article2, article3]

        prev_article = wutils.get_prev_article(articles, article1)

        self.assertIsNone(prev_article)
예제 #4
0
파일: views.py 프로젝트: jamilatta/opac
def article_detail(url_seg, url_seg_issue, url_seg_article, lang_code=""):

    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _("Issue não encontrado"))

    article = controllers.get_article_by_issue_article_seg(issue.iid, url_seg_article)

    if not article:
        abort(404, _("Artigo não encontrado"))

    if lang_code not in article.languages:
        # Se não tem idioma na URL mostra o artigo no idioma original.
        lang_code = article.original_language

    if not article.is_public:
        abort(404, ARTICLE_UNPUBLISH + _(article.unpublish_reason))

    if not article.issue.is_public:
        abort(404, ISSUE_UNPUBLISH + _(article.issue.unpublish_reason))

    if not article.journal.is_public:
        abort(404, JOURNAL_UNPUBLISH + _(article.journal.unpublish_reason))

    journal = article.journal
    issue = article.issue

    articles = controllers.get_articles_by_iid(issue.iid, is_public=True)

    article_list = [_article for _article in articles]

    previous_article = utils.get_prev_article(article_list, article)
    next_article = utils.get_next_article(article_list, article)

    context = {
        "next_article": next_article,
        "previous_article": previous_article,
        "article": article,
        "journal": journal,
        "issue": issue,
        "article_lang": lang_code,
    }

    return render_template("article/detail.html", **context)
예제 #5
0
    def test_get_prev_article(self):
        """
        Teste da função utils.get_prev_article().
        """

        article1 = utils.makeOneArticle({
            'order': '1',
        })
        article2 = utils.makeOneArticle({
            'order': '2',
        })
        article3 = utils.makeOneArticle({
            'order': '3',
        })

        # criando uma lista de artigos ordenada
        articles = [article1, article2, article3]

        prev_article = wutils.get_prev_article(articles, article2)

        self.assertEqual(prev_article, article1)
예제 #6
0
    def test_get_prev_article_when_first_article(self):
        """
        Teste da função utils.get_prev_article(), quando é o primeiro artigo
        deve retorna None.
        """

        article1 = utils.makeOneArticle({
            'order': '1',
        })
        article2 = utils.makeOneArticle({
            'order': '2',
        })
        article3 = utils.makeOneArticle({
            'order': '3',
        })

        # criando uma lista de artigos ordenada
        articles = [article1, article2, article3]

        prev_article = wutils.get_prev_article(articles, article1)

        self.assertIsNone(prev_article)