Skip to content

Commit

Permalink
Faz correções na app journal: adiciona Journal.title, wagtail_hooks.J…
Browse files Browse the repository at this point in the history
…ournalCreateView, etc (scieloorg#402)

* Adiciona Journal.title

* Modifica os atributos de journal.models.Owner e Publisher

* Cria journal.wagtail.JournalCreateView para adicionar o usuário como creator

* Adiciona migrações de banco de dados relacionados a journal
  • Loading branch information
robertatakenaka authored Mar 11, 2024
1 parent d8901eb commit 9e82f25
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 4.2.6 on 2024-03-11 11:23

from django.db import migrations, models
import django.db.models.deletion
import modelcluster.fields


class Migration(migrations.Migration):
dependencies = [
("journal", "0001_initial"),
]

operations = [
migrations.RemoveField(
model_name="owner",
name="page",
),
migrations.RemoveField(
model_name="publisher",
name="page",
),
migrations.AddField(
model_name="journal",
name="title",
field=models.CharField(
blank=True, max_length=265, null=True, verbose_name="Title"
),
),
migrations.AddField(
model_name="owner",
name="journal",
field=modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="owner",
to="journal.journal",
),
),
migrations.AddField(
model_name="publisher",
name="journal",
field=modelcluster.fields.ParentalKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="publisher",
to="journal.journal",
),
),
]
18 changes: 13 additions & 5 deletions journal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class Journal(CommonControlField, ClusterableModel):
short_title = models.CharField(
_("Short Title"), max_length=100, null=True, blank=True
)
title = models.CharField(
_("Title"), max_length=265, null=True, blank=True
)
official_journal = models.ForeignKey(
"OfficialJournal",
null=True,
Expand All @@ -136,10 +139,10 @@ class Journal(CommonControlField, ClusterableModel):
)

def __unicode__(self):
return self.short_title or str(self.official_journal)
return self.title or self.short_title or str(self.official_journal)

def __str__(self):
return self.short_title or str(self.official_journal)
return self.title or self.short_title or str(self.official_journal)

base_form_class = OfficialJournalForm

Expand All @@ -165,7 +168,7 @@ def __str__(self):
)

def autocomplete_label(self):
return self.official_journal.title
return self.title or self.official_journal.title

@property
def logo_url(self):
Expand All @@ -182,6 +185,8 @@ def create_or_update(
cls,
user,
official_journal=None,
title=None,
short_title=None,
):
logging.info(f"Journal.create_or_update({official_journal}")
try:
Expand All @@ -196,14 +201,17 @@ def create_or_update(
logging.info("create {}".format(obj))

obj.official_journal = official_journal or obj.official_journal
obj.title = title or obj.title
obj.short_title = short_title or obj.short_title

obj.save()
logging.info(f"return {obj}")
return obj


class Owner(Orderable, InstitutionHistory):
page = ParentalKey(Journal, related_name="owner")
journal = ParentalKey(Journal, related_name="owner", null=True, blank=True, on_delete=models.SET_NULL)


class Publisher(Orderable, InstitutionHistory):
page = ParentalKey(Journal, related_name="publisher")
journal = ParentalKey(Journal, related_name="publisher", null=True, blank=True, on_delete=models.SET_NULL)
11 changes: 9 additions & 2 deletions journal/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,23 @@ class OfficialJournalAdmin(ModelAdmin):
)


class JournalCreateView(CreateView):
def form_valid(self, form):
self.object = form.save_all(self.request.user)
return HttpResponseRedirect(self.get_success_url())


class JournalAdmin(ModelAdmin):
model = Journal
menu_label = _("Journal")
create_view_class = JournalCreateView
menu_icon = "folder"
menu_order = 200
add_to_settings_menu = False
exclude_from_explorer = False

list_display = ("official_journal", "short_title")
search_fields = ("official_journal__title", "short_title")
list_display = ("title", "short_title")
search_fields = ("official_journal__issn_electronic", "official_journal__issn_print", "short_title")


class JournalModelAdminGroup(ModelAdminGroup):
Expand Down

0 comments on commit 9e82f25

Please sign in to comment.