From 20c676bfbb86a1b277f2cf80c0a9be9682544cf4 Mon Sep 17 00:00:00 2001 From: erikvw Date: Thu, 25 Jan 2024 19:29:13 -0600 Subject: [PATCH 1/2] move post migrate signals and autodiscover to edc_appconfig --- edc_action_item/action_item_notification.py | 2 +- edc_action_item/apps.py | 18 ------------------ edc_action_item/auths.py | 2 +- edc_action_item/models/signals.py | 2 +- edc_action_item/post_migrate_signals.py | 14 ++++++++++++++ edc_action_item/site_action_items.py | 8 +++++--- edc_action_item/system_checks.py | 13 +++++++------ .../tests/tests/test_action_notification.py | 2 +- 8 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 edc_action_item/post_migrate_signals.py diff --git a/edc_action_item/action_item_notification.py b/edc_action_item/action_item_notification.py index 8af8c46..45ee4cd 100644 --- a/edc_action_item/action_item_notification.py +++ b/edc_action_item/action_item_notification.py @@ -2,7 +2,7 @@ from django.core.exceptions import ObjectDoesNotExist from edc_constants.constants import CLOSED, NEW, OPEN -from edc_notification import Notification +from edc_notification.notification import Notification from edc_utils import get_utcnow NOTIFY_ON_NEW_AND_NO_REFERENCE_OBJ = "notify_on_new_and_no_reference_obj" diff --git a/edc_action_item/apps.py b/edc_action_item/apps.py index 520beea..47a8ab7 100644 --- a/edc_action_item/apps.py +++ b/edc_action_item/apps.py @@ -1,29 +1,11 @@ -import sys - from django.apps import AppConfig as DjangoApponfig from django.core.management.color import color_style -from django.db.models.signals import post_migrate - -from .site_action_items import site_action_items style = color_style() -def update_action_types(sender=None, verbose=None, **kwargs): # noqa - sys.stdout.write(style.MIGRATE_HEADING("Updating action types:\n")) - site_action_items.create_or_update_action_types() - sys.stdout.write("Done.\n") - sys.stdout.flush() - - class AppConfig(DjangoApponfig): name = "edc_action_item" verbose_name = "Action Items" has_exportable_data = True include_in_administration_section = True - - def ready(self): - post_migrate.connect(update_action_types, sender=self) - sys.stdout.write(f"Loading {self.verbose_name} ...\n") - site_action_items.autodiscover() - sys.stdout.write(f" Done loading {self.verbose_name}.\n") diff --git a/edc_action_item/auths.py b/edc_action_item/auths.py index 0a37b8c..2278d6f 100644 --- a/edc_action_item/auths.py +++ b/edc_action_item/auths.py @@ -1,4 +1,4 @@ -from edc_auth.auth_objects import ( +from edc_auth.constants import ( AUDITOR_ROLE, CLINICIAN_ROLE, CLINICIAN_SUPER_ROLE, diff --git a/edc_action_item/models/signals.py b/edc_action_item/models/signals.py index 52e7aad..e005bb2 100644 --- a/edc_action_item/models/signals.py +++ b/edc_action_item/models/signals.py @@ -4,7 +4,7 @@ from django.db.models.signals import m2m_changed, post_delete, post_save from django.dispatch import receiver from edc_constants.constants import CLOSED, NEW, OPEN -from edc_notification import site_notifications +from edc_notification.site_notifications import site_notifications from simple_history.signals import post_create_historical_record from ..utils import reset_and_delete_action_item diff --git a/edc_action_item/post_migrate_signals.py b/edc_action_item/post_migrate_signals.py new file mode 100644 index 0000000..a26ac88 --- /dev/null +++ b/edc_action_item/post_migrate_signals.py @@ -0,0 +1,14 @@ +import sys + +from django.core.management.color import color_style + +style = color_style() + + +def update_action_types(sender=None, verbose=None, **kwargs): # noqa + from .site_action_items import site_action_items + + sys.stdout.write(style.MIGRATE_HEADING("Updating action types:\n")) + site_action_items.create_or_update_action_types() + sys.stdout.write("Done.\n") + sys.stdout.flush() diff --git a/edc_action_item/site_action_items.py b/edc_action_item/site_action_items.py index 5d3e965..b29d6bd 100644 --- a/edc_action_item/site_action_items.py +++ b/edc_action_item/site_action_items.py @@ -9,8 +9,10 @@ from django.apps import apps as django_apps from django.core.management.color import color_style from django.utils.module_loading import module_has_submodule -from edc_notification import AlreadyRegistered as NotificationAlreadyRegistered -from edc_notification import site_notifications +from edc_notification.site_notifications import ( + AlreadyRegistered as NotificationAlreadyRegistered, +) +from edc_notification.site_notifications import site_notifications from edc_prn.prn import Prn from edc_prn.site_prn_forms import AlreadyRegistered as PrnAlreadyRegistered from edc_prn.site_prn_forms import site_prn_forms @@ -154,7 +156,7 @@ def autodiscover(module_name=None, verbose=True): try: before_import_registry = copy.copy(site_action_items.registry) import_module(f"{app}.{module_name}") - writer(f" * registered '{module_name}' from '{app}'\n") + writer(f" - registered '{module_name}' from '{app}'\n") except SiteActionError as e: writer(f" - loading {app}.{module_name} ... ") writer(style.ERROR(f"ERROR! {e}\n")) diff --git a/edc_action_item/system_checks.py b/edc_action_item/system_checks.py index bed108d..7cd1dc7 100644 --- a/edc_action_item/system_checks.py +++ b/edc_action_item/system_checks.py @@ -1,16 +1,17 @@ -from django.core.checks import Warning, register +from django.core.checks import Warning -from edc_action_item.site_action_items import site_action_items +from .site_action_items import site_action_items -@register() -def edc_notification_check(app_configs, **kwargs): # noqa +def edc_action_item_check(app_configs, **kwargs): errors = [] - for action_cls in site_action_items.registry.items(): + for name, action_cls in site_action_items.registry.items(): try: action_cls.reference_model_cls().history - except AttributeError: + except AttributeError as e: + if "history" not in str(e): + raise errors.append( Warning( ( diff --git a/edc_action_item/tests/tests/test_action_notification.py b/edc_action_item/tests/tests/test_action_notification.py index 18ca929..788aac3 100644 --- a/edc_action_item/tests/tests/test_action_notification.py +++ b/edc_action_item/tests/tests/test_action_notification.py @@ -3,7 +3,7 @@ from django.core import mail from django.test import TestCase from edc_constants.constants import NEW -from edc_notification import NewModelNotification, UpdatedModelNotification +from edc_notification.notification import NewModelNotification, UpdatedModelNotification from edc_notification.site_notifications import site_notifications from edc_action_item.action_item_notification import ( From 1c7ffd6e51812d2db8317ab5afb1e52d9f9621ee Mon Sep 17 00:00:00 2001 From: erikvw Date: Thu, 25 Jan 2024 19:37:22 -0600 Subject: [PATCH 2/2] move post migrate signals and autodiscover to edc_appconfig --- edc_action_item/tests/action_items.py | 2 ++ runtests.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/edc_action_item/tests/action_items.py b/edc_action_item/tests/action_items.py index ebc8568..86ebdfe 100644 --- a/edc_action_item/tests/action_items.py +++ b/edc_action_item/tests/action_items.py @@ -2,6 +2,7 @@ from ..action import Action from ..action_with_notification import ActionWithNotification +from ..models import ActionType from ..site_action_items import site_action_items @@ -150,6 +151,7 @@ class CrfLongitudinalOneAction(Action): def register_actions(): + ActionType.objects.all().delete() site_action_items.registry = {} site_action_items.register(FormZeroAction) site_action_items.register(FormOneAction) diff --git a/runtests.py b/runtests.py index b043d29..be27790 100644 --- a/runtests.py +++ b/runtests.py @@ -35,6 +35,8 @@ "edc_auth.apps.AppConfig", "edc_appointment.apps.AppConfig", "edc_crf.apps.AppConfig", + "edc_data_manager.apps.AppConfig", + "edc_form_runners.apps.AppConfig", "edc_facility.apps.AppConfig", "edc_lab.apps.AppConfig", "edc_navbar.apps.AppConfig", @@ -53,6 +55,7 @@ "edc_visit_tracking.apps.AppConfig", "edc_visit_schedule.apps.AppConfig", "edc_action_item.apps.AppConfig", + "edc_appconfig.apps.AppConfig", ], add_dashboard_middleware=True, use_test_urls=True,