From 174ac642359692ed8215269bd9cc2fae8020cb23 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:45:18 +1000 Subject: [PATCH 1/3] Allow downloaded files to be inline or attachments --- InvenTree/InvenTree/helpers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 From d77b99c0ca2adcf7d4e73e681d818ded3fe78084 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 7 Aug 2021 21:57:41 +1000 Subject: [PATCH 2/3] Add user settings for report and labels --- InvenTree/common/models.py | 14 +++++++++++ .../templates/InvenTree/settings/navbar.html | 12 ++++++++++ .../InvenTree/settings/settings.html | 2 ++ .../InvenTree/settings/user_labels.html | 23 +++++++++++++++++++ .../InvenTree/settings/user_reports.html | 23 +++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 InvenTree/templates/InvenTree/settings/user_labels.html create mode 100644 InvenTree/templates/InvenTree/settings/user_reports.html diff --git a/InvenTree/common/models.py b/InvenTree/common/models.py index 839780d5b4..e2486c41df 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'), 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 @@ +
  • + + {% trans "Labels" %} + +
  • + +
  • + + {% trans "Reports" %} + +
  • +