From 5a57164f343e7cc8dad9af9273b3ee33678fcf31 Mon Sep 17 00:00:00 2001 From: Roberta Takenaka <505143+robertatakenaka@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:45:15 -0300 Subject: [PATCH] =?UTF-8?q?Faz=20corre=C3=A7=C3=B5es=20na=20app=20journal:?= =?UTF-8?q?=20adiciona=20Journal.title,=20wagtail=5Fhooks.JournalCreateVie?= =?UTF-8?q?w,=20etc=20=20(#402)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- ...ner_page_remove_publisher_page_and_more.py | 51 +++++++++++++++++++ journal/models.py | 18 +++++-- journal/wagtail_hooks.py | 11 +++- 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 journal/migrations/0002_remove_owner_page_remove_publisher_page_and_more.py diff --git a/journal/migrations/0002_remove_owner_page_remove_publisher_page_and_more.py b/journal/migrations/0002_remove_owner_page_remove_publisher_page_and_more.py new file mode 100644 index 00000000..d17b893a --- /dev/null +++ b/journal/migrations/0002_remove_owner_page_remove_publisher_page_and_more.py @@ -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", + ), + ), + ] diff --git a/journal/models.py b/journal/models.py index 4fc5d935..e932d752 100644 --- a/journal/models.py +++ b/journal/models.py @@ -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, @@ -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 @@ -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): @@ -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: @@ -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) diff --git a/journal/wagtail_hooks.py b/journal/wagtail_hooks.py index 385b193e..2209a53a 100644 --- a/journal/wagtail_hooks.py +++ b/journal/wagtail_hooks.py @@ -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):