Skip to content

Commit

Permalink
add system check to warn if email not enabled, typing hints
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 28, 2024
1 parent 1f76ca9 commit 2e14bc5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
45 changes: 24 additions & 21 deletions edc_action_item/action_with_notification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import Type, cast

from django.db import models

Expand All @@ -12,35 +12,38 @@ class ActionWithNotification(Action):
support for notifications.
"""

notification_email_to: List[str] = None
notification_email_to: list[str] = None
notification_display_name: str = None
notification_fields: List[str] = None
notification_super_cls = ActionItemNotification
notification_fields: list[str] = None
notification_super_cls: Type[ActionItemNotification] = ActionItemNotification
notify_on_changed_reference_obj: models.Model = True
notify_on_close: bool = False
notify_on_new: bool = False
notify_on_new_and_no_reference_obj: bool = True
notify_on_open: bool = False

@classmethod
def notification_cls(cls):
def notification_cls(cls) -> Type[ActionItemNotification]:
"""Returns a subclass of ActionItemModelNotification."""
return type(
f"{cls.__name__}Notification",
(cls.notification_super_cls,),
dict(
name=f"{cls.name}-notification",
notification_action_name=cls.name,
display_name=(
cls.notification_display_name or f"{cls.display_name} Notification"
return cast(
Type[ActionItemNotification],
type(
f"{cls.__name__}Notification",
(cls.notification_super_cls,),
dict(
name=f"{cls.name}-notification",
notification_action_name=cls.name,
display_name=(
cls.notification_display_name or f"{cls.display_name} Notification"
),
email_to=cls.notification_email_to,
notification_fields=cls.notification_fields,
model=cls.get_reference_model(),
notify_on_new_and_no_reference_obj=cls.notify_on_new_and_no_reference_obj,
notify_on_new=cls.notify_on_new,
notify_on_open=cls.notify_on_open,
notify_on_close=cls.notify_on_close,
notify_on_changed_reference_obj=cls.notify_on_changed_reference_obj,
),
email_to=cls.notification_email_to,
notification_fields=cls.notification_fields,
model=cls.get_reference_model(),
notify_on_new_and_no_reference_obj=cls.notify_on_new_and_no_reference_obj,
notify_on_new=cls.notify_on_new,
notify_on_open=cls.notify_on_open,
notify_on_close=cls.notify_on_close,
notify_on_changed_reference_obj=cls.notify_on_changed_reference_obj,
),
)
2 changes: 1 addition & 1 deletion edc_action_item/site_action_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def autodiscover(module_name=None, verbose=True):
except Exception as e:
raise SiteActionError(
f"{e.__class__.__name__} was raised when loading {module_name}. "
f"Got {e} See {app}.{module_name}"
f'Got "{e}" See {app}.{module_name}'
)


Expand Down
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
BASE_DIR=base_dir,
APP_NAME=app_name,
ETC_DIR=str(base_dir / app_name / "tests" / "etc"),
EMAIL_ENABLED=True,
SILENCED_SYSTEM_CHECKS=[
"edc_consent.E001",
"sites.E101",
Expand Down

0 comments on commit 2e14bc5

Please sign in to comment.