Beispiel #1
0
def pressrelease(url_seg, url_seg_issue, url_seg_article, lang_code):
    journal = controllers.get_journal_by_url_seg(url_seg)

    issue = controllers.get_issue_by_url_seg(journal.url_segment, url_seg_issue)

    if url_seg_article:
        article = controllers.get_article_by_url_seg(url_seg_article)
    else:
        article = None

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

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

    press_release = controllers.get_press_release(journal, issue, lang_code, article)

    if not press_release:
        abort(404, _('Press Release não encontrado'))

    context = {
        'press_release': press_release
    }

    return render_template("includes/press_release.html", **context)
Beispiel #2
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'))

    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_pdf',
                                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))

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

    if not pdf_ssm_path:
        raise abort(404,
                    _('Recurso do Artigo não encontrado. Caminho inválido!'))
    else:
        return get_content_from_ssm(pdf_ssm_path)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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=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)
Beispiel #6
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)
Beispiel #7
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()
Beispiel #8
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()
Beispiel #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, e:
        feed_language = "pt"
Beispiel #10
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)
Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)