More docstrings

This commit is contained in:
Matthias 2022-05-29 03:17:11 +02:00
parent 8d5f229000
commit cddead457f
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093
6 changed files with 21 additions and 4 deletions

View File

@ -12,6 +12,7 @@ class ActionMixin:
MIXIN_NAME = 'Actions'
def __init__(self):
"""Register mixin."""
super().__init__()
self.add_mixin('action', True, __class__)

View File

@ -40,6 +40,7 @@ class BarcodeMixin:
MIXIN_NAME = 'Barcode'
def __init__(self):
"""Register mixin."""
super().__init__()
self.add_mixin('barcode', 'has_barcode', __class__)

View File

@ -17,6 +17,7 @@ class LabelPrintingMixin:
MIXIN_NAME = 'Label printing'
def __init__(self): # pragma: no cover
"""Register mixin."""
super().__init__()
self.add_mixin('labels', True, __class__)

View File

@ -11,13 +11,16 @@ class SimpleActionPlugin(ActionMixin, InvenTreePlugin):
ACTION_NAME = "simple"
def perform_action(self, user=None, data=None):
"""Sample method."""
print("Action plugin in action!")
def get_info(self, user, data=None):
"""Sample method."""
return {
"user": user.username,
"hello": "world",
}
def get_result(self, user=None, data=None):
"""Sample method."""
return True

View File

@ -18,12 +18,14 @@ from stock.models import StockItem, StockLocation
class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
"""Builtin BarcodePlugin for matching and generating internal barcodes."""
NAME = "InvenTreeBarcode"
def validate(self):
"""An "InvenTree" barcode must be a jsonnable-dict with the following tags:
"""Validate a barcode.
An "InvenTree" barcode must be a jsonnable-dict with the following tags:
{
'tool': 'InvenTree',
'version': <anything>
@ -52,7 +54,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return True
def getStockItem(self):
"""Lookup StockItem by 'stockitem' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'stockitem':
@ -81,7 +83,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return None
def getStockLocation(self):
"""Lookup StockLocation by 'stocklocation' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'stocklocation':
@ -109,7 +111,7 @@ class InvenTreeBarcodePlugin(BarcodeMixin, InvenTreePlugin):
return None
def getPart(self):
"""Lookup Part by 'part' key in barcode data."""
for k in self.data.keys():
if k.lower() == 'part':

View File

@ -11,7 +11,13 @@ from plugin.mixins import BulkNotificationMethod, SettingsMixin
class PlgMixin:
"""Mixin to access plugin easier.
This needs to be spit out to reference the class. Perks of python.
"""
def get_plugin(self):
"""Return plugin reference."""
return CoreNotificationsPlugin
@ -32,6 +38,8 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
}
class EmailNotification(PlgMixin, BulkNotificationMethod):
"""Notificationmethod for delivery via Email."""
METHOD_NAME = 'mail'
METHOD_ICON = 'fa-envelope'
CONTEXT_EXTRA = [
@ -62,6 +70,7 @@ class CoreNotificationsPlugin(SettingsMixin, InvenTreePlugin):
)
def send_bulk(self):
"""Send the notifications out via email."""
html_message = render_to_string(self.context['template']['html'], self.context)
targets = self.targets.values_list('email', flat=True)