From fe1541acbf3eebe1a5f8dfd98cfa7ba1d48f4d09 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Tue, 8 Oct 2019 01:33:38 +0100 Subject: [PATCH] Cables can now be created. --- assets/forms.py | 16 +++++---- .../management/commands/createSampleData.py | 12 +++++++ .../management/commands/deleteSampleData.py | 2 +- assets/templates/asset_create.html | 32 ++++++++--------- assets/views.py | 36 ++++++++++--------- 5 files changed, 58 insertions(+), 40 deletions(-) diff --git a/assets/forms.py b/assets/forms.py index 3b5ec6ea..e33c87ec 100644 --- a/assets/forms.py +++ b/assets/forms.py @@ -5,21 +5,25 @@ from assets import models class AssetForm(forms.ModelForm): - class Meta: - model = models.Asset - fields = '__all__' + def clean_date_sold(self): if self.cleaned_data["date_sold"] and self.cleaned_data["date_acquired"] > self.cleaned_data["date_sold"]: raise ValidationError("Cannot sell an item before it is acquired") return self.cleaned_data["date_sold"] + + class Meta: + model = models.Asset + fields = '__all__' + widgets = { + 'is_cable' : forms.CheckboxInput() + } class CableForm(AssetForm): - class Meta: + class Meta(AssetForm.Meta): model = models.Cable - fields = '__all__' -class SupplierForm(forms.ModelForm): +class SupplierForm(forms.Form): class Meta: model = models.Supplier fields = '__all__' diff --git a/assets/management/commands/createSampleData.py b/assets/management/commands/createSampleData.py index 0d5beeb0..d054b17d 100644 --- a/assets/management/commands/createSampleData.py +++ b/assets/management/commands/createSampleData.py @@ -21,6 +21,7 @@ class Command(BaseCommand): self.create_statuses() self.create_suppliers() self.create_assets() + self.create_connectors() def create_categories(self): categories = ['Case', 'Video', 'General', 'Sound', 'Lighting', 'Rigging'] @@ -60,3 +61,14 @@ class Command(BaseCommand): asset.purchased_from = random.choice(suppliers) asset.save() + + def create_connectors(self): + connectors = [ + { "description":"13A UK", "current_rating":13, "voltage_rating":230, "num_pins":3 }, + { "description":"16A", "current_rating":16, "voltage_rating":230, "num_pins":3 }, + { "description":"32/3", "current_rating":32, "voltage_rating":400, "num_pins":5 }, + { "description":"Socapex", "current_rating":23, "voltage_rating":600, "num_pins":19 }, + ] + for connector in connectors: + conn = models.Connector.objects.create(**connector) + conn.save() \ No newline at end of file diff --git a/assets/management/commands/deleteSampleData.py b/assets/management/commands/deleteSampleData.py index d58bee5f..f0338faa 100644 --- a/assets/management/commands/deleteSampleData.py +++ b/assets/management/commands/deleteSampleData.py @@ -21,7 +21,7 @@ class Command(BaseCommand): self.delete_objects(models.AssetCategory) self.delete_objects(models.AssetStatus) self.delete_objects(models.Supplier) - self.delete_objects(models.Collection) + self.delete_objects(models.Connector) self.delete_objects(models.Asset) def delete_objects(self, model): diff --git a/assets/templates/asset_create.html b/assets/templates/asset_create.html index ee6c9e60..a29c3635 100644 --- a/assets/templates/asset_create.html +++ b/assets/templates/asset_create.html @@ -58,7 +58,7 @@ {% endfor %} - {% render_field form.is_cable|attr:'onchange=checkIfCableHidden()' value=object.is_cable %} + {% render_field form.is_cable|attr:'onchange=checkIfCableHidden()' %}
+ +
- -
- - {% render_field cable_form.length|add_class:'form-control' %} - {{ cable_form.length.help_text }} + + {% render_field form.length|add_class:'form-control' %} + {{ form.length.help_text }}
- - {% render_field cable_form.csa|add_class:'form-control' value=object.csa %} - {{ cable_form.csa.help_text }} + + {% render_field form.csa|add_class:'form-control' value=object.csa %} + {{ form.csa.help_text }}
- - {% render_field cable_form.circuits|add_class:'form-control' value=object.circuits %} + + {% render_field form.circuits|add_class:'form-control' value=object.circuits %}
- - {% render_field cable_form.cores|add_class:'form-control' value=object.cores %} + + {% render_field form.cores|add_class:'form-control' value=object.cores %}
@@ -216,7 +216,7 @@ {% block js%}