Esempio n. 1
0
    def test_get_articles_by_iid(self):
        """
        Testando a função controllers.get_articles_by_iid(), deve retorna uma
        lista de articles.
        """

        self._make_one(attrib={
            '_id': '012ijs9y24',
            'issue': '90210j83',
            'order': '14',
            'journal': 'oak,ajimn1'
        })
        self._make_one(attrib={
            '_id': '2183ikos90',
            'issue': '90210j83',
            'order': '12',
            'journal': 'oak,ajimn1'
        })
        self._make_one(attrib={
            '_id': '9298wjso89',
            'issue': '90210j82',
            'order': '13',
            'journal': 'oak,ajimn1'
        })

        expected = ['2183ikos90', '012ijs9y24', ]

        articles = [article.id for article in controllers.get_articles_by_iid('90210j83')]

        self.assertListEqual(articles, expected)
Esempio n. 2
0
    def test_get_articles_by_iid_from_continuous_publication_issue(self):
        """
        Testando a função controllers.get_articles_by_iid(), deve retorna uma
        lista de articles.
        """

        self._make_one(attrib={
            '_id': '012ijs9y24',
            'issue': '90210j83',
            'journal': 'oak,ajimn1',
            'publication_date': '2018-01-01',
        })

        self._make_one(attrib={
            '_id': '2183ikos90',
            'issue': '90210j83',
            'journal': 'oak,ajimn1',
            'publication_date': '2018-01-10',
        })

        self._make_one(attrib={
            '_id': '9298wjso89',
            'issue': '90210j83',
            'journal': 'oak,ajimn1',
            'publication_date': '2018-01-08',
        })

        expected = ['2183ikos90', '9298wjso89', '012ijs9y24', ]

        articles = [article.id for article in controllers.get_articles_by_iid('90210j83')]

        self.assertListEqual(articles, expected)
Esempio n. 3
0
def collection_list_feed():
    language = session.get('lang', get_locale())
    collection = controllers.get_current_collection()

    title = 'SciELO - %s - %s' % (collection.name,
                                  _('Últimos periódicos inseridos na coleção'))
    subtitle = _('10 últimos periódicos inseridos na coleção %s' %
                 collection.name)

    feed = AtomFeed(title,
                    subtitle=subtitle,
                    feed_url=request.url,
                    url=request.url_root)

    journals = controllers.get_journals_paginated(title_query='',
                                                  page=1,
                                                  order_by='-created',
                                                  per_page=10)

    if not journals.items:
        feed.add('Nenhum periódico encontrado',
                 url=request.url,
                 updated=datetime.now())

    for journal in journals.items:
        issues = controllers.get_issues_by_jid(journal.jid, is_public=True)
        last_issue = issues[0] if issues else None

        articles = []
        if last_issue:
            articles = controllers.get_articles_by_iid(last_issue.iid,
                                                       is_public=True)

        result_dict = OrderedDict()
        for article in articles:
            section = article.get_section_by_lang(language[:2])
            result_dict.setdefault(section, [])
            result_dict[section].append(article)

        context = {
            'journal': journal,
            'articles': result_dict,
            'language': language,
            'last_issue': last_issue
        }

        feed.add(journal.title,
                 render_template("collection/list_feed_content.html",
                                 **context),
                 content_type='html',
                 author=journal.publisher_name,
                 url=url_external('main.journal_detail',
                                  url_seg=journal.url_segment),
                 updated=journal.updated,
                 published=journal.created)

    return feed.get_response()
Esempio n. 4
0
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)
Esempio n. 5
0
def issue_toc(url_seg, url_seg_issue):
    default_lang = current_app.config.get('BABEL_DEFAULT_LOCALE')
    section_filter = request.args.get('section', '', type=str)

    if not session.get('lang'):
        lang = default_lang
    else:
        lang = session.get('lang')[:2]

    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _('Fascículo não encontrado'))

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

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

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

    if articles:
        sections = list(articles.item_frequencies('section').keys())
        sections = sorted([k for k in sections if k is not None])
    else:
        sections = []

    issues = controllers.get_issues_by_jid(journal.id, is_public=True)

    if section_filter != '':
        articles = articles.filter(section__iexact=section_filter)

    issue_list = [_issue for _issue in issues]

    previous_issue = utils.get_prev_issue(issue_list, issue)
    next_issue = utils.get_next_issue(issue_list, issue)

    context = {
                'next_issue': next_issue,
                'previous_issue': previous_issue,
                'journal': journal,
                'issue': issue,
                'articles': articles,
                'sections': sections,
                'section_filter': section_filter,
                # o primiero item da lista é o último fascículo.
                'last_issue': issues[0] if issues else None
               }

    return render_template("issue/toc.html", **context)
Esempio n. 6
0
def issue_toc(url_seg, url_seg_issue):
    default_lang = current_app.config.get("BABEL_DEFAULT_LOCALE")
    section_filter = request.args.get("section", "", type=unicode)

    if not session.get("lang"):
        lang = default_lang
    else:
        lang = session.get("lang")[:2]

    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _("Fascículo não encontrado"))

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

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

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

    if articles:
        sections = sorted(articles.item_frequencies("section").keys())
    else:
        sections = []

    issues = controllers.get_issues_by_jid(journal.id, is_public=True)

    if section_filter != "":
        articles = articles.filter(section__iexact=section_filter)

    issue_list = [_issue for _issue in issues]

    previous_issue = utils.get_prev_issue(issue_list, issue)
    next_issue = utils.get_next_issue(issue_list, issue)

    context = {
        "next_issue": next_issue,
        "previous_issue": previous_issue,
        "journal": journal,
        "issue": issue,
        "articles": articles,
        "sections": sections,
        "section_filter": section_filter,
        # o primiero item da lista é o último fascículo.
        "last_issue": issues[0] if issues else None,
    }

    return render_template("issue/toc.html", **context)
Esempio n. 7
0
def collection_list_feed():
    default_lang = current_app.config.get('BABEL_DEFAULT_LOCALE')
    language = session.get('lang', default_lang) or default_lang
    collection = controllers.get_current_collection()

    title = 'SciELO - %s - %s' % (collection.name, _('Últimos periódicos inseridos na coleção'))
    subtitle = _('10 últimos periódicos inseridos na coleção %s' % collection.name)

    feed = AtomFeed(title,
                    subtitle=subtitle,
                    feed_url=request.url, url=request.url_root)

    journals = controllers.get_journals_paginated(
        title_query='', page=1, order_by='-created', per_page=10)

    if not journals.items:
        feed.add('Nenhum periódico encontrado',
                 url=request.url,
                 updated=datetime.now())

    for journal in journals.items:
        issues = controllers.get_issues_by_jid(journal.jid, is_public=True)
        last_issue = issues[0] if issues else None

        articles = []
        if last_issue:
            articles = controllers.get_articles_by_iid(last_issue.iid,
                                                       is_public=True)

        result_dict = OrderedDict()
        for article in articles:
            section = article.get_section_by_lang(language[:2])
            result_dict.setdefault(section, [])
            result_dict[section].append(article)

        context = {
            'journal': journal,
            'articles': result_dict,
            'language': language,
            'last_issue': last_issue
        }

        feed.add(journal.title,
                 render_template("collection/list_feed_content.html", **context),
                 content_type='html',
                 author=journal.publisher_name,
                 url=url_external('main.journal_detail', url_seg=journal.url_segment),
                 updated=journal.updated,
                 published=journal.created)

    return feed.get_response()
Esempio n. 8
0
def collection_list_feed():
    default_lang = current_app.config.get("BABEL_DEFAULT_LOCALE")
    language = session.get("lang", default_lang) or default_lang
    collection = controllers.get_current_collection()

    title = "SciELO - %s - %s" % (collection.name, _("Últimos periódicos inseridos na coleção"))
    subtitle = _("10 últimos periódicos inseridos na coleção %s" % collection.name)

    feed = AtomFeed(
        title,
        subtitle=subtitle,
        logo=utils.get_resources_url(g.collection.logo_resource, "img", language),
        feed_url=request.url,
        url=request.url_root,
    )

    journals = controllers.get_journals_paginated(title_query="", page=1, order_by="-created", per_page=10)

    if not journals.items:
        feed.add("Nenhum periódico encontrado", url=request.url, updated=datetime.now())

    for journal in journals.items:
        issues = controllers.get_issues_by_jid(journal.jid, is_public=True)
        last_issue = issues[0] if issues else None

        articles = []
        if last_issue:
            articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True)

        result_dict = OrderedDict()
        for article in articles:
            section = article.get_section_by_lang(language[:2])
            result_dict.setdefault(section, [])
            result_dict[section].append(article)

        context = {"journal": journal, "articles": result_dict, "language": language, "last_issue": last_issue}

        feed.add(
            journal.title,
            render_template("collection/list_feed_content.html", **context),
            content_type="html",
            author=journal.publisher_name,
            url=url_external("main.journal_detail", url_seg=journal.url_segment),
            updated=journal.updated,
            published=journal.created,
        )

    return feed.get_response()
Esempio n. 9
0
def issue_feed(url_seg, url_seg_issue):
    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _('Fascículo não encontrado'))

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

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

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

    feed = AtomFeed(journal.title or "",
                    feed_url=request.url,
                    url=request.url_root,
                    subtitle=utils.get_label_issue(issue))

    # ######### TODO: Revisar/Melhorar/Consertar #########
    try:
        feed_language = session['lang'][:2].lower()
    except Exception as e:
        feed_language = 'pt'

    for article in articles:
        # ######### TODO: Revisar #########
        article_lang = feed_language
        if feed_language not in article.languages:
            article_lang = article.original_language

        feed.add(article.title or 'Unknow title',
                 render_template("issue/feed_content.html", article=article),
                 content_type='html',
                 author=article.authors,
                 url=url_external('main.article_detail',
                                  url_seg=journal.url_segment,
                                  url_seg_issue=issue.url_segment,
                                  url_seg_article=article.url_segment,
                                  lang_code=article_lang),
                 updated=journal.updated,
                 published=journal.created)

    return feed.get_response()
Esempio n. 10
0
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)
Esempio n. 11
0
    def test_get_articles_by_iid(self):
        """
        Testando a função controllers.get_articles_by_iid(), deve retorna uma
        lista de articles.
        """

        self._makeOne(attrib={'_id': '012ijs9y24', 'issue': '90210j83',
                              'journal': 'oak,ajimn1'})
        self._makeOne(attrib={'_id': '2183ikos90', 'issue': '90210j83',
                              'journal': 'oak,ajimn1'})
        self._makeOne(attrib={'_id': '9298wjso89', 'issue': '90210j82',
                              'journal': 'oak,ajimn1'})

        expected = ['012ijs9y24', '2183ikos90']

        articles = [article.id for article in controllers.get_articles_by_iid('90210j83')]

        self.assertListEqual(sorted(articles), sorted(expected))
Esempio n. 12
0
def issue_feed(url_seg, url_seg_issue):
    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _('Número não encontrado'))

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

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

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

    feed = AtomFeed(journal.title or "",
                    feed_url=request.url,
                    url=request.url_root,
                    subtitle=utils.get_label_issue(issue))

    feed_language = session.get('lang', get_locale())

    for article in articles:
        # ######### TODO: Revisar #########
        article_lang = feed_language
        if feed_language not in article.languages:
            article_lang = article.original_language

        feed.add(article.title or 'Unknow title',
                 render_template("issue/feed_content.html", article=article),
                 content_type='html',
                 author=article.authors,
                 id=article.doi or article.pid,
                 url=url_external('main.article_detail',
                                  url_seg=journal.url_segment,
                                  url_seg_issue=issue.url_segment,
                                  url_seg_article=article.url_segment,
                                  lang_code=article_lang),
                 updated=journal.updated,
                 published=journal.created)

    return feed.get_response()
Esempio n. 13
0
def journal_feed(url_seg):
    journal = controllers.get_journal_by_url_seg(url_seg)

    if not journal:
        abort(404, _('Periódico não encontrado'))

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

    issues = controllers.get_issues_by_jid(journal.jid, is_public=True)
    last_issue = issues[0] if issues else None
    articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True)

    feed = AtomFeed(journal.title,
                    feed_url=request.url,
                    url=request.url_root,
                    subtitle=utils.get_label_issue(last_issue))

    feed_language = session.get('lang', get_locale())
    feed_language = feed_language[:2].lower()

    for article in articles:

        # ######### TODO: Revisar #########
        article_lang = feed_language
        if feed_language not in article.languages:
            article_lang = article.original_language

        feed.add(article.title or _('Artigo sem título'),
                 render_template("issue/feed_content.html", article=article),
                 content_type='html',
                 id=article.doi or article.pid,
                 author=article.authors,
                 url=url_external('main.article_detail',
                                  url_seg=journal.url_segment,
                                  url_seg_issue=last_issue.url_segment,
                                  url_seg_article=article.url_segment,
                                  lang_code=article_lang),
                 updated=journal.updated,
                 published=journal.created)

    return feed.get_response()
Esempio n. 14
0
def router_legacy_pdf(journal_acron, issue_info, pdf_filename):
    language = session.get('lang', get_locale())
    pdf_filename = '%s.pdf' % pdf_filename

    journal = controllers.get_journal_by_acron(journal_acron)

    if not journal:
        abort(404, _('Periódico não encontrado'))

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

    # procuramos o issue filtrando pelo campo: assets_code e o journal
    issue = controllers.get_issue_by_journal_and_assets_code(
        assets_code=issue_info, journal=journal)

    if not issue:
        abort(404, _('Número não encontrado'))

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

    pdf_lang = language

    # procuramos entre os artigos, qual tem um pdf nesse idioma com esse filename
    article_match = None
    for article in controllers.get_articles_by_iid(iid=issue.iid):
        if article.pdfs:
            for pdf in article.pdfs:
                if pdf['url'].endswith(pdf_filename):
                    article_match = article
                    pdf_lang = pdf['lang']
                    break

    if article_match is None:
        abort(404, _('PDF do artigo não foi encontrado'))
    else:
        return article_detail_pdf(url_seg=journal.url_segment,
                                  url_seg_issue=issue.url_segment,
                                  url_seg_article=article_match.url_segment,
                                  lang_code=pdf_lang)
Esempio n. 15
0
def journal_feed(url_seg):
    journal = controllers.get_journal_by_url_seg(url_seg)

    if not journal:
        abort(404, _("Periódico não encontrado"))

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

    issues = controllers.get_issues_by_jid(journal.jid, is_public=True)
    last_issue = issues[0] if issues else None
    articles = controllers.get_articles_by_iid(last_issue.iid, is_public=True)

    feed = AtomFeed(
        journal.title, feed_url=request.url, url=request.url_root, subtitle=utils.get_label_issue(last_issue)
    )

    # ######### TODO: Revisar/Melhorar/Consertar #########
    try:
        feed_language = session["lang"][:2].lower()
    except Exception, e:
        feed_language = "pt"
Esempio n. 16
0
def issue_feed(url_seg, url_seg_issue):
    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if not issue:
        abort(404, _("Fascículo não encontrado"))

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

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

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

    feed = AtomFeed(
        journal.title or "", feed_url=request.url, url=request.url_root, subtitle=utils.get_label_issue(issue)
    )

    # ######### TODO: Revisar/Melhorar/Consertar #########
    try:
        feed_language = session["lang"][:2].lower()
    except Exception, e:
        feed_language = "pt"
Esempio n. 17
0
def article_detail(url_seg, url_seg_issue, url_seg_article, lang_code=''):
    article_url = url_for('main.article_detail',
                          url_seg=url_seg,
                          url_seg_issue=url_seg_issue,
                          url_seg_article=url_seg_article)

    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:
        article = controllers.get_article_by_aop_url_segs(
            issue.journal, url_seg_issue, url_seg_article)
        if not article:
            abort(404, _('Artigo não encontrado'))
        return redirect(
            url_for('main.article_detail',
                    url_seg=article.journal.acronym,
                    url_seg_issue=article.issue.url_segment,
                    url_seg_article=article.url_segment))

    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)

    pdf_urls_path = []

    if article.pdfs:
        try:
            pdf_urls = [pdf['url'] for pdf in article.pdfs]

            if not pdf_urls:
                abort(404, _('PDF do Artigo não encontrado'))
            else:
                pdf_urls_parsed = list(map(urlparse, pdf_urls))
                pdf_urls_path = [pdf.path for pdf in pdf_urls_parsed]

        except Exception:
            abort(404, _('PDF do Artigo não encontrado'))

    html_article = None

    text_versions = None
    if article.htmls:
        try:
            html_url = [
                html for html in article.htmls if html['lang'] == lang_code
            ]

            if len(html_url) != 1:
                abort(404, _('HTML do Artigo não encontrado'))
            else:
                html_url = html_url[0]['url']

            if html_url.startswith('http'):  # http:// ou https://
                html_url_parsed = urlparse(html_url)
                html_full_ssm_url = current_app.config[
                    'SSM_BASE_URI'] + html_url_parsed.path
            else:
                html_full_ssm_url = current_app.config[
                    'SSM_BASE_URI'] + html_url

            # Obtemos o html do SSM
            try:
                result = requests.get(html_full_ssm_url)
            except requests.exceptions.RequestException:
                abort(404, _('HTML do Artigo não encontrado ou indisponível'))
            else:
                if result.status_code == 200 and len(result.content) > 0:

                    # Criamos um objeto do tip soup
                    soup = BeautifulSoup(result.content.decode('utf-8'),
                                         'html.parser')

                    # Fatiamos o HTML pelo div com class: articleTxt
                    html_article = soup.find('div',
                                             {'id': 'standalonearticle'})
                else:
                    abort(404, _('Artigo não encontrado'))

        except IndexError:
            abort(404, _('Artigo não encontrado'))
        text_versions = sorted([(html['lang'],
                                 display_original_lang_name(html['lang']),
                                 url_for('main.article_detail',
                                         url_seg=journal.url_segment,
                                         url_seg_issue=issue.url_segment,
                                         url_seg_article=article.url_segment,
                                         lang_code=html['lang']))
                                for html in article.htmls])

    context = {
        'next_article':
        next_article,
        'previous_article':
        previous_article,
        'article':
        article,
        'journal':
        journal,
        'issue':
        issue,
        'html':
        html_article,
        'pdfs':
        article.pdfs,
        'pdf_urls_path':
        pdf_urls_path,
        'article_lang':
        lang_code,
        'text_versions':
        text_versions,
        'related_links':
        related_articles_urls.related_links(article_url, [article.title]),
    }

    return render_template("article/detail.html", **context)
Esempio n. 18
0
def issue_toc(url_seg, url_seg_issue):
    # idioma da sessão
    language = session.get('lang', get_locale())

    section_filter = request.args.get('section', '', type=str)

    issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)

    if issue and issue.journal:
        issue_legend = descriptive_short_format(
            title=issue.journal.title,
            short_title=issue.journal.short_title,
            pubdate=str(issue.year),
            volume=issue.volume,
            number=issue.number,
            suppl=issue.suppl_text,
            language=language[:2].lower())

    if not issue:
        abort(404, _('Número não encontrado'))

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

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

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

    if articles:
        sections = list(articles.item_frequencies('section').keys())
        sections = sorted([k for k in sections if k is not None])
    else:
        sections = []

    issues = controllers.get_issues_by_jid(journal.id, is_public=True)

    if section_filter != '':
        articles = articles.filter(section__iexact=section_filter)

    issue_list = [_issue for _issue in issues]

    previous_issue = utils.get_prev_issue(issue_list, issue)
    next_issue = utils.get_next_issue(issue_list, issue)

    for article in articles:
        article_text_languages = [doc['lang'] for doc in article.htmls]
        article_pdf_languages = [(doc['lang'], doc['url'])
                                 for doc in article.pdfs]

        setattr(article, "article_text_languages", article_text_languages)
        setattr(article, "article_pdf_languages", article_pdf_languages)

    context = {
        'next_issue': next_issue,
        'previous_issue': previous_issue,
        'journal': journal,
        'issue': issue,
        'issue_legend': issue_legend,
        'articles': articles,
        'sections': sections,
        'section_filter': section_filter,
        # o primiero item da lista é o último número.
        'last_issue': issues[0] if issues else None
    }

    return render_template("issue/toc.html", **context)
Esempio n. 19
0
def article_detail_pdf(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)

    pdf_ssm_path = None

    if article.pdfs:
        try:
            pdf_url = [pdf for pdf in article.pdfs if pdf['lang'] == lang_code]

            if len(pdf_url) != 1:
                abort(404, _('PDF do Artigo não encontrado'))
            else:
                pdf_url = pdf_url[0]['url']

            pdf_url_parsed = urlparse(pdf_url)
            pdf_ssm_path = pdf_url_parsed.path

        except Exception:
            abort(404, _('PDF do Artigo não encontrado'))
    else:
        abort(404, _('PDF do Artigo não encontrado'))

    context = {
        'next_article': next_article,
        'previous_article': previous_article,
        'article': article,
        'journal': journal,
        'issue': issue,
        'pdf_ssm_path': pdf_ssm_path,
        'pdfs': article.pdfs,
        'article_lang': lang_code
    }

    return render_template("article/detail_pdf.html", **context)
Esempio n. 20
0
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:
        article = controllers.get_article_by_aop_url_segs(
            issue.journal, url_seg_issue, url_seg_article)
    if not article:
        abort(404, _('Artigo não encontrado'))

    lang_code = lang_code or article.original_language
    if lang_code not in article.languages + [article.original_language]:
        # Se não é idioma válido, redireciona
        return redirect(url_for('main.article_detail',
                                url_seg=article.journal.url_segment,
                                url_seg_issue=article.issue.url_segment,
                                url_seg_article=article.url_segment,
                                lang_code=article.original_language),
                        code=301)

    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))

    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)

    pdf_urls_path = []

    if article.pdfs:
        try:
            pdf_urls = [pdf['url'] for pdf in article.pdfs]

            if not pdf_urls:
                abort(404, _('PDF do Artigo não encontrado'))
            else:
                pdf_urls_parsed = list(map(urlparse, pdf_urls))
                pdf_urls_path = [pdf.path for pdf in pdf_urls_parsed]

        except Exception:
            abort(404, _('PDF do Artigo não encontrado'))

    try:
        html, text_languages = render_html(article, lang_code)
    except (ValueError, NonRetryableError, RetryableError):
        abort(404, _('HTML do Artigo não encontrado ou indisponível'))

    text_versions = sorted([(lang, display_original_lang_name(lang),
                             url_for('main.article_detail',
                                     url_seg=article.journal.url_segment,
                                     url_seg_issue=article.issue.url_segment,
                                     url_seg_article=article.url_segment,
                                     lang_code=lang))
                            for lang in text_languages])
    context = {
        'next_article': next_article,
        'previous_article': previous_article,
        'article': article,
        'journal': article.journal,
        'issue': issue,
        'html': html,
        'pdfs': article.pdfs,
        'pdf_urls_path': pdf_urls_path,
        'article_lang': lang_code,
        'text_versions': text_versions,
        'related_links': controllers.related_links(article),
    }

    return render_template("article/detail.html", **context)