mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Update label templates
- New ones are automatically copied across now
This commit is contained in:
parent
da715d7381
commit
bf51e1bfb1
@ -1,6 +1,7 @@
|
||||
import os
|
||||
import shutil
|
||||
import logging
|
||||
import hashlib
|
||||
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
@ -9,6 +10,20 @@ from django.conf import settings
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def hashFile(filename):
|
||||
"""
|
||||
Calculate the MD5 hash of a file
|
||||
"""
|
||||
|
||||
md5 = hashlib.md5()
|
||||
|
||||
with open(filename, 'rb') as f:
|
||||
data = f.read()
|
||||
md5.update(data)
|
||||
|
||||
return md5.hexdigest()
|
||||
|
||||
|
||||
class LabelConfig(AppConfig):
|
||||
name = 'label'
|
||||
|
||||
@ -35,6 +50,7 @@ class LabelConfig(AppConfig):
|
||||
src_dir = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
'templates',
|
||||
'label',
|
||||
'stockitem',
|
||||
)
|
||||
|
||||
@ -70,7 +86,21 @@ class LabelConfig(AppConfig):
|
||||
src_file = os.path.join(src_dir, label['file'])
|
||||
dst_file = os.path.join(settings.MEDIA_ROOT, filename)
|
||||
|
||||
if not os.path.exists(dst_file):
|
||||
to_copy = False
|
||||
|
||||
if os.path.exists(dst_file):
|
||||
# File already exists - let's see if it is the "same",
|
||||
# or if we need to overwrite it with a newer copy!
|
||||
|
||||
if not hashFile(dst_file) == hashFile(src_file):
|
||||
logger.info(f"Hash differs for '{filename}'")
|
||||
to_copy = True
|
||||
|
||||
else:
|
||||
logger.info(f"Label template '{filename}' is not present")
|
||||
to_copy = True
|
||||
|
||||
if to_copy:
|
||||
logger.info(f"Copying label template '{dst_file}'")
|
||||
shutil.copyfile(src_file, dst_file)
|
||||
|
||||
@ -106,6 +136,7 @@ class LabelConfig(AppConfig):
|
||||
src_dir = os.path.join(
|
||||
os.path.dirname(os.path.realpath(__file__)),
|
||||
'templates',
|
||||
'label',
|
||||
'stocklocation',
|
||||
)
|
||||
|
||||
@ -146,7 +177,21 @@ class LabelConfig(AppConfig):
|
||||
src_file = os.path.join(src_dir, label['file'])
|
||||
dst_file = os.path.join(settings.MEDIA_ROOT, filename)
|
||||
|
||||
if not os.path.exists(dst_file):
|
||||
to_copy = False
|
||||
|
||||
if os.path.exists(dst_file):
|
||||
# File already exists - let's see if it is the "same",
|
||||
# or if we need to overwrite it with a newer copy!
|
||||
|
||||
if not hashFile(dst_file) == hashFile(src_file):
|
||||
logger.info(f"Hash differs for '{filename}'")
|
||||
to_copy = True
|
||||
|
||||
else:
|
||||
logger.info(f"Label template '{filename}' is not present")
|
||||
to_copy = True
|
||||
|
||||
if to_copy:
|
||||
logger.info(f"Copying label template '{dst_file}'")
|
||||
shutil.copyfile(src_file, dst_file)
|
||||
|
||||
|
20
InvenTree/label/templates/label/stockitem/qr.html
Normal file
20
InvenTree/label/templates/label/stockitem/qr.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "label/label_base.html" %}
|
||||
|
||||
{% load barcode %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
.qr {
|
||||
position: fixed;
|
||||
left: 0mm;
|
||||
top: 0mm;
|
||||
height: {{ height }}mm;
|
||||
width: {{ height }}mm;
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<img class='qr' src='{% qrcode qr_data %}'>
|
||||
{% endblock %}
|
20
InvenTree/label/templates/label/stocklocation/qr.html
Normal file
20
InvenTree/label/templates/label/stocklocation/qr.html
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends "label/label_base.html" %}
|
||||
|
||||
{% load barcode %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
.qr {
|
||||
position: fixed;
|
||||
left: 0mm;
|
||||
top: 0mm;
|
||||
height: {{ height }}mm;
|
||||
width: {{ height }}mm;
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<img class='qr' src='{% qrcode qr_data %}'>
|
||||
{% endblock %}
|
@ -0,0 +1,33 @@
|
||||
{% extends "label/label_base.html" %}
|
||||
|
||||
{% load barcode %}
|
||||
|
||||
{% block style %}
|
||||
|
||||
.qr {
|
||||
position: fixed;
|
||||
left: 0mm;
|
||||
top: 0mm;
|
||||
height: {{ height }}mm;
|
||||
width: {{ height }}mm;
|
||||
}
|
||||
|
||||
.loc {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
display: inline;
|
||||
position: absolute;
|
||||
left: {{ width }},
|
||||
top: 2mm;
|
||||
}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<img class='qr' src='{% qrcode qr_data %}'>
|
||||
|
||||
<div class='loc'>
|
||||
{{ location.name }}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -1,16 +0,0 @@
|
||||
<style>
|
||||
@page {
|
||||
width: 24mm;
|
||||
height: 24mm;
|
||||
padding: 1mm;
|
||||
}
|
||||
|
||||
.qr {
|
||||
margin: 2px;
|
||||
width: 22mm;
|
||||
height: 22mm;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<img class='qr' src="{{ label_tools.qr_code(item.barcode) }}"/>
|
@ -1,16 +0,0 @@
|
||||
<style>
|
||||
@page {
|
||||
width: 24mm;
|
||||
height: 24mm;
|
||||
padding: 1mm;
|
||||
}
|
||||
|
||||
.qr {
|
||||
margin: 2px;
|
||||
width: 22mm;
|
||||
height: 22mm;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<img class='qr' src="{{ label_tools.qr_code(location.barcode) }}"/>
|
@ -1,43 +0,0 @@
|
||||
<style>
|
||||
@page {
|
||||
width: 75mm;
|
||||
height: 24mm;
|
||||
padding: 1mm;
|
||||
}
|
||||
|
||||
.location {
|
||||
padding: 5px;
|
||||
font-weight: bold;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
height: 100%;
|
||||
vertical-align: middle;
|
||||
float: right;
|
||||
display: inline;
|
||||
font-size: 125%;
|
||||
position: absolute;
|
||||
top: 0mm;
|
||||
left: 23mm;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.qr {
|
||||
margin: 2px;
|
||||
width: 22mm;
|
||||
height: 22mm;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<img class='qr' src="{{ label_tools.qr_code(location.barcode) }}"/>
|
||||
|
||||
<div class='location'>
|
||||
{{ location.name }}
|
||||
<br>
|
||||
<br>
|
||||
<hr>
|
||||
Location ID: {{ location.pk }}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user