diff --git a/opac_schema/v1/models.py b/opac_schema/v1/models.py index 5632bfa..51da89e 100644 --- a/opac_schema/v1/models.py +++ b/opac_schema/v1/models.py @@ -924,6 +924,15 @@ def csl_json(self, site_domain="https://www.scielo.br"): data_parts = [self.issue.year, month] if month else [self.issue.year] + fpage_lpage = [] + if self.fpage != '' and self.fpage: + fpage_lpage.append(self.fpage) + + if self.lpage != '' and self.lpage: + fpage_lpage.append(self.lpage) + + page = self.elocation if self.elocation else "-".join(fpage_lpage) + return [ { "id": self._id, @@ -941,7 +950,7 @@ def csl_json(self, site_domain="https://www.scielo.br"): data_parts ] }, - "page": self.elocation, + "page": page, "publisher": self.journal.publisher_name, "title": self.title, "type": "article-journal", # This must in future equalize with https://github.com/scieloorg/scielo_publishing_schema/blob/master/docs/source/tagset/elemento-article.rst and https://github.com/citation-style-language/schema/wiki/Data-Model-and-Mappings diff --git a/setup.py b/setup.py index 3bd5afa..a43f4f9 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name="Opac Schema", - version='2.65', + version='2.66', description="Schema of SciELO OPAC", author="SciELO", author_email="dev@scielo.org", diff --git a/tests/test_article.py b/tests/test_article.py index cb4e6c9..eb41d61 100644 --- a/tests/test_article.py +++ b/tests/test_article.py @@ -591,7 +591,7 @@ def test_if_csl_json_property_return_correct_items(self): article_doc = Article(**article_data) article_doc.save() - self.assertEqual(article_doc.csl_json, [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola', 'given': 'Brígida'}, {'family': 'Frota', 'given': 'Maria Myrian Melo'}, {'family': 'Oliveira', 'given': 'André Gadelha de'}, {'family': 'Uchôa', 'given': 'Kênio Monteles'}, {'family': 'Leandro Filho', 'given': 'Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola', 'given': 'Brígida'}, {'family': 'Frota', 'given': 'Maria Myrian Melo'}, {'family': 'Oliveira', 'given': 'André Gadelha de'}, {'family': 'Uchôa', 'given': 'Kênio Monteles'}, {'family': 'Leandro Filho', 'given': 'Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) def test_if_csl_json_property_return_correct_without_common_on_authors(self): journal_doc = self._create_dummy_journal() @@ -619,7 +619,7 @@ def test_if_csl_json_property_return_correct_without_common_on_authors(self): article_doc = Article(**article_data) - self.assertEqual(article_doc.csl_json, [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) def test_if_csl_json_property_return_correct_without_authors(self): journal_doc = self._create_dummy_journal() @@ -641,7 +641,7 @@ def test_if_csl_json_property_return_correct_without_authors(self): article_doc = Article(**article_data) - self.assertEqual(article_doc.csl_json, [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) def test_if_csl_json_property_return_correct_with_empty_authors(self): journal_doc = self._create_dummy_journal() @@ -663,4 +663,174 @@ def test_if_csl_json_property_return_correct_with_empty_authors(self): article_doc = Article(**article_data) - self.assertEqual(article_doc.csl_json, [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': '', 'given': ''}, {'family': '', 'given': ''}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) \ No newline at end of file + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': '', 'given': ''}, {'family': '', 'given': ''}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '@location', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_preferably_elocation_on_page(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'pid': "S0101-02022019000300123", + 'elocation': "e123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': 'e123', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_empty_page_with_empty_elocation_fpage_lpage(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'pid': "S0101-02022019000300123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_empty_page_with_empty_elocation_lpage(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'fpage': '100', + 'pid': "S0101-02022019000300123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '100', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_empty_page_with_empty_elocation_fpage(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'lpage': '200', + 'pid': "S0101-02022019000300123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '200', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_empty_page_with_empty_elocation(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'fpage': '100', + 'lpage': '200', + 'pid': "S0101-02022019000300123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': '100-200', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) + + def test_if_csl_json_property_return_empty_page_with_elocation_fpage_lpage(self): + journal_doc = self._create_dummy_journal() + issue_doc = self._create_dummy_issue(journal_doc) + + article_data = { + '_id': "2918f62938de499ba0af74932d0fbee5", + 'aid': "2918f62938de499ba0af74932d0fbee5", + 'is_public': True, + 'title': "Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome", + 'type': "case-report", + 'doi': "10.1590/2175-8239-JBN-2020-0050", + 'journal': journal_doc, + 'issue': issue_doc, + 'elocation': 'e987', + 'fpage': '100', + 'lpage': '200', + 'pid': "S0101-02022019000300123", + 'authors': [ + "Miola Brígida", + "Frota Maria Myrian Melo", + "Oliveira André Gadelha de", + "Uchôa Kênio Monteles", + "Leandro Filho Francisco de Assis" + ] + } + + article_doc = Article(**article_data) + + self.assertEqual(article_doc.csl_json(), [{'id': '2918f62938de499ba0af74932d0fbee5', 'DOI': '10.1590/2175-8239-JBN-2020-0050', 'URL': 'https://doi.org/10.1590/2175-8239-JBN-2020-0050', 'ISSN': '2179-975X', 'author': [{'family': 'Miola Brígida', 'given': 'Miola Brígida'}, {'family': 'Frota Maria Myrian Melo', 'given': 'Frota Maria Myrian Melo'}, {'family': 'Oliveira André Gadelha de', 'given': 'Oliveira André Gadelha de'}, {'family': 'Uchôa Kênio Monteles', 'given': 'Uchôa Kênio Monteles'}, {'family': 'Leandro Filho Francisco de Assis', 'given': 'Leandro Filho Francisco de Assis'}], 'container-title': 'Acta Amazonica', 'container-title-short': 'Acta Amaz.', 'issue': 'Acta Amaz., 2018 123(9999)', 'issued': {'date-parts': [[2018, 9]]}, 'page': 'e987', 'publisher': 'Instituto Nacional de Pesquisas da Amazônia', 'title': 'Nephrotic syndrome associated with primary atypical hemolytic uremic syndrome', 'type': 'article-journal', 'volume': '123'}]) \ No newline at end of file