Skip to content

Commit

Permalink
Custumiza a representação de Journal nos Autocompletelabel (#897)
Browse files Browse the repository at this point in the history
* Altera metodo Journal.__str__

* customiza a representacao de Journal em SciELOJournalAdmin

* Improve Journal.__str__
  • Loading branch information
samuelveigarangel authored Dec 10, 2024
1 parent 68d637a commit b33d095
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion journal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,18 @@ def __unicode__(self):
return f"{self.title}" or f"{self.official}"

def __str__(self):
return f"{self.title}" or f"{self.official}"
active_collection = SciELOJournal.objects.filter(journal=self, collection__is_active=True)
collection_acronym = ", ".join(col.collection.acron3 for col in active_collection)

issns = []
if self.official.issn_print:
issns.append(f"Issn Print: {self.official.issn_print}")
if self.official.issn_electronic:
issns.append(f"Issn Electronic: {self.official.issn_electronic}")
issns = " - ".join(issns)

title = self.title or str(self.official)
return f"{title} ({collection_acronym}) | ({issns})"

base_form_class = CoreAdminModelForm

Expand Down
10 changes: 9 additions & 1 deletion journal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class SciELOJournalAdmin(ModelAdmin):
exclude_from_explorer = False

list_display = (
"journal",
"custom_journal",
"issn_scielo",
"journal_acron",
"collection",
Expand All @@ -132,6 +132,7 @@ class SciELOJournalAdmin(ModelAdmin):
"journal__title",
"issn_scielo",
)

def get_queryset(self, request):
qs = super().get_queryset(request)
user_groups = request.user.groups.values_list('name', flat=True)
Expand All @@ -141,6 +142,13 @@ def get_queryset(self, request):
return qs.filter(id__in=request.user.journal.all().values_list("id", flat=True))
return qs

def custom_journal(self, obj):
return f"{obj.journal.title}" or f"{obj.journal.official}"
custom_journal.short_description = "Journal"
custom_journal.admin_order_field = "journal"




class TOCSectionAdmin(ModelAdmin):
model = models.JournalTocSection
Expand Down

0 comments on commit b33d095

Please sign in to comment.