mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
rename to be clearer what the funtions and vars are fore
This commit is contained in:
parent
01ad534664
commit
373c061389
@ -36,8 +36,8 @@ class NotificationMethod:
|
|||||||
self.targets = targets
|
self.targets = targets
|
||||||
self.context = self.check_context(context)
|
self.context = self.check_context(context)
|
||||||
|
|
||||||
# Gather recipients
|
# Gather targets
|
||||||
self.recipients = self.get_recipients()
|
self.targets = self.get_targets()
|
||||||
|
|
||||||
def check_context(self, context):
|
def check_context(self, context):
|
||||||
def check(ref, obj):
|
def check(ref, obj):
|
||||||
@ -74,8 +74,8 @@ class NotificationMethod:
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_recipients(self):
|
def get_targets(self):
|
||||||
raise NotImplementedError('The `get_recipients` method must be implemented!')
|
raise NotImplementedError('The `get_targets` method must be implemented!')
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
return True
|
return True
|
||||||
@ -107,23 +107,23 @@ class EmailNotification(BulkNotificationMethod):
|
|||||||
('template', 'subject', ),
|
('template', 'subject', ),
|
||||||
]
|
]
|
||||||
|
|
||||||
def get_recipients(self):
|
def get_targets(self):
|
||||||
return EmailAddress.objects.filter(
|
return EmailAddress.objects.filter(
|
||||||
user__in=self.targets,
|
user__in=self.targets,
|
||||||
)
|
)
|
||||||
|
|
||||||
def send_bulk(self):
|
def send_bulk(self):
|
||||||
html_message = render_to_string(self.context['template']['html'], self.context)
|
html_message = render_to_string(self.context['template']['html'], self.context)
|
||||||
recipients = self.recipients.values_list('email', flat=True)
|
targets = self.targets.values_list('email', flat=True)
|
||||||
|
|
||||||
InvenTree.tasks.send_email(self.context['template']['subject'], '', recipients, html_message=html_message)
|
InvenTree.tasks.send_email(self.context['template']['subject'], '', targets, html_message=html_message)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class UIMessageNotification(SingleNotificationMethod):
|
class UIMessageNotification(SingleNotificationMethod):
|
||||||
METHOD_NAME = 'ui_message'
|
METHOD_NAME = 'ui_message'
|
||||||
|
|
||||||
def get_recipients(self):
|
def get_targets(self):
|
||||||
return self.targets
|
return self.targets
|
||||||
|
|
||||||
def send(self, target):
|
def send(self, target):
|
||||||
@ -201,7 +201,7 @@ def deliver_notification(cls: NotificationMethod, obj, category: str, targets, c
|
|||||||
# Init delivery method
|
# Init delivery method
|
||||||
method = cls(obj, category, targets, context)
|
method = cls(obj, category, targets, context)
|
||||||
|
|
||||||
if method.recipients and len(method.recipients) > 0:
|
if method.targets and len(method.targets) > 0:
|
||||||
# Log start
|
# Log start
|
||||||
logger.info(f"Notify users via '{method.METHOD_NAME}' for notification '{category}' for '{str(obj)}'")
|
logger.info(f"Notify users via '{method.METHOD_NAME}' for notification '{category}' for '{str(obj)}'")
|
||||||
|
|
||||||
@ -214,11 +214,11 @@ def deliver_notification(cls: NotificationMethod, obj, category: str, targets, c
|
|||||||
# Select delivery method and execute it
|
# Select delivery method and execute it
|
||||||
if hasattr(method, 'send_bulk'):
|
if hasattr(method, 'send_bulk'):
|
||||||
success = method.send_bulk()
|
success = method.send_bulk()
|
||||||
success_count = len(method.recipients)
|
success_count = len(method.targets)
|
||||||
|
|
||||||
elif hasattr(method, 'send'):
|
elif hasattr(method, 'send'):
|
||||||
for rec in method.recipients:
|
for target in method.targets:
|
||||||
if method.send(rec):
|
if method.send(target):
|
||||||
success_count += 1
|
success_count += 1
|
||||||
else:
|
else:
|
||||||
success = False
|
success = False
|
||||||
|
Loading…
Reference in New Issue
Block a user