From 56de002c47ca4701ca197de5ca731d483e27847f Mon Sep 17 00:00:00 2001 From: Roberta Takenaka Date: Sun, 30 Jul 2023 17:30:01 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20importa=C3=A7=C3=B5es=20de=20m=C3=B3d?= =?UTF-8?q?ulos=20do=20wagtail=20que=20ficar=C3=A3o=20obsoletos=20(#298)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Aplica black * Remove espaços no início e no fim no XML ao obter XMLWithPre * Troca wagtail.admin.edit_handlers por wagtail.admin.panels * Troca DocumentChooserPanel por FieldPanel * Corrige importação de wagtail core e hooks --- article/utils/parse_name_author.py | 4 ++-- book/models.py | 2 +- book/utils/utils.py | 4 ++-- doi/models.py | 2 +- pid_provider/wagtail_hooks.py | 14 +++----------- researcher/models.py | 11 ++++------- researcher/wagtail_hooks.py | 2 +- xmlsps/models.py | 6 ++---- xmlsps/wagtail_hooks.py | 4 +--- xmlsps/xml_sps_lib.py | 3 ++- 10 files changed, 19 insertions(+), 33 deletions(-) diff --git a/article/utils/parse_name_author.py b/article/utils/parse_name_author.py index dbc8674f..bbd8fed9 100644 --- a/article/utils/parse_name_author.py +++ b/article/utils/parse_name_author.py @@ -1,4 +1,4 @@ -import re +import re def parse_author_name(name): @@ -9,4 +9,4 @@ def parse_author_name(name): if match: return {"given_names": match.group(2), "surname": match.group(1)} else: - return {"declared_name": name} \ No newline at end of file + return {"declared_name": name} diff --git a/book/models.py b/book/models.py index c23f38c3..587bd4fa 100644 --- a/book/models.py +++ b/book/models.py @@ -2,7 +2,7 @@ from django.utils.translation import gettext as _ from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail.admin.edit_handlers import ( +from wagtail.admin.panels import ( FieldPanel, InlinePanel, ObjectList, diff --git a/book/utils/utils.py b/book/utils/utils.py index dbc8674f..bbd8fed9 100644 --- a/book/utils/utils.py +++ b/book/utils/utils.py @@ -1,4 +1,4 @@ -import re +import re def parse_author_name(name): @@ -9,4 +9,4 @@ def parse_author_name(name): if match: return {"given_names": match.group(2), "surname": match.group(1)} else: - return {"declared_name": name} \ No newline at end of file + return {"declared_name": name} diff --git a/doi/models.py b/doi/models.py index 68f80a12..6a5ac8f4 100755 --- a/doi/models.py +++ b/doi/models.py @@ -1,6 +1,6 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from wagtail.admin.edit_handlers import FieldPanel +from wagtail.admin.panels import FieldPanel from core.choices import LANGUAGE from core.forms import CoreAdminModelForm diff --git a/pid_provider/wagtail_hooks.py b/pid_provider/wagtail_hooks.py index e0bbf3ab..b9389ec3 100644 --- a/pid_provider/wagtail_hooks.py +++ b/pid_provider/wagtail_hooks.py @@ -64,9 +64,7 @@ class PidProviderXMLAdmin(ModelAdmin): "aop_pid", "main_doi", ) - list_filter = ( - "article_pub_year", - ) + list_filter = ("article_pub_year",) search_fields = ( "journal__title", "pkg_name", @@ -100,9 +98,7 @@ class PidChangeAdmin(ModelAdmin): "new", "pid_type", ) - list_filter = ( - "pid_type", - ) + list_filter = ("pid_type",) search_fields = ( "old", "new", @@ -113,11 +109,7 @@ class PidProviderAdminGroup(ModelAdminGroup): menu_label = _("Pid Provider") menu_icon = "folder-open-inverse" # change as required menu_order = 100 # will put in 3rd place (000 being 1st, 100 2nd) - items = ( - PidProviderXMLAdmin, - PidRequestAdmin, - PidChangeAdmin - ) + items = (PidProviderXMLAdmin, PidRequestAdmin, PidChangeAdmin) modeladmin_register(PidProviderAdminGroup) diff --git a/researcher/models.py b/researcher/models.py index 05050ec0..40e7e036 100644 --- a/researcher/models.py +++ b/researcher/models.py @@ -2,9 +2,8 @@ from django.utils.translation import gettext_lazy as _ from modelcluster.fields import ParentalKey from modelcluster.models import ClusterableModel -from wagtail.admin.edit_handlers import FieldPanel, InlinePanel, MultiFieldPanel -from wagtail.core.models import Orderable -from wagtail.documents.edit_handlers import DocumentChooserPanel +from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel +from wagtail.models import Orderable from wagtailautocomplete.edit_handlers import AutocompletePanel from core.models import CommonControlField, Gender @@ -23,9 +22,7 @@ class Researcher(ClusterableModel, CommonControlField): given_names = models.CharField( _("Given names"), max_length=128, blank=True, null=True ) - last_name = models.CharField( - _("Last name"), max_length=128, blank=True, null=True - ) + last_name = models.CharField(_("Last name"), max_length=128, blank=True, null=True) declared_name = models.CharField( _("Declared Name"), max_length=255, blank=True, null=True ) @@ -263,4 +260,4 @@ class EditorialBoardMemberFile(models.Model): def filename(self): return os.path.basename(self.attachment.name) - panels = [DocumentChooserPanel("attachment")] + panels = [FieldPanel("attachment")] diff --git a/researcher/wagtail_hooks.py b/researcher/wagtail_hooks.py index 83ac3e7e..bc4a1c7c 100644 --- a/researcher/wagtail_hooks.py +++ b/researcher/wagtail_hooks.py @@ -7,7 +7,7 @@ modeladmin_register, ) from wagtail.contrib.modeladmin.views import CreateView -from wagtail.core import hooks +from wagtail import hooks from .button_helper import EditorialBoardMemberHelper from .models import EditorialBoardMember, EditorialBoardMemberFile, Researcher diff --git a/xmlsps/models.py b/xmlsps/models.py index 9901b55b..30b00c00 100644 --- a/xmlsps/models.py +++ b/xmlsps/models.py @@ -213,11 +213,9 @@ def __str__(self): @classmethod def get_or_create(cls, journal, volume, number, suppl, pub_year): if journal is None: - raise XMLIssueGetOrCreateError( - f"XMLIssue.get_or_create requires journal") + raise XMLIssueGetOrCreateError(f"XMLIssue.get_or_create requires journal") if pub_year is None: - raise XMLIssueGetOrCreateError( - f"XMLIssue.get_or_create requires pub_year") + raise XMLIssueGetOrCreateError(f"XMLIssue.get_or_create requires pub_year") try: return cls.objects.get( journal=journal, diff --git a/xmlsps/wagtail_hooks.py b/xmlsps/wagtail_hooks.py index 5a1dda30..eaeed18f 100644 --- a/xmlsps/wagtail_hooks.py +++ b/xmlsps/wagtail_hooks.py @@ -27,9 +27,7 @@ class XMLSPSAdmin(ModelAdmin): "is_published", "pid_v3", ) - list_filter = ( - "is_published", - ) + list_filter = ("is_published",) search_fields = ( "pid_v3", "pid_v2", diff --git a/xmlsps/xml_sps_lib.py b/xmlsps/xml_sps_lib.py index c08225ee..fb3a2f5f 100644 --- a/xmlsps/xml_sps_lib.py +++ b/xmlsps/xml_sps_lib.py @@ -187,6 +187,7 @@ def get_xml_with_pre_from_uri(uri, timeout=30): def get_xml_with_pre(xml_content): try: + xml_content = xml_content.strip() # return etree.fromstring(xml_content) pref, xml = split_processing_instruction_doctype_declaration_and_xml( xml_content @@ -194,7 +195,7 @@ def get_xml_with_pre(xml_content): return XMLWithPre(pref, etree.fromstring(xml)) except Exception as e: - if xml_content.strip(): + if xml_content: raise GetXmlWithPreError( "Unable to get xml with pre %s: %s ... %s" % (e, xml_content[:100], xml_content[-200:])