2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +00:00

More docstrings

This commit is contained in:
Matthias
2022-05-29 03:17:11 +02:00
parent 8d5f229000
commit cddead457f
6 changed files with 21 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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