• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inventree / InvenTree / 8604849533

08 Apr 2024 06:20PM CUT coverage: 78.857%. First build
8604849533

Pull #6981

github

web-flow
Merge 3d6fa4389 into 4adce85ef
Pull Request #6981: Bump djangorestframework from 3.14.0 to 3.15.1 in /src/backend

19152 of 24287 relevant lines covered (78.86%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/backend/InvenTree/plugin/base/label/label.py
1
"""Functions to print a label to a mixin printer."""
2

3
import logging
4

5
from django.conf import settings
6
from django.utils.translation import gettext_lazy as _
7

8
import common.notifications
9
from InvenTree.exceptions import log_error
10
from plugin.registry import registry
11

12
logger = logging.getLogger('inventree')
13

14

15
def print_label(plugin_slug: str, **kwargs):
16
    """Print label with the provided plugin.
17

18
    This task is nominally handled by the background worker.
19
    If the printing fails (throws an exception) then the user is notified.
20

21
    Arguments:
22
        plugin_slug (str): The unique slug (key) of the plugin.
23

24
    kwargs:
25
        passed through to the plugin.print_label() method
26
    """
27
    logger.info("Plugin '%s' is printing a label", plugin_slug)
×
28

29
    plugin = registry.get_plugin(plugin_slug)
×
30

31
    if plugin is None:  # pragma: no cover
×
32
        logger.error("Could not find matching plugin for '%s'", plugin_slug)
×
33
        return
×
34

35
    try:
×
36
        plugin.print_label(**kwargs)
×
37
    except Exception as e:  # pragma: no cover
×
38
        # Plugin threw an error - notify the user who attempted to print
39
        ctx = {'name': _('Label printing failed'), 'message': str(e)}
×
40

41
        user = kwargs.get('user', None)
×
42

43
        if user:
×
44
            # Log an error message to the database
45
            log_error('plugin.print_label')
×
46
            logger.exception(
47
                "Label printing failed: Sending notification to user '%s'", user
48
            )  # pragma: no cover
49

50
            # Throw an error against the plugin instance
51
            common.notifications.trigger_notification(
52
                plugin.plugin_config(),
53
                'label.printing_failed',
54
                targets=[user],
55
                context=ctx,
56
                delivery_methods={common.notifications.UIMessageNotification},
57
            )
58

59
        if settings.TESTING:
60
            # If we are in testing mode, we want to know about this exception
61
            raise e
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc