Merge pull request #1920 from SchrodingersGat/label-print-options

Label print options
This commit is contained in:
Oliver 2021-08-07 22:27:34 +10:00 committed by GitHub
commit 5448165ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 90 additions and 5 deletions

View File

@ -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

View File

@ -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):

View File

@ -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
)

View File

@ -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)

View File

@ -30,6 +30,18 @@
</a>
</li>
<li class='list-group-item' title='{% trans "Labels" %}'>
<a href='#' class='nav-toggle' id='select-user-labels'>
<span class='fas fa-tag'></span> {% trans "Labels" %}
</a>
</li>
<li class='list-group-item' title='{% trans "Reports" %}'>
<a href='#' class='nav-toggle' id='select-user-reports'>
<span class='fas fa-file-pdf'></span> {% trans "Reports" %}
</a>
</li>
<!--
<li class='list-group-item' title='{% trans "Settings" %}'>
<a href='#' class='nav-toggle' id='select-user-settings'>

View File

@ -18,6 +18,8 @@
{% include "InvenTree/settings/user_settings.html" %}
{% include "InvenTree/settings/user_homepage.html" %}
{% include "InvenTree/settings/user_search.html" %}
{% include "InvenTree/settings/user_labels.html" %}
{% include "InvenTree/settings/user_reports.html" %}
{% if user.is_staff %}

View File

@ -0,0 +1,23 @@
{% extends "panel.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block label %}user-labels{% endblock %}
{% block heading %}
{% trans "Label Settings" %}
{% endblock %}
{% block content %}
<div class='row'>
<table class='table table-striped table-condensed'>
{% include "InvenTree/settings/header.html" %}
<tbody>
{% include "InvenTree/settings/setting.html" with key="LABEL_INLINE" icon='fa-tag' user_setting=True %}
</tbody>
</table>
</div>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% extends "panel.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block label %}user-reports{% endblock %}
{% block heading %}
{% trans "Report Settings" %}
{% endblock %}
{% block content %}
<div class='row'>
<table class='table table-striped table-condensed'>
{% include "InvenTree/settings/header.html" %}
<tbody>
{% include "InvenTree/settings/setting.html" with key="REPORT_INLINE" icon='fa-file-pdf' user_setting=True %}
</tbody>
</table>
</div>
{% endblock %}