Exemplo n.º 1
0
def article_detail_pid(pid):

    article = controllers.get_article_by_pid(pid)

    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))
Exemplo n.º 2
0
def populate_pdfs_path_html_version(filename="fixtures/pdfs_path_file_html_version.json"):
    """
    Esse comando tem como responsabilidade enriquecer os registros de artigos com o caminho da URL do site anterior para os PDFs.

    Além do nome dos arquivos em PDF o site precisa dos caminhos dos PDFs para que seja possível resolver URLs como http://www.scielo.br/pdf/aa/v36n2/v36n2a09.pdf

    O arquivo ``fixtures/pdfs_path_file_html_version.json` é extraído uma única vez, contendo todos os PIDs da versão HTML, caminho dos PDFs e idioma.

    Estrutura do arquivo: ``pdfs_path_file_html_version.json``:

    [
      {
        "pid": "S0044-59672004000100001",
        "file_path": "/pdf/aa/v34n1/v34n1a01.pdf",
        "lang": "pt"
      },
    ]

    """

    with open(filename) as fp:

        data_json = json.load(fp)

    for art_pdf_path in data_json:

        art = controllers.get_article_by_pid(art_pdf_path['pid'])

        if art.pdfs:
            for pdf in art.pdfs:
                if art_pdf_path.get('lang', '') == pdf.get('lang'):
                    pdf['file_path'] = art_pdf_path.get('file_path')

            art.save()

            print("PDF do PID: %s atualizado com sucesso, caminho %s" % (art_pdf_path.get('pid'), art_pdf_path.get('file_path')))
        else:

            print("PDF do PID: %s não encontrado na base de dados do OPAC." % (art_pdf_path.get('pid')))
Exemplo n.º 3
0
def router_legacy():

    script_php = request.args.get('script', None)
    pid = request.args.get('pid', None)
    allowed_scripts = [
        'sci_serial', 'sci_issuetoc', 'sci_arttext', 'sci_abstract',
        'sci_issues', 'sci_pdf'
    ]
    if (script_php is not None) and (script_php
                                     in allowed_scripts) and not pid:
        # se tem pelo menos um param: pid ou script_php
        abort(
            400,
            _(u'Requsição inválida ao tentar acessar o artigo com pid: %s' %
              pid))
    elif script_php and pid:

        if script_php == 'sci_serial':
            # pid = issn
            journal = controllers.get_journal_by_issn(pid)

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

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

            return journal_detail(journal.url_segment)

        elif script_php == 'sci_issuetoc':

            issue = controllers.get_issue_by_pid(pid)

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

            return issue_toc(issue.journal.url_segment, issue.url_segment)

        elif script_php == 'sci_arttext' or script_php == 'sci_abstract':

            article = controllers.get_article_by_pid(pid)

            if not article:
                article = controllers.get_article_by_oap_pid(pid)

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

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

            return article_detail(article.journal.url_segment,
                                  article.issue.url_segment,
                                  article.url_segment)

        elif script_php == 'sci_issues':

            journal = controllers.get_journal_by_issn(pid)

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

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

            return issue_grid(journal.url_segment)

        elif script_php == 'sci_pdf':
            # accesso ao pdf do artigo:
            article = controllers.get_article_by_pid(pid)

            if not article:
                article = controllers.get_article_by_oap_pid(pid)

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

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

            return article_detail_pdf(article.journal.url_segment,
                                      article.issue.url_segment,
                                      article.url_segment)

        else:
            abort(
                400,
                _(u'Requsição inválida ao tentar acessar o artigo com pid: %s'
                  % pid))

    else:
        return redirect('/')
Exemplo n.º 4
0
def router_legacy():

    script_php = request.args.get('script')
    pid = request.args.get('pid')

    if not script_php or not pid:
        abort(404, _('Página não encontrado'))

    if script_php == 'sci_serial':

        # pid = issn
        journal = controllers.get_journal_by_issn(pid)

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

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

        return journal_detail(journal.url_segment)

    elif script_php == 'sci_issuetoc':

        issue = controllers.get_issue_by_pid(pid)

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

        return issue_toc(issue.journal.url_segment, issue.url_segment)

    elif script_php == 'sci_arttext' or script_php == 'sci_abstract':

        article = controllers.get_article_by_pid(pid)

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

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

        return article_detail(article.journal.url_segment,
                              article.issue.url_segment,
                              article.url_segment)

    elif script_php == 'sci_issues':

        journal = controllers.get_journal_by_issn(pid)

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

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

        return issue_grid(journal.url_segment)