Skip to content

Commit

Permalink
Merge pull request #780 from samuelveigarangel/issue-771
Browse files Browse the repository at this point in the history
Melhoria no JournalSerializer: Cria Função get_scielo_journal para Mostrar ScieloJournal
  • Loading branch information
samuelveigarangel authored Jul 24, 2024
2 parents 183f6e9 + 84124a9 commit 1aa4724
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
3 changes: 2 additions & 1 deletion issue/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class IssueSerializer(serializers.ModelSerializer):
journal = serializers.SerializerMethodField()
sections = TocSectionsSerializer(many=True, read_only=True)
license = LicenseStatementSerializer(many=True, read_only=True)

class Meta:
model = models.Issue
fields = [
Expand Down Expand Up @@ -47,4 +47,5 @@ def get_journal(self, obj):
"issn_electronic": obj.journal.official.issn_electronic,
"issnl": obj.journal.official.issnl,
"scielo_journal": scielo_journal,
"collection_acron": obj.journal.scielojournal_set.first().collection.acron3,
}
46 changes: 38 additions & 8 deletions journal/api/v1/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from rest_framework import serializers
from collections import defaultdict

from core.api.v1.serializers import LanguageSerializer
from journal import models



class OfficialJournalSerializer(serializers.ModelSerializer):
class Meta:
model = models.OfficialJournal
Expand Down Expand Up @@ -43,7 +43,9 @@ class Meta:


class PublisherSerializer(serializers.ModelSerializer):
name = serializers.CharField(source='institution.institution.institution_identification.name')
name = serializers.CharField(
source="institution.institution.institution_identification.name"
)

class Meta:
model = models.PublisherHistory
Expand All @@ -53,8 +55,10 @@ class Meta:


class OwnerSerializer(serializers.ModelSerializer):
name = serializers.CharField(source='institution.institution.institution_identification.name')

name = serializers.CharField(
source="institution.institution.institution_identification.name"
)

class Meta:
model = models.OwnerHistory
fields = [
Expand All @@ -69,18 +73,45 @@ class JournalSerializer(serializers.ModelSerializer):
subject = SubjectSerializer(many=True, read_only=True)
text_language = LanguageSerializer(many=True, read_only=True)
journal_use_license = JournalUseLicenseSerializer(many=False, read_only=True)
publisher = PublisherSerializer(many=True, read_only=True, source="publisher_history")
publisher = PublisherSerializer(
many=True, read_only=True, source="publisher_history"
)
owner = OwnerSerializer(many=True, read_only=True, source="owner_history")
acronym = serializers.SerializerMethodField()

scielo_journal = serializers.SerializerMethodField()

def get_acronym(self, obj):
scielo_journal = obj.scielojournal_set.first()
return scielo_journal.journal_acron if scielo_journal else None

def get_scielo_journal(self, obj):
results = models.SciELOJournal.objects.filter(journal=obj).prefetch_related("journal_history")
journals = []
for item in results:
journal_dict = {
'collection_acron': item.collection.acron3,
'issn_scielo': item.issn_scielo,
'journal_acron': item.journal_acron,
'journal_history': [
{
'day': history.day,
'month': history.month,
'year': history.year,
'event_type': history.event_type,
'interruption_reason': history.interruption_reason,
} for history in item.journal_history.all()
],
}
journals.append(journal_dict)

return journals


class Meta:
model = models.Journal
fields = [
"official",
"scielo_journal",
"title",
"short_title",
"acronym",
Expand All @@ -90,5 +121,4 @@ class Meta:
"subject_descriptor",
"subject",
"text_language",

]
]
4 changes: 2 additions & 2 deletions journal/sources/am_to_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def update_logo(
try:
if journal_logo := JournalLogo.objects.filter(journal=journal).first():
journal.logo = journal_logo.logo
# else:
# tasks.fetch_and_process_journal_logo.apply_async(kwargs=dict(journal_id=journal.id))
else:
tasks.fetch_and_process_journal_logo.apply_async(kwargs=dict(journal_id=journal.id))

except Exception as e:
exc_type, exc_value, exc_traceback = sys.exc_info()
Expand Down

0 comments on commit 1aa4724

Please sign in to comment.