diff --git a/assets/forms.py b/assets/forms.py index 0ccd32f3..6f2e5dc1 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -3,7 +3,6 @@ from django.db.models import Q from assets import models - class AssetForm(forms.ModelForm): related_models = { 'asset': models.Asset, diff --git a/assets/templates/cable_test_form.html b/assets/templates/cable_test_form.html new file mode 100644 index 00000000..10332c35 --- /dev/null +++ b/assets/templates/cable_test_form.html @@ -0,0 +1,28 @@ +{% extends 'base_assets.html' %} +{% load widget_tweaks %} +{% load button from filters %} +{% load cache %} + +{% block content %} + {% if create %} +
+ {% elif edit %} + + {% endif %} +{% include 'form_errors.html' %} +{% csrf_token %} + +
+
+ {% for field in form %} +
+ {% include 'partials/form_field.html' with field=field %} +
+ {% endfor %} +
+ {% button 'submit' %} +
+
+
+
+{% endblock %} diff --git a/assets/testing.py b/assets/testing.py new file mode 100644 index 00000000..72063775 --- /dev/null +++ b/assets/testing.py @@ -0,0 +1,42 @@ +from django.db import models + +from . import models as am + + +class Test(models.Model): + item = models.ForeignKey(to=am.Asset, on_delete=models.CASCADE) + date = models.DateField() + tested_by = models.ForeignKey(to='RIGS.Profile', on_delete=models.CASCADE) + + +class ElectricalTest(Test): + visual = models.BooleanField() + remarks = models.TextField() + + +class CableTest(ElectricalTest): + # Should contain X circuit tests, where X is determined by circuits as per cable type + pass + + +class CircuitTest(models.Model): + test = models.ForeignKey(to=CableTest, on_delete=models.CASCADE) + continuity = models.DecimalField(help_text='Ω') + insulation_resistance = models.DecimalField(help_text='MΩ') + + +class TestRequirement(models.Model): + item = models.ForeignKey(to=am.Asset, on_delete=models.CASCADE) + test_type = models.ForeignKey(to=Test, on_delete=models.CASCADE) + period = models.IntegerField() # X months + + +class CableTestForm(forms.ModelForm): + class Meta + model = CableTest + + +class CircuitTest(forms.ModelForm): + class Meta: + model = Choice + exclude = ('test',) diff --git a/assets/urls.py b/assets/urls.py index 3091b84b..5d8403ae 100644 --- a/assets/urls.py +++ b/assets/urls.py @@ -43,4 +43,6 @@ urlpatterns = [ (views.SupplierCreate.as_view()), name='supplier_create'), path('supplier//edit/', permission_required_with_403('assets.change_supplier') (views.SupplierUpdate.as_view()), name='supplier_update'), + + path('testing//cable_test/' views.AddCableTest.as_view(), name='cable_test'), ] diff --git a/assets/views.py b/assets/views.py index 4ad4c94c..f5005380 100644 --- a/assets/views.py +++ b/assets/views.py @@ -24,7 +24,7 @@ from z3c.rml import rml2pdf from PyRIGS.views import GenericListView, GenericDetailView, GenericUpdateView, GenericCreateView, ModalURLMixin, \ is_ajax, OEmbedView -from assets import forms, models +from assets import forms, models, testing class AssetList(LoginRequiredMixin, generic.ListView): @@ -430,3 +430,8 @@ class GenerateLabels(generic.View): response['Content-Disposition'] = f'filename="{name}"' response.write(merged.getvalue()) return response + + +class AddCableTest(generic.CreateView): + model = testing.CableTest + template = 'cable_test_form.html'