diff --git a/article/migrations/0012_alter_article_publisher.py b/article/migrations/0012_alter_article_publisher.py new file mode 100644 index 00000000..e9668900 --- /dev/null +++ b/article/migrations/0012_alter_article_publisher.py @@ -0,0 +1,26 @@ +# Generated by Django 5.0.3 on 2024-04-19 18:23 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("article", "0011_alter_article_options"), + ("institution", "0005_institution_institution_type_scielo_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="article", + name="publisher", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="institution.publisher", + verbose_name="Publisher", + ), + ), + ] diff --git a/article/models.py b/article/models.py index f4cb4166..1b7f4d65 100755 --- a/article/models.py +++ b/article/models.py @@ -27,7 +27,7 @@ ) from doi.models import DOI from doi_manager.models import CrossRefConfiguration -from institution.models import Institution, Sponsor +from institution.models import Sponsor, Publisher from issue.models import Issue, TocSection from journal.models import Journal, SciELOJournal from pid_provider.provider import PidProvider @@ -87,7 +87,7 @@ class Article(CommonControlField, ClusterableModel): elocation_id = models.CharField(max_length=64, null=True, blank=True) keywords = models.ManyToManyField(Keyword, blank=True) publisher = models.ForeignKey( - Institution, + Publisher, verbose_name=_("Publisher"), null=True, blank=True, diff --git a/article/scripts/load_article.py b/article/scripts/load_article.py index ed91d78a..a26a7efd 100644 --- a/article/scripts/load_article.py +++ b/article/scripts/load_article.py @@ -9,4 +9,4 @@ def run(user_id=None, file_path=None): # Xml usado para testes. file_path = file_path or "article/fixtures/0034-7094-rba-69-03-0227.xml" - load_article.apply_async(args=(user_id, file_path)) + load_article.apply_async(kwargs=dict(user_id=user_id, file_path=file_path)) diff --git a/article/search_indexes.py b/article/search_indexes.py index 04b285e8..7988e5a9 100644 --- a/article/search_indexes.py +++ b/article/search_indexes.py @@ -336,7 +336,8 @@ def prepare_titles(self, obj): def prepare_creator(self, obj): if obj.researchers: - return [researcher for researcher in obj.researchers.all()] + researchers = obj.researchers.select_related('person_name').filter(person_name__isnull=False) + return [str(researcher) for researcher in researchers] def prepare_collab(self, obj): if obj.collab: diff --git a/article/sources/xmlsps.py b/article/sources/xmlsps.py index f3261ac7..08ef48fe 100755 --- a/article/sources/xmlsps.py +++ b/article/sources/xmlsps.py @@ -16,6 +16,7 @@ from packtools.sps.models.front_articlemeta_issue import ArticleMetaIssue from packtools.sps.models.funding_group import FundingGroup from packtools.sps.models.journal_meta import ISSN, Title +from packtools.sps.models import journal_meta from packtools.sps.models.kwd_group import ArticleKeywords from packtools.sps.pid_provider.xml_sps_lib import XMLWithPre @@ -24,7 +25,7 @@ from core.forms import CoreAdminModelForm from core.models import Language, License, LicenseStatement from doi.models import DOI -from institution.models import Sponsor +from institution.models import Sponsor, Publisher from issue.models import Issue, TocSection from journal.models import Journal, OfficialJournal from researcher.exceptions import PersonNameCreateError @@ -119,6 +120,7 @@ def load_article(user, xml=None, file_path=None, v3=None): article.license = ls.license article.save() break + article.publisher = get_or_create_publisher(xmltree=xmltree, user=user, item=pid_v3) article.valid = True article.save() except Exception as e: @@ -167,6 +169,37 @@ def get_journal(xmltree): return None +def get_or_create_publisher(xmltree, user, item): + try: + publisher_names = journal_meta.Publisher(xmltree=xmltree).publishers_names + if publisher_names: + return Publisher.get_or_create( + user=user, + name=publisher_names[0], + acronym=None, + level_1=None, + level_2=None, + level_3=None, + location=None, + official=None, + is_official=None, + url=None, + institution_type=None, + ) + except Exception as e: + exc_type, exc_value, exc_traceback = sys.exc_info() + UnexpectedEvent.create( + item=item, + action="article.xmlsps.get_or_create_publisher", + exception=e, + exc_traceback=exc_traceback, + detail=dict( + function="article.xmlsps.get_or_create_publisher", + publisher_name=publisher_names, + ), + ) + + def get_or_create_fundings(xmltree, user, item): """ Ex fundings_group: diff --git a/article/templates/search/indexes/article/article_compile.txt b/article/templates/search/indexes/article/article_compile.txt index c39d3567..4cccefa2 100644 --- a/article/templates/search/indexes/article/article_compile.txt +++ b/article/templates/search/indexes/article/article_compile.txt @@ -16,7 +16,7 @@ {% for research in object.researchers.all %} - {{research.given_names}} {{research.last_name}} + {{research.person_name}} {% endfor %} diff --git a/researcher/wagtail_hooks.py b/researcher/wagtail_hooks.py index 790185cb..04dab247 100644 --- a/researcher/wagtail_hooks.py +++ b/researcher/wagtail_hooks.py @@ -30,8 +30,8 @@ class ResearcherAdmin(ModelAdmin): search_fields = ( "person_name__fullname", "person_name__declared_name", - "affiliation__institution__name", - "affiliation__institution__acronym", + "affiliation__institution__institution_identification__name", + "affiliation__institution__institution_identification__acronym", )