-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Rack and RackItem Models and Forms * Add Views and URLs * Add Template Pages * MakeMigrations for Rack and RackItem * Migrate to Abstract Device Model for Client/Network Devices * Link RackItem and Network Device * Bugfixes * More Bugfixes * Generalise Device Create and Index Pages for Client and Network Devices * Delete Admin/Test Files * Rack Measure Conversions and Index * Add Networked vs Infrastructure Devices * Forms Folder for Network App * Make Migrations for Network Devices
- Loading branch information
1 parent
e7a8ba8
commit 60bcf5c
Showing
44 changed files
with
1,019 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def mm_to_inch(mm: float) -> float: | ||
"""Convert mm to Inches""" | ||
return mm / 25.4 | ||
|
||
|
||
def inch_to_mm(inch: float) -> float: | ||
"""Convert Inches to mm""" | ||
return inch * 25.4 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 5.0.2 on 2024-06-06 18:30 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("electric", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="circuit", | ||
name="breaker_type", | ||
field=models.CharField( | ||
choices=[ | ||
("fuse", "Fuse"), | ||
("mcb", "MCB"), | ||
("rcd", "RCD"), | ||
("RCBO", "rcbo"), | ||
("gfci", "GFCI"), | ||
], | ||
max_length=10, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 5.0.2 on 2024-07-08 18:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("electric", "0002_alter_circuit_breaker_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="circuit", | ||
name="breaker_type", | ||
field=models.CharField( | ||
choices=[ | ||
("fuse", "Fuse"), | ||
("mcb", "MCB"), | ||
("rcd", "RCD"), | ||
("rcbo", "RCBO"), | ||
("gfci", "GFCI"), | ||
], | ||
max_length=10, | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from django import forms | ||
|
||
from network.models import ClientDevice, NetworkDevice | ||
from network.models.device import InfrastructureDevice, NetworkedDevice | ||
from network.objects import ConnectionType | ||
|
||
class NetworkedDeviceForm(forms.ModelForm): | ||
|
||
connection_type = forms.ChoiceField( | ||
choices=ConnectionType.choices(), | ||
widget=forms.Select(attrs={"class": "form-control"}), | ||
) | ||
|
||
class Meta: | ||
model = NetworkedDevice | ||
abstract = True | ||
fields = [ | ||
"name", | ||
"mac_address", | ||
"vlan", | ||
"ip_address", | ||
"connection_type", | ||
"wifi", | ||
] | ||
|
||
def __init__(self, *args, vlan_options=None, wifi_options=None, **kwargs): | ||
super(NetworkedDeviceForm, self).__init__(*args, **kwargs) | ||
|
||
self.fields["vlan"].widget = forms.Select(choices=vlan_options, attrs={"class": "form-control"}) | ||
|
||
empty_choice = [("", "None")] | ||
|
||
self.fields["wifi"].widget = forms.Select(choices=empty_choice + wifi_options, attrs={"class": "form-control"}) | ||
self.fields["wifi"].required = False | ||
|
||
def clean(self): | ||
cleaned_data = super().clean() | ||
|
||
connection_type = cleaned_data.get("connection_type") | ||
wifi = cleaned_data.get("wifi") | ||
if connection_type == "ethernet" and wifi: | ||
raise forms.ValidationError("WiFi must be null for Ethernet Connections", code="invalid") | ||
if connection_type == "wifi" and not wifi: | ||
raise forms.ValidationError("WiFi must be set for WiFi Connections", code="invalid") | ||
|
||
return cleaned_data | ||
|
||
|
||
class ClientDeviceForm(NetworkedDeviceForm): | ||
class Meta(NetworkedDeviceForm.Meta): | ||
model = ClientDevice | ||
|
||
|
||
class NetworkDeviceForm(NetworkedDeviceForm): | ||
class Meta(NetworkedDeviceForm.Meta): | ||
model = NetworkDevice | ||
fields = NetworkedDeviceForm.Meta.fields + ["device_type"] | ||
|
||
|
||
class InfrastructureDeviceForm(forms.ModelForm): | ||
class Meta: | ||
model = InfrastructureDevice | ||
fields = ["name", "device_type"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django import forms | ||
|
||
from network.models import VLAN, WifiNetwork | ||
from network.models.ip import IpRange | ||
|
||
class IpRangeForm(forms.Form): | ||
|
||
description = forms.CharField(widget=forms.Textarea(attrs={"style": "height:50px;"}), required=False) | ||
|
||
class Meta: | ||
model = IpRange | ||
fields = ["start_address", "end_address", "num_addresses", "description"] | ||
|
||
|
||
class VLANForm(forms.ModelForm): | ||
|
||
description = forms.CharField(widget=forms.Textarea(attrs={"style": "height:50px;"}), required=False) | ||
|
||
class Meta: | ||
model = VLAN | ||
fields = ["vlan_id", "name", "description"] | ||
|
||
|
||
class WifiForm(forms.ModelForm): | ||
class Meta: | ||
model = WifiNetwork | ||
fields = ["ssid", "password"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django import forms | ||
|
||
from network.models import Rack, RackItem | ||
|
||
class RackForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = Rack | ||
fields = ["name", "width", "rack_units"] | ||
|
||
|
||
class RackItemForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = RackItem | ||
fields = ["name", "rack_units", "rack", "device"] | ||
|
||
def __init__(self, *args, rack_options=None, device_options=None, **kwargs): | ||
super(RackItemForm, self).__init__(*args, **kwargs) | ||
|
||
self.fields["rack"].widget = forms.Select(choices=rack_options, attrs={"class": "form-control"}) | ||
|
||
self.fields["device"].widget = forms.Select(choices=device_options, attrs={"class": "form-control"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Generated by Django 5.0.2 on 2024-06-06 18:05 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("network", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Rack", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=50)), | ||
( | ||
"width", | ||
models.PositiveIntegerField( | ||
choices=[(10, "WIDTH_10"), (19, "WIDTH_19"), (23, "WIDTH_23")] | ||
), | ||
), | ||
("rack_units", models.FloatField()), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="RackItem", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=50)), | ||
("rack_units", models.FloatField()), | ||
( | ||
"rack", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="rack_items", | ||
to="network.rack", | ||
), | ||
), | ||
], | ||
), | ||
] |
Oops, something went wrong.