PDF fixes, and working on models andstlying django side

This commit is contained in:
Tyrel Souza 2023-09-18 14:01:34 -04:00
parent 87922787c9
commit 13bbc4705a
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
13 changed files with 471 additions and 246 deletions

View File

@ -279,7 +279,7 @@ namespace BenchtopPDF
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.LowLimit / 1000.0:F3}");
table.Cell().Element(CellStyle).AlignRight().Text($"{masterValue.HighLimit / 1000.0:F3}");
table.Cell().Element(CellStyle).AlignRight().Text($"{value / 1000.0:F3}");
table.Cell().Element(CellStyle).AlignRight().Text($"{delta / 1000.0:F3}");
table.Cell().Element(CellStyle).AlignRight().Text($"---");
}

View File

@ -1,14 +1,8 @@
from django.contrib import admin
from sheets.models import (
Configuration,
from .models import (
Sheet
)
class ConfigurationAdmin(admin.ModelAdmin):
pass
admin.site.register(Configuration, ConfigurationAdmin)
class SheetAdmin(admin.ModelAdmin):
pass

View File

@ -3,31 +3,60 @@ from django.forms.widgets import ClearableFileInput
from django.db import models
from django.utils.translation import gettext_lazy as _
from sheets.models import Configuration, Sheet
from .models import Sheet
class SheetForm(forms.ModelForm):
class Meta:
model = Sheet
fields = ["instrument", "customer_name", "customer_address", "control_number", "serial_number", "accuracy", "barometric_pressure", "temperature", "humidity", "report_type", "as_found", "as_left", "both", "configuration",]
widgets = {
fields = [
"customer_name",
"onsite_cal",
"control_doc",
"technician",
"instrument_model",
"serial_number",
"channel",
"transducer_model",
"transducer_span",
"calibration_serial",
"calibration_model",
"calibration_date",
"calibration_due_date",
"calibration_cert_id",
"accuracy",
"barometric_pressure",
"temperature",
"humidity",
"report_type",
"as_found",
"as_left",
"both",
]
widgets = {
"accuracy": forms.NumberInput(attrs={'step': 0.01}),
"barometric_pressure": forms.NumberInput(attrs={'step': 0.01, 'max': 1100, 'min': 800}),
"temperature": forms.NumberInput(attrs={'step': 0.01, 'max': 1000.0, 'min': -459.67}),
"humidity": forms.NumberInput(attrs={'step': 0.01, 'max': 100.0, 'min': 0.0}),
}
"calibration_date": forms.SelectDateWidget(),
"calibration_due_date": forms.SelectDateWidget(),
}
def __init__(self, *args, **kwargs):
super(SheetForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
# add v-model to each model field
if isinstance(field, forms.fields.FileField):
field.widget.attrs.update(
{
'v-on:change': f"change_{name}",
'v-if': f"show_{name}"
'v-on:change': f"change_{name}",
'v-if': f"show_{name}"
})
else:
field.widget.attrs.update({'v-model': name})

View File

@ -1,30 +1,38 @@
# Generated by Django 4.2.3 on 2023-07-26 18:12
# Generated by Django 4.2.5 on 2023-09-18 17:03
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
dependencies = [
]
operations = [
migrations.CreateModel(
name="Configuration",
name='Sheet',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("serial", models.CharField(max_length=100)),
("device", models.CharField(max_length=100)),
("calibration_date", models.DateField()),
("calibration_due_date", models.DateField()),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('customer_name', models.CharField(max_length=256)),
('customer_address', models.CharField(max_length=256)),
('serial_number', models.CharField(max_length=256)),
('accuracy', models.FloatField()),
('barometric_pressure', models.FloatField()),
('temperature', models.FloatField()),
('humidity', models.FloatField()),
('report_type', models.CharField(choices=[('TV', 'Transducer Verify'), ('HC', 'Hardware Calibration')], max_length=256)),
('as_found', models.FileField(blank=True, upload_to='')),
('as_left', models.FileField(blank=True, upload_to='')),
('both', models.FileField(blank=True, upload_to='')),
('calibration_cert_id', models.CharField(default=0, max_length=100)),
('calibration_date', models.DateField(default=0)),
('calibration_due_date', models.DateField(default=0)),
('calibration_model', models.CharField(default=0, max_length=100)),
('calibration_serial', models.CharField(default=0, max_length=100)),
('channel', models.CharField(default=0, max_length=256)),
('instrument_model', models.CharField(default=0, max_length=256)),
('transducer_model', models.CharField(default=0, max_length=256)),
('transducer_span', models.CharField(default=0, max_length=256)),
],
),
]

View File

@ -0,0 +1,58 @@
# Generated by Django 4.2.5 on 2023-09-18 17:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='sheet',
name='calibration_cert_id',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='sheet',
name='calibration_date',
field=models.DateField(),
),
migrations.AlterField(
model_name='sheet',
name='calibration_due_date',
field=models.DateField(),
),
migrations.AlterField(
model_name='sheet',
name='calibration_model',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='sheet',
name='calibration_serial',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='sheet',
name='channel',
field=models.CharField(max_length=256),
),
migrations.AlterField(
model_name='sheet',
name='instrument_model',
field=models.CharField(max_length=256),
),
migrations.AlterField(
model_name='sheet',
name='transducer_model',
field=models.CharField(max_length=256),
),
migrations.AlterField(
model_name='sheet',
name='transducer_span',
field=models.CharField(max_length=256),
),
]

View File

@ -1,56 +0,0 @@
# Generated by Django 4.2.3 on 2023-07-26 19:33
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("sheets", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="Sheet",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("instrument", models.CharField(max_length=256)),
("customer_name", models.CharField(max_length=256)),
("customer_address", models.CharField(max_length=256)),
("control_number", models.CharField(max_length=256)),
("serial_number", models.CharField(max_length=256)),
("accuracy", models.FloatField()),
("barometric_pressure", models.FloatField()),
("temperature", models.FloatField()),
("humidity", models.FloatField()),
(
"report_type",
models.CharField(
choices=[
("TV", "Transducer Verify"),
("HC", "Hardware Calibration"),
],
max_length=256,
),
),
("as_found", models.FileField(upload_to="")),
("as_left", models.FileField(upload_to="")),
("both", models.FileField(upload_to="")),
(
"configuration",
models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
to="sheets.configuration",
),
),
],
),
]

View File

@ -1,36 +0,0 @@
# Generated by Django 4.2.3 on 2023-07-26 20:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("sheets", "0002_sheet"),
]
operations = [
migrations.AlterField(
model_name="sheet",
name="as_found",
field=models.FileField(blank=True, upload_to=""),
),
migrations.AlterField(
model_name="sheet",
name="as_left",
field=models.FileField(blank=True, upload_to=""),
),
migrations.AlterField(
model_name="sheet",
name="both",
field=models.FileField(blank=True, upload_to=""),
),
migrations.RemoveField(
model_name="sheet",
name="configuration",
),
migrations.AddField(
model_name="sheet",
name="configuration",
field=models.ManyToManyField(to="sheets.configuration"),
),
]

View File

@ -0,0 +1,34 @@
# Generated by Django 4.2.5 on 2023-09-18 17:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('sheets', '0002_alter_sheet_calibration_cert_id_and_more'),
]
operations = [
migrations.RemoveField(
model_name='sheet',
name='customer_address',
),
migrations.AddField(
model_name='sheet',
name='control_doc',
field=models.CharField(default=0, max_length=256),
preserve_default=False,
),
migrations.AddField(
model_name='sheet',
name='onsite_cal',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='sheet',
name='technician',
field=models.CharField(default=0, max_length=256),
preserve_default=False,
),
]

View File

@ -1,41 +1,41 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
# Create your models here.
class Configuration(models.Model):
serial = models.CharField(max_length=100)
device = models.CharField(max_length=100)
calibration_date = models.DateField()
calibration_due_date = models.DateField()
def __str__(self):
return f"{self.serial} {self.device} [{self.calibration_date} to {self.calibration_due_date}]"
class Sheet(models.Model):
instrument = models.CharField(max_length=256)
customer_name = models.CharField(max_length=256)
customer_address = models.CharField(max_length=256)
control_number = models.CharField(max_length=256)
instrument_model = models.CharField(max_length=256)
serial_number = models.CharField(max_length=256)
channel = models.CharField(max_length=256)
transducer_model = models.CharField(max_length=256)
transducer_span = models.CharField(max_length=256)
customer_name = models.CharField(max_length=256)
onsite_cal = models.BooleanField(default=False)
control_doc = models.CharField(max_length=256)
technician = models.CharField(max_length=256)
accuracy = models.FloatField()
barometric_pressure = models.FloatField()
temperature = models.FloatField()
humidity = models.FloatField()
calibration_serial = models.CharField(max_length=100)
calibration_model = models.CharField(max_length=100)
calibration_date = models.DateField()
calibration_due_date = models.DateField()
calibration_cert_id = models.CharField(max_length=100)
CHOICES = [
('TV', _('Transducer Verify')),
('HC', _('Hardware Calibration'))
]
report_type = models.CharField(max_length=256,
report_type = models.CharField(
max_length=256,
choices=CHOICES,
)
as_found = models.FileField(blank=True)
as_left = models.FileField(blank=True)
both = models.FileField(blank=True)
configuration = models.ManyToManyField("Configuration")
both = models.FileField(blank=True)

View File

@ -2,6 +2,7 @@ import re
import json
from pprint import pprint
def in_range(index, value, master_values):
return (
master_values[index]["Low Limit"] <= value <= master_values[index]["High Limit"]

View File

@ -1,121 +1,227 @@
<html>
<body class="app">
<html lang="en">
<head>
<!--? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.8.1/dist/css/foundation.min.css"-->
<!--? crossorigin="anonymous">-->
<!--? <script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.8.1/dist/js/foundation.min.js"-->
<!--? crossorigin="anonymous"></script>-->
<script type="importmap">
{
"imports": {
"vue": "https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.41/vue.esm-browser.js"
}
}
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js" integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
<script type="importmap">
{
"imports": {
"vue": "https://cdnjs.cloudflare.com/ajax/libs/vue/3.2.41/vue.esm-browser.js"
}
}
</script>
<style>
.app {
margin: auto;
align: center;
width: 50%;
}
</style>
</head>
<body class="app">
<div id="app">
<form action="." method="post" enctype="multipart/form-data">
{% csrf_token %}
<table>
<tdata>
<tr><td>Customer Name</td><td>{{ form.customer_name }}</td></tr>
<tr><td>Customer Address</td><td>{{ form.customer_address }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<table class="table table-striped">
<thead>
<tr>
<th colspan="2"><h2>Customer</h2></th>
</tr>
</thead>
<tbody>
<tr><td>Instrument</td><td>{{ form.instrument }}</td></tr>
<tr><td>Control Number</td><td>{{ form.control_number }}</td></tr>
<tr><td>Serial Number</td><td>{{ form.serial_number }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr>
<td>Customer Name</td>
<td>{{ form.customer_name }}</td>
</tr>
<tr>
<td>On Site Calibration</td>
<td>{{ form.onsite_cal }}</td>
</tr>
<tr>
<td>Control Doc#</td>
<td>{{ form.control_doc }}</td>
</tr>
<tr>
<td>Technician</td>
<td>{{ form.technician }}</td>
</tr>
</tbody>
<tr><td>Accuracy</td><td>{{ form.accuracy }}</td></tr>
<tr><td>Barometric Pressure (mbar)</td><td>{{ form.barometric_pressure }}</td></tr>
<tr><td>Temperature (&deg;F)</td><td>{{ form.temperature }}</td></tr>
<tr><td>Humidity</td><td>{{ form.humidity }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<thead>
<tr>
<th colspan="2"><h2>Instrument</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td>Model:</td>
<td>{{ form.instrument_model }}</td>
</tr>
<tr>
<td>Serial Number</td>
<td>{{ form.serial_number }}</td>
</tr>
<tr>
<td>Channel</td>
<td>{{ form.channel }}</td>
</tr>
<tr>
<td>Transducer Model:</td>
<td>{{ form.transducer_model }}</td>
</tr>
<tr>
<td>Transducer Span:</td>
<td>{{ form.transducer_span }}</td>
</tr>
</tbody>
<tr><td>Report Type</td><td>{{ form.report_type }}</td></tr>
<tr><td>Configuration(s)</td><td>{{ form.configuration }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<thead>
<tr>
<th colspan="2"><h2>Primary Calibration Device</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td>Model</td>
<td>{{ form.calibration_model }}</td>
</tr>
<tr>
<td>Serial #</td>
<td>{{ form.calibration_serial }}</td>
</tr>
<tr>
<td>Cal Date</td>
<td>{{ form.calibration_date }}</td>
</tr>
<tr>
<td>Cal Due Date</td>
<td>{{ form.calibration_due_date }}</td>
</tr>
<tr>
<td>Cert ID</td>
<td>{{ form.calibration_cert_id }}</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="2"><h2>Environment</h2></th>
</tr>
</thead>
<tbody>
<tr><td>As Found: {{ form.as_found }}</td><td>As Left:{{ form.as_left }}</td></tr>
<tr><td colspan=2>One File: {{ form.both }}</td></tr>
<tr><td colspan=2><hr></td></tr>
<tr><td>&nbsp;</td><td align="right"><input type="submit" value="Generate PDF and Label"></td></tr>
<tr>
<td>Accuracy</td>
<td>{{ form.accuracy }}</td>
</tr>
<tr>
<td>Barometric Pressure (mbar)</td>
<td>{{ form.barometric_pressure }}</td>
</tr>
<tr>
<td>Temperature (&deg;F)</td>
<td>{{ form.temperature }}</td>
</tr>
<tr>
<td>Humidity</td>
<td>{{ form.humidity }}</td>
</tr>
</tbody>
</tdata>
<thead>
<tr>
<th colspan="2"><h2>Report Uploads</h2></th>
</tr>
</thead>
<tbody>
<tr>
<td>Report Type</td>
<td>{{ form.report_type }}</td>
</tr>
<tr>
<td colspan=2>One File: {{ form.both }}</td>
</tr>
<tr>
<td>As Found: {{ form.as_found }}</td>
<td>As Left:{{ form.as_left }}</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right"><input type="submit" value="Generate PDF and Label"></td>
</tr>
</tbody>
</table>
</form>
</div>
{% verbatim %}
<script type="module">
import { createApp, ref, reactive, computed } from 'vue'
import {createApp, ref, reactive, computed} from 'vue'
// Vue.config.delimiters = ['${', '}'];
const vm = createApp({
el: "#app",
data() {
const instrument = ""
const customer_name = ""
const customer_address = ""
const control_number = ""
const serial_number = ""
const accuracy = ref("0.5")
const barometric_pressure = ref(1013.25)
const temperature = ref("50")
const humidity = ref("50.0")
const report_type = ""
const as_found = ""
const as_left = ""
const both = ""
const show_as_found = reactive(true)
const show_as_left = reactive(true)
const show_both = reactive(true)
// Vue.config.delimiters = ['${', '}'];
const vm = createApp({
el: "#app",
data() {
const as_found = ""
const as_left = ""
const both = ""
const accuracy = ref("0.5")
const barometric_pressure = ref(1013.25)
const temperature = ref("50")
const humidity = ref("50.0")
const show_as_found = reactive(true)
const show_as_left = reactive(true)
const show_both = reactive(true)
return {
instrument,
customer_name,
customer_address,
control_number,
serial_number,
accuracy,
barometric_pressure,
temperature,
humidity,
report_type,
as_found,
as_left,
both,
show_as_found,
show_as_left,
show_both
return {
accuracy,
barometric_pressure,
temperature,
humidity,
as_found,
as_left,
both,
show_as_found,
show_as_left,
show_both
}
},
ready: () => {
this.watchFileInput();
},
methods: {
change_as_found: function (event) {
this.show_both = false
},
change_as_left: function (event) {
this.show_both = false
},
change_both: function (event) {
this.show_as_found = false
this.show_as_left = false
},
watchFileInput: function () {
// will notify a file input
$('input[type="file"]').change(this.notifyFileInput.bind(this));
},
notifyFileInput: function (event) {
// update file name value
this.file = event.target.files[0].name;
}
}
},
ready: () => {
this.watchFileInput();
},
methods: {
change_as_found: function(event) {
console.log(this)
this.show_both = false
},
change_as_left: function(event) {
this.show_both = false
},
change_both: function(event) {
this.show_as_found = false
this.show_as_left = false
},
watchFileInput: function() {
// will notify a file input
$('input[type="file"]').change(this.notifyFileInput.bind(this));
},
notifyFileInput: function(event) {
var fileName = event.target.files[0].name;
// update file name value
this.file = fileName;
}
}
}).mount("#app")
}).mount("#app")
</script>
{% endverbatim %}
</body>

View File

@ -1,9 +1,9 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import SheetForm, SheetForm
from django.core.exceptions import ValidationError
from .parsers import parse_transducer, parse_hardware_calibration
from .forms import SheetForm, SheetForm
from .parsers import parse_transducer, parse_hardware_calibration
def upload_file(request):
@ -23,7 +23,9 @@ def upload_file(request):
pass
else:
raise ValidationError("Please provide proper files")
return HttpResponseRedirect("/success/url/")
f.save()
breakpoint()
return HttpResponseRedirect("/")
else:
form = SheetForm()
return render(request, "sheets/upload.html", {"form": form})

View File

@ -0,0 +1,85 @@
|| Transducer Verify Report ||
TRANSDUCER1
===============================================================
Transducer 1 CTS D34-442 115PSIA
Setpoint Pressure 1 0.000 psig
Setpoint Pressure 2 20.000 psig
Setpoint Pressure 3 40.000 psig
Setpoint Pressure 4 60.000 psig
Setpoint Pressure 5 80.000 psig
Setpoint Pressure 6 100.000 psig
Instrument Pressure 1 0.000 psig
Instrument Pressure 2 20.002 psig
Instrument Pressure 3 39.997 psig
Instrument Pressure 4 60.010 psig
Instrument Pressure 5 80.001 psig
Instrument Pressure 6 100.002 psig
Master Value 1 0.000 psig
Master Value 2 20.000 psig
Master Value 3 40.000 psig
Master Value 4 60.000 psig
Master Value 5 80.000 psig
Master Value 6 100.000 psig
Verify Date 07/20/22
Verify Time 11:20:26
TRANSDUCER2
===============================================================
Transducer 2 CTS A12-221 250SCCM
Setpoint Pressure 1 20.000 psig
Setpoint Pressure 2 20.000 psig
Setpoint Pressure 3 20.000 psig
Setpoint Pressure 4 20.000 psig
Setpoint Pressure 5 20.000 psig
Setpoint Pressure 6 20.000 psig
Setpoint Pressure 7 20.000 psig
Setpoint Pressure 8 20.000 psig
Setpoint Pressure 9 20.000 psig
Setpoint Pressure 10 20.000 psig
Setpoint Pressure 11 20.000 psig
Instrument Pressure 1 20.154 psig
Instrument Pressure 2 20.153 psig
Instrument Pressure 3 20.152 psig
Instrument Pressure 4 20.150 psig
Instrument Pressure 5 20.148 psig
Instrument Pressure 6 20.145 psig
Instrument Pressure 7 20.144 psig
Instrument Pressure 8 20.141 psig
Instrument Pressure 9 20.139 psig
Instrument Pressure 10 20.138 psig
Instrument Pressure 11 20.136 psig
Instrument Flow 1 -0.082 sccm
Instrument Flow 2 24.802 sccm
Instrument Flow 3 49.664 sccm
Instrument Flow 4 74.836 sccm
Instrument Flow 5 99.416 sccm
Instrument Flow 6 125.289 sccm
Instrument Flow 7 150.205 sccm
Instrument Flow 8 175.290 sccm
Instrument Flow 9 200.165 sccm
Instrument Flow 10 224.748 sccm
Instrument Flow 11 249.825 sccm
Master Reading 1 0.000 sccm
Master Reading 2 25.000 sccm
Master Reading 3 50.000 sccm
Master Reading 4 75.000 sccm
Master Reading 5 100.000 sccm
Master Reading 6 125.000 sccm
Master Reading 7 150.000 sccm
Master Reading 8 175.000 sccm
Master Reading 9 200.000 sccm
Master Reading 10 225.000 sccm
Master Reading 11 250.000 sccm
Master Value 1 0.000 sccm
Master Value 2 25.000 sccm
Master Value 3 50.000 sccm
Master Value 4 75.000 sccm
Master Value 5 100.000 sccm
Master Value 6 125.000 sccm
Master Value 7 150.000 sccm
Master Value 8 175.000 sccm
Master Value 9 200.000 sccm
Master Value 10 225.000 sccm
Master Value 11 250.000 sccm
Verify Date 07/15/21
Verify Time 14:55:10