files, parsing, updates
This commit is contained in:
parent
10a216a37d
commit
bac7d9ac9d
@ -1,3 +1,16 @@
|
||||
from django.contrib import admin
|
||||
from sheets.models import (
|
||||
Configuration,
|
||||
Sheet
|
||||
)
|
||||
|
||||
# Register your models here.
|
||||
class ConfigurationAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
admin.site.register(Configuration, ConfigurationAdmin)
|
||||
|
||||
|
||||
class SheetAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
|
||||
admin.site.register(Sheet, SheetAdmin)
|
||||
|
@ -3,35 +3,22 @@ from django.forms.widgets import ClearableFileInput
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class UploadFileForm(forms.Form):
|
||||
instrument = forms.CharField()
|
||||
customer_name = forms.CharField()
|
||||
customer_address = forms.CharField()
|
||||
control_number = forms.CharField()
|
||||
serial_number = forms.CharField()
|
||||
accuracy = forms.FloatField(widget=forms.NumberInput(attrs={'step': 0.01}))
|
||||
barometric_pressure = forms.FloatField(widget=forms.NumberInput(attrs={'step': 0.01, 'max': 1100, 'min': 800}))
|
||||
temperature = forms.FloatField(widget=forms.NumberInput(attrs={'step': 0.01, 'max': 1000.0, 'min': -459.67}))
|
||||
humidity = forms.FloatField(widget=forms.NumberInput(attrs={'step': 0.01, 'max': 100.0, 'min': 0.0}))
|
||||
from sheets.models import Configuration, Sheet
|
||||
|
||||
|
||||
CHOICES = [
|
||||
('TV', _('Transducer Verify')),
|
||||
('HC', _('Hardware Calibration'))
|
||||
]
|
||||
|
||||
report_type = forms.ChoiceField(
|
||||
widget=forms.RadioSelect,
|
||||
choices=CHOICES,
|
||||
)
|
||||
|
||||
as_found = forms.FileField(required=False, widget=ClearableFileInput(attrs={'placeholder': ...}))
|
||||
as_left = forms.FileField(required=False, widget=ClearableFileInput(attrs={'placeholder': ...}))
|
||||
both = forms.FileField(required=False, widget=ClearableFileInput(attrs={'placeholder': ...}))
|
||||
|
||||
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 = {
|
||||
"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}),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UploadFileForm, self).__init__(*args, **kwargs)
|
||||
super(SheetForm, self).__init__(*args, **kwargs)
|
||||
|
||||
for name, field in self.fields.items():
|
||||
# add v-model to each model field
|
||||
@ -42,4 +29,5 @@ class UploadFileForm(forms.Form):
|
||||
'v-if': f"show_{name}"
|
||||
})
|
||||
else:
|
||||
field.widget.attrs.update({'v-model': name})
|
||||
field.widget.attrs.update({'v-model': name})
|
||||
|
||||
|
30
benchtopdevices/sheets/migrations/0001_initial.py
Normal file
30
benchtopdevices/sheets/migrations/0001_initial.py
Normal file
@ -0,0 +1,30 @@
|
||||
# Generated by Django 4.2.3 on 2023-07-26 18:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Configuration",
|
||||
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()),
|
||||
],
|
||||
),
|
||||
]
|
56
benchtopdevices/sheets/migrations/0002_sheet.py
Normal file
56
benchtopdevices/sheets/migrations/0002_sheet.py
Normal file
@ -0,0 +1,56 @@
|
||||
# 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",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,36 @@
|
||||
# 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"),
|
||||
),
|
||||
]
|
@ -1,4 +1,5 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
# Create your models here.
|
||||
|
||||
@ -9,4 +10,32 @@ class Configuration(models.Model):
|
||||
calibration_due_date = models.DateField()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.serial} {self.description}"
|
||||
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)
|
||||
serial_number = models.CharField(max_length=256)
|
||||
accuracy = models.FloatField()
|
||||
barometric_pressure = models.FloatField()
|
||||
temperature = models.FloatField()
|
||||
humidity = models.FloatField()
|
||||
|
||||
|
||||
CHOICES = [
|
||||
('TV', _('Transducer Verify')),
|
||||
('HC', _('Hardware Calibration'))
|
||||
]
|
||||
|
||||
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")
|
@ -49,7 +49,7 @@ def parse_calibration_data(text):
|
||||
return calibration_data
|
||||
|
||||
|
||||
def parse_hardware_calibration(content):
|
||||
def parse_hardware_calibration(content, accuracy):
|
||||
# Split the content into instrument info and calibration data sections
|
||||
info_section, calibration_section = content.split(
|
||||
"|| Hardware Calibration Report ||"
|
||||
|
@ -1,18 +1,29 @@
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from .forms import UploadFileForm
|
||||
from .forms import SheetForm, SheetForm
|
||||
from django.core.exceptions import ValidationError
|
||||
from .parsers import parse_transducer, parse_hardware_calibration
|
||||
|
||||
|
||||
|
||||
def upload_file(request):
|
||||
if request.method == "POST":
|
||||
breakpoint()
|
||||
f = UploadFileForm(request.POST, request.FILES)
|
||||
f = SheetForm(request.POST, request.FILES)
|
||||
if f.is_valid():
|
||||
data = f.clean()
|
||||
content = request.FILES['file'].read()
|
||||
as_found = request.FILES.get('as_found')
|
||||
as_left = request.FILES.get('as_left')
|
||||
both = request.FILES.get('both')
|
||||
if both:
|
||||
if data['report_type'] == "TV":
|
||||
tv = parse_transducer(both.read().decode(), data['accuracy'])
|
||||
else:
|
||||
hc = parse_hardware_calibration(both.read().decode(), data['accuracy'])
|
||||
elif as_found and as_left:
|
||||
pass
|
||||
else:
|
||||
raise ValidationError("Please provide proper files")
|
||||
return HttpResponseRedirect("/success/url/")
|
||||
else:
|
||||
form = UploadFileForm()
|
||||
form = SheetForm()
|
||||
return render(request, "sheets/upload.html", {"form": form})
|
Loading…
Reference in New Issue
Block a user