PEP fixes

This commit is contained in:
Matthias 2021-12-02 00:06:26 +01:00
parent 61b53a10b0
commit 50a046d3da
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -1,12 +1,18 @@
from django.utils.translation import ugettext_lazy as _ import logging
from datetime import timedelta
from django.template.loader import render_to_string from django.template.loader import render_to_string
from allauth.account.models import EmailAddress from allauth.account.models import EmailAddress
from InvenTree.helpers import inheritors from InvenTree.helpers import inheritors
from common.models import NotificationEntry
import InvenTree.tasks import InvenTree.tasks
logger = logging.getLogger('inventree')
# region notification classes # region notification classes
# region base classes # region base classes
class NotificationMethod: class NotificationMethod:
@ -14,7 +20,7 @@ class NotificationMethod:
def __init__(self, obj, entry_name, receivers) -> None: def __init__(self, obj, entry_name, receivers) -> None:
# check if a sending fnc is defined # check if a sending fnc is defined
if (not 'send' in self) and (not 'send_bulk' in self): if ('send' not in self) and ('send_bulk' not in self):
raise NotImplementedError('A NotificationMethod must either define a `send` or a `send_bulk` method') raise NotImplementedError('A NotificationMethod must either define a `send` or a `send_bulk` method')
# define arguments # define arguments
@ -42,6 +48,7 @@ class BulkNotificationMethod(NotificationMethod):
raise NotImplementedError('The `send` method must be overriden!') raise NotImplementedError('The `send` method must be overriden!')
# endregion # endregion
# region implementations # region implementations
class EmailNotification(BulkNotificationMethod): class EmailNotification(BulkNotificationMethod):
method_name = 'mail' method_name = 'mail'
@ -54,11 +61,11 @@ class EmailNotification(BulkNotificationMethod):
def send_bulk(self, context): def send_bulk(self, context):
# TODO: In the future, include the part image in the email template # TODO: In the future, include the part image in the email template
if not 'template' in context: if 'template' not in context:
raise NotImplementedError('Templates must be provided in the `context`') raise NotImplementedError('Templates must be provided in the `context`')
if not 'html' in context['template']: if 'html' not in context['template']:
raise NotImplementedError("template['html'] must be provided in the `context`") raise NotImplementedError("template['html'] must be provided in the `context`")
if not 'subject' in context['template']: if 'subject' not in context['template']:
raise NotImplementedError("template['subject'] must be provided in the `context`") raise NotImplementedError("template['subject'] must be provided in the `context`")
html_message = render_to_string(context['template']['html'], context) html_message = render_to_string(context['template']['html'], context)
@ -71,11 +78,7 @@ class EmailNotification(BulkNotificationMethod):
# endregion # endregion
def trigger_notifaction( def trigger_notifaction(obj, entry_name=None, obj_ref='pk', receivers=None, receiver_fnc=None, receiver_args=[], receiver_kwargs={}, notification_context={}):
obj, entry_name=None, obj_ref='pk',
receivers=None, receiver_fnc=None, receiver_args=[], receiver_kwargs={},
notification_context={}
):
""" """
Send out an notification Send out an notification
""" """
@ -94,7 +97,6 @@ def trigger_notifaction(
if not obj_ref_value: if not obj_ref_value:
raise KeyError(f"Could not resolve an object reference for '{str(obj)}' with {obj_ref}, pk, id") raise KeyError(f"Could not resolve an object reference for '{str(obj)}' with {obj_ref}, pk, id")
# Check if we have notified recently... # Check if we have notified recently...
delta = timedelta(days=1) delta = timedelta(days=1)