Adds simple test-report template

This commit is contained in:
Oliver Walters 2021-02-04 15:29:46 +11:00
parent ddbf2a6313
commit a025b7239d
4 changed files with 161 additions and 23 deletions

View File

@ -1,22 +0,0 @@
"""
Custom template tags for report generation
"""
import os
from django import template
from django.conf import settings
register = template.Library()
@register.simple_tag()
def asset(filename):
"""
Return fully-qualified path for an upload report asset file.
"""
path = os.path.join(settings.MEDIA_ROOT, 'report', 'assets', filename)
path = os.path.abspath(path)
return f"file://{path}"

View File

@ -5,7 +5,6 @@
@page { @page {
size: A4; size: A4;
margin: 2cm; margin: 2cm;
margin-top: 4cm;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-size: 75%; font-size: 75%;
@ -46,10 +45,12 @@
} }
.header { .header {
{% block header_style %}
top: 0px; top: 0px;
left: 0px; left: 0px;
position: fixed; position: fixed;
width: 100%; width: 100%;
{% endblock %}
margin-top: -2.5cm; margin-top: -2.5cm;
} }

View File

@ -0,0 +1,105 @@
{% extends "report/inventree_report_base.html" %}
{% load i18n %}
{% load report %}
{% load inventree_extras %}
{% block style %}
.test-table {
width: 100%;
}
{% block bottom_left %}
content: "{{ date.isoformat }}";
{% endblock %}
{% block bottom_center %}
content: "InvenTree v{% inventree_version %}";
{% endblock %}
{% block top_center %}
content: "{% trans 'Stock Item Test Report' %}";
{% endblock %}
.test-row {
padding: 3px;
}
.test-pass {
color: #5f5;
}
.test-fail {
color: #F55;
}
.container {
padding: 5px;
border: 1px solid;
}
.text-left {
display: inline-block;
width: 50%;
}
.img-right {
display: inline;
align-content: right;
align-items: right;
width: 50%;
}
{% endblock %}
{% block page_content %}
<div class='container'>
<div class='text-left'>
<h2>
{{ stock_item.part.full_name }}
</h2>
</div>
<div class='img-right'>
<img src="{% part_image part %}">
<hr>
<h3>
{% trans "Serial Number" %}: {{ stock_item.serial }}
</h3>
</div>
</div>
<h3>{% trans "Test Results" %}</h3>
<table class='table test-table'>
<thead>
<tr>
<th>{% trans "Test" %}</th>
<th>{% trans "Result" %}</th>
<th>{% trans "Value" %}</th>
<th>{% trans "User" %}</th>
<th>{% trans "Date" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan='5'><hr></td>
</tr>
{% for test in result_list %}
<tr class='test-row'>
<td>{{ test.test }}</td>
{% if test.result %}
<td class='test-pass'>{% trans "Pass" %}</td>
{% else %}
<td class='test-fail'>{% trans "Fail" %}</td>
{% endif %}
<td>{{ test.value }}</td>
<td>{{ test.user.username }}</td>
<td>{{ test.date.date.isoformat }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -0,0 +1,54 @@
"""
Custom template tags for report generation
"""
import os
from django import template
from django.conf import settings
from part.models import Part
from stock.models import StockItem
register = template.Library()
@register.simple_tag()
def asset(filename):
"""
Return fully-qualified path for an upload report asset file.
"""
path = os.path.join(settings.MEDIA_ROOT, 'report', 'assets', filename)
path = os.path.abspath(path)
return f"file://{path}"
@register.simple_tag()
def part_image(part):
"""
Return a fully-qualified path for a part image
"""
if type(part) is Part:
img = part.image.name
elif type(part) is StockItem:
img = part.part.image.name
else:
img = ''
path = os.path.join(settings.MEDIA_ROOT, img)
path = os.path.abspath(path)
print("Path:", path)
if not os.path.exists(path) or not os.path.isfile(path):
# Image does not exist
# Return the 'blank' image
path = os.path.join(settings.STATIC_ROOT, 'img', 'blank_image.png')
path = os.path.abspath(path)
return f"file://{path}"