-
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.
Voltage Config Value Circuit Model/CRUD Pages
- Loading branch information
1 parent
114c68f
commit 5b3d833
Showing
25 changed files
with
325 additions
and
10 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
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ElectricConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "electric" |
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,16 @@ | ||
from django import forms | ||
|
||
from .models.circuits import Circuit | ||
|
||
class CircuitForm(forms.ModelForm): | ||
|
||
breaker_type = forms.ChoiceField(choices=Circuit.BREAKER_TYPES, widget=forms.Select(attrs={"class": "form-control"})) | ||
circuit_type = forms.ChoiceField(choices=Circuit.CIRCUIT_TYPES, widget=forms.Select(attrs={"class": "form-control"})) | ||
|
||
spd_protection = forms.BooleanField(label="SPD Protection", required=False) | ||
|
||
description = forms.CharField(widget=forms.Textarea(attrs={"style": "height:50px;"}), required=False) | ||
|
||
class Meta: | ||
model = Circuit | ||
fields = ["name", "current_rating", "breaker_type", "spd_protection", "wire_diameter", "circuit_type", "description"] |
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,57 @@ | ||
# Generated by Django 5.0.2 on 2024-03-18 22:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Circuit", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=100)), | ||
("current_rating", models.IntegerField()), | ||
( | ||
"breaker_type", | ||
models.CharField( | ||
choices=[ | ||
("fuse", "Fuse"), | ||
("mcb", "MCB"), | ||
("rcd", "RCD"), | ||
("gfci", "GFCI"), | ||
], | ||
max_length=10, | ||
), | ||
), | ||
("spd_protection", models.BooleanField()), | ||
("wire_diameter", models.FloatField()), | ||
( | ||
"circuit_type", | ||
models.CharField( | ||
choices=[ | ||
("lighting", "Lighting"), | ||
("outlet", "Outlet"), | ||
("appliance", "Appliance"), | ||
("heating", "Heating"), | ||
("cooling", "Cooling"), | ||
], | ||
max_length=20, | ||
), | ||
), | ||
("description", models.TextField(blank=True)), | ||
], | ||
), | ||
] |
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 @@ | ||
from .circuits import Circuit |
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,34 @@ | ||
from common.utils.config import get_config_value | ||
from django.db import models | ||
|
||
|
||
class Circuit(models.Model): | ||
BREAKER_TYPES = ( | ||
("fuse", "Fuse"), | ||
("mcb", "MCB"), | ||
("rcd", "RCD"), | ||
("gfci", "GFCI"), | ||
) | ||
|
||
CIRCUIT_TYPES = ( | ||
("lighting", "Lighting"), | ||
("outlet", "Outlets"), | ||
("appliance", "Appliance"), | ||
("heating", "Heating"), | ||
("cooling", "Cooling"), | ||
) | ||
|
||
name = models.CharField(max_length=100) | ||
current_rating = models.IntegerField() | ||
breaker_type = models.CharField(max_length=10, choices=BREAKER_TYPES) | ||
spd_protection = models.BooleanField() # Surge Protection Device | ||
wire_diameter = models.FloatField() | ||
circuit_type = models.CharField(max_length=20, choices=CIRCUIT_TYPES) | ||
description = models.TextField(blank=True) | ||
|
||
@property | ||
def power_rating(self) -> float: | ||
return self.current_rating * get_config_value("voltage", 0) | ||
|
||
def __str__(self): | ||
return self.name |
17 changes: 17 additions & 0 deletions
17
NetworkMapper/electric/templates/electric/circuit/create.html
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,17 @@ | ||
{% extends "base/crud.html" %} | ||
|
||
{% block title_content %} | ||
Create Circuit | ||
{% endblock %} | ||
|
||
{% block header_content %} | ||
Create Circuit | ||
{% endblock %} | ||
|
||
{% block form_action %} | ||
{% url 'circuit.create' %} | ||
{% endblock %} | ||
|
||
{% block back_link %} | ||
{% url 'circuit.index' %} | ||
{% endblock %} |
17 changes: 17 additions & 0 deletions
17
NetworkMapper/electric/templates/electric/circuit/edit.html
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,17 @@ | ||
{% extends "base/crud.html" %} | ||
|
||
{% block title_content %} | ||
Edit Circuit | ||
{% endblock %} | ||
|
||
{% block header_content %} | ||
Edit Circuit - {{ circuit.name }} | ||
{% endblock %} | ||
|
||
{% block form_action %} | ||
{% url 'circuit.edit' circuit.id %} | ||
{% endblock %} | ||
|
||
{% block back_link %} | ||
{% url 'circuit.index' %} | ||
{% endblock %} |
33 changes: 33 additions & 0 deletions
33
NetworkMapper/electric/templates/electric/circuit/index.html
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,33 @@ | ||
{% extends "base/index.html" %} | ||
|
||
{% block title_content %} | ||
Circuits | ||
{% endblock %} | ||
|
||
{% block header_content %} | ||
Circuits | ||
{% endblock %} | ||
|
||
{% block create_link %} | ||
{% url 'circuit.create' %} | ||
{% endblock %} | ||
|
||
{% block table_head %} | ||
<tr> | ||
<th>Circuit</th> | ||
</tr> | ||
{% endblock %} | ||
|
||
{% block table_body %} | ||
{% for circuit in circuits %} | ||
<tr> | ||
<td>{{ circuit.name }}</td> | ||
<td> | ||
<a href="{% url 'circuit.edit' circuit.id %}">Edit</a> | ||
</td> | ||
<td> | ||
<a href="{% url 'circuit.delete' circuit.id %}">Delete</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
{% endblock %} |
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 @@ | ||
{% extends "base/master.html" %} | ||
|
||
|
||
{% block title %} | ||
Electric | ||
{% endblock %} | ||
|
||
|
||
{% block content %} | ||
|
||
<div class="container mt-5"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-5"> | ||
<h2>Voltage</h2> | ||
<form method="post" action="{% url 'electric_index' %}"> | ||
{% csrf_token %} | ||
<div class="form-group d-flex"> | ||
<label for="voltage">Voltage:</label> | ||
<input type="text" id="voltage" name="voltage" value="{{ voltage }}" class="form-control"> | ||
<button type="submit" name="voltage-submit" class="btn btn-primary">Save</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
{% endblock %} |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,11 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
path("", views.index.index, name="electric_index"), | ||
path("circuit", views.circuit.index, name="circuit.index"), | ||
path("circuit/create", views.circuit.create, name="circuit.create"), | ||
path("circuit/<int:id>/edit", views.circuit.edit, name="circuit.edit"), | ||
path("circuit/<int:id>/delete", views.circuit.delete, name="circuit.delete"), | ||
] |
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 @@ | ||
from . import circuit, index |
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,40 @@ | ||
from django.shortcuts import get_object_or_404, redirect, render | ||
|
||
from ..forms import CircuitForm | ||
from ..models.circuits import Circuit | ||
|
||
def index(request): | ||
circuits = Circuit.objects.all() | ||
return render(request, "electric/circuit/index.html", {"circuits": circuits}) | ||
|
||
|
||
def create(request): | ||
if request.method == "POST": | ||
form = CircuitForm(request.POST) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect("circuit.index") | ||
else: | ||
form = CircuitForm() | ||
|
||
return render(request, "electric/circuit/create.html", {"form": form}) | ||
|
||
|
||
def edit(request, id: int): | ||
circuit = get_object_or_404(Circuit, id=id) | ||
|
||
if request.method == "POST": | ||
form = CircuitForm(request.POST, instance=circuit) | ||
if form.is_valid(): | ||
form.save() | ||
return redirect("circuit.index") | ||
else: | ||
form = CircuitForm(instance=circuit) | ||
|
||
return render(request, "electric/circuit/edit.html", {"form": form, "circuit": circuit}) | ||
|
||
|
||
def delete(request, id: int): | ||
circuit = get_object_or_404(Circuit, id=id) | ||
circuit.delete() | ||
return redirect("circuit.index") |
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,15 @@ | ||
from common.utils.config import get_config_value, update_config_value | ||
from django.shortcuts import redirect, render | ||
from django.urls import reverse | ||
|
||
|
||
def index(request): | ||
if request.method == "POST": | ||
if "voltage-submit" in request.POST: | ||
voltage = request.POST.get("voltage") | ||
update_config_value("voltage", voltage) | ||
return redirect(reverse("electric_index")) | ||
|
||
voltage = get_config_value("voltage", 0) | ||
|
||
return render(request, "electric/index.html", {"voltage": voltage}) |
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,31 @@ | ||
# Generated by Django 5.0.2 on 2024-03-18 22:32 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("ip", "0003_clientdevice"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="IpRange", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("start_address", models.GenericIPAddressField()), | ||
("end_address", models.GenericIPAddressField()), | ||
("num_addresses", models.PositiveIntegerField()), | ||
("description", models.TextField(blank=True, null=True)), | ||
], | ||
), | ||
] |
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
Oops, something went wrong.