diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 628fd2e646..319b88cb09 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -344,13 +344,15 @@ def GetExportFormats(): ] -def DownloadFile(data, filename, content_type='application/text'): - """ Create a dynamic file for the user to download. +def DownloadFile(data, filename, content_type='application/text', inline=False): + """ + Create a dynamic file for the user to download. Args: data: Raw file data (string or bytes) filename: Filename for the file download content_type: Content type for the download + inline: Download "inline" or as attachment? (Default = attachment) Return: A StreamingHttpResponse object wrapping the supplied data @@ -365,7 +367,10 @@ def DownloadFile(data, filename, content_type='application/text'): response = StreamingHttpResponse(wrapper, content_type=content_type) response['Content-Length'] = len(data) - response['Content-Disposition'] = 'attachment; filename={f}'.format(f=filename) + + disposition = "inline" if inline else "attachment" + + response['Content-Disposition'] = f'{disposition}; filename={filename}' return response diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 839780d5b4..3924a516f3 100644 --- a/InvenTree/common/models.py +++ b/InvenTree/common/models.py @@ -926,6 +926,20 @@ class InvenTreeUserSetting(BaseInvenTreeSetting): 'validator': bool, }, + "LABEL_INLINE": { + 'name': _('Inline label display'), + 'description': _('Display PDF labels in the browser, instead of downloading as a file'), + 'default': True, + 'validator': bool, + }, + + "REPORT_INLINE": { + 'name': _('Inline report display'), + 'description': _('Display PDF reports in the browser, instead of downloading as a file'), + 'default': False, + 'validator': bool, + }, + 'SEARCH_PREVIEW_RESULTS': { 'name': _('Search Preview Results'), 'description': _('Number of results to show in search preview window'), @@ -965,7 +979,10 @@ class InvenTreeUserSetting(BaseInvenTreeSetting): @classmethod def get_filters(cls, key, **kwargs): - return {'key__iexact': key, 'user__id': kwargs['user'].id} + return { + 'key__iexact': key, + 'user__id': kwargs['user'].id + } class PriceBreak(models.Model): diff --git a/InvenTree/label/api.py b/InvenTree/label/api.py index b2d17efdfe..c8b265fd93 100644 --- a/InvenTree/label/api.py +++ b/InvenTree/label/api.py @@ -109,10 +109,12 @@ class LabelPrintMixin: else: pdf = outputs[0].get_document().write_pdf() + inline = common.models.InvenTreeUserSetting.get_setting('LABEL_INLINE', user=request.user) return InvenTree.helpers.DownloadFile( pdf, label_name, - content_type='application/pdf' + content_type='application/pdf', + inline=inline ) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index dce3d248e5..b12a59f136 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -204,6 +204,7 @@ def settings_value(key, *args, **kwargs): if 'user' in kwargs: return InvenTreeUserSetting.get_setting(key, user=kwargs['user']) + return InvenTreeSetting.get_setting(key) diff --git a/InvenTree/templates/InvenTree/settings/navbar.html b/InvenTree/templates/InvenTree/settings/navbar.html index 83bbc10fe9..e7ea17f91f 100644 --- a/InvenTree/templates/InvenTree/settings/navbar.html +++ b/InvenTree/templates/InvenTree/settings/navbar.html @@ -30,6 +30,18 @@ +