mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 00:42:17 +00:00
Move relevant fields and create migration to autogen cable types
This commit is contained in:
@@ -92,7 +92,7 @@ class Command(BaseCommand):
|
|||||||
csa=random.choice(csas),
|
csa=random.choice(csas),
|
||||||
length=random.choice(lengths),
|
length=random.choice(lengths),
|
||||||
circuits=random.choice(circuits),
|
circuits=random.choice(circuits),
|
||||||
cores=random.choice(circuits)
|
cores=random.choice(cores)
|
||||||
)
|
)
|
||||||
|
|
||||||
if i % 5 == 0:
|
if i % 5 == 0:
|
||||||
|
|||||||
29
assets/migrations/0011_auto_20200218_1617.py
Normal file
29
assets/migrations/0011_auto_20200218_1617.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 2.0.13 on 2020-02-18 16:17
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0010_auto_20200207_1737'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='CableType',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('circuits', models.IntegerField(blank=True, null=True)),
|
||||||
|
('cores', models.IntegerField(blank=True, null=True)),
|
||||||
|
('plug', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='plug', to='assets.Connector')),
|
||||||
|
('socket', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='socket', to='assets.Connector')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='asset',
|
||||||
|
name='cable_type',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='assets.CableType'),
|
||||||
|
),
|
||||||
|
]
|
||||||
26
assets/migrations/0012_auto_20200218_1627.py
Normal file
26
assets/migrations/0012_auto_20200218_1627.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 2.0.13 on 2020-02-18 16:27
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
|
||||||
|
def move_cable_type_data(apps, schema_editor):
|
||||||
|
Asset = apps.get_model('assets', 'Asset')
|
||||||
|
CableType = apps.get_model('assets', 'CableType')
|
||||||
|
for asset in Asset.objects.filter(is_cable=True):
|
||||||
|
# Only create one type per...well...type
|
||||||
|
if(not CableType.objects.filter(Q(plug=asset.plug) & Q(socket=asset.socket))):
|
||||||
|
cabletype = CableType.objects.create(plug=asset.plug, socket=asset.socket, circuits=asset.circuits, cores=asset.cores)
|
||||||
|
asset.save()
|
||||||
|
cabletype.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0011_auto_20200218_1617'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(move_cable_type_data)
|
||||||
|
]
|
||||||
29
assets/migrations/0013_auto_20200218_1639.py
Normal file
29
assets/migrations/0013_auto_20200218_1639.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Generated by Django 2.0.13 on 2020-02-18 16:39
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0012_auto_20200218_1627'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='asset',
|
||||||
|
name='circuits',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='asset',
|
||||||
|
name='cores',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='asset',
|
||||||
|
name='plug',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='asset',
|
||||||
|
name='socket',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -66,6 +66,18 @@ class Connector(models.Model):
|
|||||||
return self.description
|
return self.description
|
||||||
|
|
||||||
|
|
||||||
|
class CableType(models.Model):
|
||||||
|
circuits = models.IntegerField(blank=True, null=True)
|
||||||
|
cores = models.IntegerField(blank=True, null=True)
|
||||||
|
plug = models.ForeignKey(Connector, on_delete=models.SET_NULL,
|
||||||
|
related_name='plug', blank=True, null=True)
|
||||||
|
socket = models.ForeignKey(Connector, on_delete=models.SET_NULL,
|
||||||
|
related_name='socket', blank=True, null=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.plug.description + "--->" + self.socket.description
|
||||||
|
|
||||||
|
|
||||||
@reversion.register
|
@reversion.register
|
||||||
class Asset(models.Model, RevisionMixin):
|
class Asset(models.Model, RevisionMixin):
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -92,16 +104,12 @@ class Asset(models.Model, RevisionMixin):
|
|||||||
|
|
||||||
# Cable assets
|
# Cable assets
|
||||||
is_cable = models.BooleanField(default=False)
|
is_cable = models.BooleanField(default=False)
|
||||||
plug = models.ForeignKey(Connector, on_delete=models.SET_NULL,
|
cable_type = models.ForeignKey(to=CableType, blank=True, null=True, on_delete=models.SET_NULL)
|
||||||
related_name='plug', blank=True, null=True)
|
|
||||||
socket = models.ForeignKey(Connector, on_delete=models.SET_NULL,
|
|
||||||
related_name='socket', blank=True, null=True)
|
|
||||||
length = models.DecimalField(decimal_places=1, max_digits=10,
|
length = models.DecimalField(decimal_places=1, max_digits=10,
|
||||||
blank=True, null=True, help_text='m')
|
blank=True, null=True, help_text='m')
|
||||||
csa = models.DecimalField(decimal_places=2, max_digits=10,
|
csa = models.DecimalField(decimal_places=2, max_digits=10,
|
||||||
blank=True, null=True, help_text='mm^2')
|
blank=True, null=True, help_text='mm^2')
|
||||||
circuits = models.IntegerField(blank=True, null=True)
|
|
||||||
cores = models.IntegerField(blank=True, null=True)
|
|
||||||
|
|
||||||
# Hidden asset_id components
|
# Hidden asset_id components
|
||||||
# For example, if asset_id was "C1001" then asset_id_prefix would be "C" and number "1001"
|
# For example, if asset_id was "C1001" then asset_id_prefix would be "C" and number "1001"
|
||||||
|
|||||||
37
assets/templates/cable_type_form.html
Normal file
37
assets/templates/cable_type_form.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{% extends 'base_assets.html' %}
|
||||||
|
{% load widget_tweaks %}
|
||||||
|
{% block title %}Asset {{ object.asset_id }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>
|
||||||
|
Create Cable Type
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<form method="post" id="asset_update_form" action="{% url 'asset_create'%}">
|
||||||
|
{% include 'form_errors.html' %}
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="id" value="{{ object.id|default:0 }}" hidden=true>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.plug.id_for_label }}">Plug</label>
|
||||||
|
{% render_field form.plug|add_class:'form-control'%}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.socket.id_for_label }}">Socket</label>
|
||||||
|
{% render_field form.socket|add_class:'form-control'%}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.circuits.id_for_label }}">Circuits</label>
|
||||||
|
{% render_field form.circuits|add_class:'form-control' value=object.circuits %}
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.cores.id_for_label }}">Cores</label>
|
||||||
|
{% render_field form.cores|add_class:'form-control' value=object.cores %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
<label for="{{ form.category.id_for_label }}" >Category</label>
|
<label for="{{ form.category.id_for_label }}" >Category</label>
|
||||||
{% render_field form.category|add_class:'form-control'%}
|
{% render_field form.category|add_class:'form-control'%}
|
||||||
</div>
|
</div>
|
||||||
{% render_field form.is_cable|attr:'onchange=checkIfCableHidden()' %} <label for="{{ form.is_cable.id_for_label }}">Cable?</label>
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ form.status.id_for_label }}" >Status</label>
|
<label for="{{ form.status.id_for_label }}" >Status</label>
|
||||||
{% render_field form.status|add_class:'form-control'%}
|
{% render_field form.status|add_class:'form-control'%}
|
||||||
@@ -32,6 +31,10 @@
|
|||||||
<label for="{{ form.serial_number.id_for_label }}">Serial Number</label>
|
<label for="{{ form.serial_number.id_for_label }}">Serial Number</label>
|
||||||
{% render_field form.serial_number|add_class:'form-control' value=object.serial_number %}
|
{% render_field form.serial_number|add_class:'form-control' value=object.serial_number %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.is_cable.id_for_label }}">Cable?</label>
|
||||||
|
{% render_field form.is_cable|attr:'onchange=checkIfCableHidden()' %}
|
||||||
|
</div>
|
||||||
<!---TODO: Lower default number of lines in comments box-->
|
<!---TODO: Lower default number of lines in comments box-->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ form.comments.id_for_label }}">Comments</label>
|
<label for="{{ form.comments.id_for_label }}">Comments</label>
|
||||||
|
|||||||
@@ -6,12 +6,11 @@
|
|||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
{% if create or edit or duplicate %}
|
{% if create or edit or duplicate %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ form.plug.id_for_label }}">Plug</label>
|
<label for="{{ form.cable_type.id_for_label }}">Cable Type</label>
|
||||||
{% render_field form.plug|add_class:'form-control'%}
|
<div class="input-group">
|
||||||
</div>
|
{% render_field form.cable_type|add_class:'form-control' %}
|
||||||
<div class="form-group">
|
<span class="input-group-addon">{{ form.length.help_text }}</span>
|
||||||
<label for="{{ form.socket.id_for_label }}">Socket</label>
|
</div>
|
||||||
{% render_field form.socket|add_class:'form-control'%}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{ form.length.id_for_label }}">Length</label>
|
<label for="{{ form.length.id_for_label }}">Length</label>
|
||||||
@@ -27,14 +26,6 @@
|
|||||||
<span class="input-group-addon">{{ form.csa.help_text }}</span>
|
<span class="input-group-addon">{{ form.csa.help_text }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label for="{{ form.circuits.id_for_label }}">Circuits</label>
|
|
||||||
{% render_field form.circuits|add_class:'form-control' value=object.circuits %}
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="{{ form.cores.id_for_label }}">Cores</label>
|
|
||||||
{% render_field form.cores|add_class:'form-control' value=object.cores %}
|
|
||||||
</div>
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<dl>
|
<dl>
|
||||||
<dt>Socket</dt>
|
<dt>Socket</dt>
|
||||||
|
|||||||
Reference in New Issue
Block a user