Render a template for get a labels of multiple devices
This commit is contained in:
parent
8d3cad48bf
commit
a8df3f5e5a
|
@ -1007,3 +1007,18 @@ class TradeDocumentForm(FlaskForm):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return self._obj
|
return self._obj
|
||||||
|
|
||||||
|
|
||||||
|
class PrintTagsForm(FlaskForm):
|
||||||
|
devices = StringField(render_kw={'class': "devicesList d-none"})
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
|
||||||
|
if not self.devices.data:
|
||||||
|
return False
|
||||||
|
|
||||||
|
device_ids = self.devices.data.split(",")
|
||||||
|
self._tags = Tag.query.filter(Tag.device_id.in_(device_ids)).all()
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
|
@ -21,6 +21,7 @@ from ereuse_devicehub.inventory.forms import (
|
||||||
LotForm,
|
LotForm,
|
||||||
NewActionForm,
|
NewActionForm,
|
||||||
NewDeviceForm,
|
NewDeviceForm,
|
||||||
|
PrintTagsForm,
|
||||||
TagDeviceForm,
|
TagDeviceForm,
|
||||||
TagForm,
|
TagForm,
|
||||||
TagUnnamedForm,
|
TagUnnamedForm,
|
||||||
|
@ -118,6 +119,7 @@ class DeviceListMix(GenericMixView):
|
||||||
'form_new_datawipe': form_new_datawipe,
|
'form_new_datawipe': form_new_datawipe,
|
||||||
'form_new_trade': form_new_trade,
|
'form_new_trade': form_new_trade,
|
||||||
'form_filter': form_filter,
|
'form_filter': form_filter,
|
||||||
|
'form_print_tags': PrintTagsForm(),
|
||||||
'lot': lot,
|
'lot': lot,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
'list_devices': list_devices,
|
'list_devices': list_devices,
|
||||||
|
@ -381,6 +383,35 @@ class TagAddUnnamedView(View):
|
||||||
return flask.render_template(self.template_name, form=form, **context)
|
return flask.render_template(self.template_name, form=form, **context)
|
||||||
|
|
||||||
|
|
||||||
|
class PrintTagsView(View):
|
||||||
|
"""This View is used to print labels from multiple devices"""
|
||||||
|
|
||||||
|
methods = ['POST', 'GET']
|
||||||
|
decorators = [login_required]
|
||||||
|
template_name = 'inventory/print_tags.html'
|
||||||
|
title = 'Design and implementation of labels'
|
||||||
|
|
||||||
|
def dispatch_request(self):
|
||||||
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
context = {
|
||||||
|
'lots': lots,
|
||||||
|
'page_title': self.title,
|
||||||
|
'version': __version__,
|
||||||
|
'referrer': request.referrer,
|
||||||
|
}
|
||||||
|
|
||||||
|
form = PrintTagsForm()
|
||||||
|
if form.validate_on_submit():
|
||||||
|
context['form'] = form
|
||||||
|
context['tags'] = form._tags
|
||||||
|
return flask.render_template(self.template_name, **context)
|
||||||
|
else:
|
||||||
|
messages.error('Error you need select one or more devices')
|
||||||
|
|
||||||
|
next_url = request.referrer or url_for('inventory.devicelist')
|
||||||
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
class TagDetailView(View):
|
class TagDetailView(View):
|
||||||
decorators = [login_required]
|
decorators = [login_required]
|
||||||
template_name = 'inventory/tag_detail.html'
|
template_name = 'inventory/tag_detail.html'
|
||||||
|
@ -734,3 +765,7 @@ devices.add_url_rule(
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/export/<string:export_id>/', view_func=ExportsView.as_view('export')
|
'/export/<string:export_id>/', view_func=ExportsView.as_view('export')
|
||||||
)
|
)
|
||||||
|
devices.add_url_rule(
|
||||||
|
'/tags/print',
|
||||||
|
view_func=PrintTagsView.as_view('print_tags'),
|
||||||
|
)
|
||||||
|
|
|
@ -235,6 +235,17 @@
|
||||||
Remove Tag from selected Device
|
Remove Tag from selected Device
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<form id="print_tags" method="post" action="{{ url_for('inventory.print_tags') }}">
|
||||||
|
{% for f in form_print_tags %}
|
||||||
|
{{ f }}
|
||||||
|
{% endfor %}
|
||||||
|
<a href="javascript:$('#print_tags').submit()" class="dropdown-item">
|
||||||
|
<i class="bi bi-x"></i>
|
||||||
|
Print tags
|
||||||
|
</a>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
{% extends "ereuse_devicehub/base_site.html" %}
|
||||||
|
{% block main %}
|
||||||
|
|
||||||
|
<div class="pagetitle">
|
||||||
|
<h1>Print tags</h1>
|
||||||
|
<nav>
|
||||||
|
<ol class="breadcrumb">
|
||||||
|
<li class="breadcrumb-item"><a href="{{ url_for('inventory.taglist')}}">Tag management</a></li>
|
||||||
|
<li class="breadcrumb-item active">Print Tags</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div><!-- End Page Title -->
|
||||||
|
|
||||||
|
<section class="section profile">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xl-8">
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="pt-4 pb-2">
|
||||||
|
<h5 class="card-title text-center pb-0 fs-4">Print Tags</h5>
|
||||||
|
<p class="text-center small">{{ title }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-3 col-md-4">
|
||||||
|
{% for tag in tags %}
|
||||||
|
<div style="width:256px; height:148px; border: solid 1px; padding: 10px;">
|
||||||
|
<div id="print">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<div id="{{ tag.id }}"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col">
|
||||||
|
<div style="padding-top: 55px"><b id="tag_{{ tag.id }}">{{ tag.id }}</b></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
<div class="col-1">
|
||||||
|
</div>
|
||||||
|
<div class="col label">
|
||||||
|
<label class="col-form-label col-sm-2">Size</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<select class="form-select" id="printerType">
|
||||||
|
<option label="Brother small size (62 x 29)" value="brotherSmall" selected="selected">
|
||||||
|
Brother small size (62 x 29)
|
||||||
|
</option>
|
||||||
|
<option label="Printer tag small (97 x 59)" value="smallTagPrinter">
|
||||||
|
Printer tag small (97 x 59)
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label class="col-form-label col-sm-2">Width</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<input class="form-control" id="width-tag" name='width-tag' type="number" value="62" min="52" max="300" />
|
||||||
|
<span class="input-group-text">mm</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label class="col-form-label col-sm-2">Height</label>
|
||||||
|
<div class="col-sm-10">
|
||||||
|
<div class="input-group mb-3">
|
||||||
|
<input class="form-control" id="height-tag" name='height-tag' type="number" value="29" min="28" max="200" />
|
||||||
|
<span class="input-group-text">mm</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mt-5">
|
||||||
|
<div class="col-lg-3 col-md-4">
|
||||||
|
<a href="javascript:printpdf()" class="btn btn-success">Print</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-4">
|
||||||
|
<a href="javascript:save_size()" class="btn btn-primary">Save</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-3 col-md-4">
|
||||||
|
<a href="javascript:reset_size()" class="btn btn-danger">Reset</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<script src="{{ url_for('static', filename='js/qrcode.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/jspdf.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/print.pdf.js') }}"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
{% for tag in tags %}
|
||||||
|
new QRCode(document.getElementById("{{ tag.id }}"), {
|
||||||
|
text: "{{url_for('inventory.device_details', id=tag.device.devicehub_id, _external=True)}}",
|
||||||
|
width: 128,
|
||||||
|
height: 128,
|
||||||
|
colorDark : "#000000",
|
||||||
|
colorLight : "#ffffff",
|
||||||
|
correctLevel : QRCode.CorrectLevel.H
|
||||||
|
});
|
||||||
|
{% endfor %}
|
||||||
|
</script>
|
||||||
|
{% endblock main %}
|
Reference in New Issue