init
Some checks failed
Build And Test / build-and-push (push) Failing after 53s

This commit is contained in:
2024-12-13 17:12:03 +09:00
parent a27be94b19
commit ea11832a53
695 changed files with 71766 additions and 1 deletions

0
nhnc_mgmt/__init__.py Normal file
View File

4
nhnc_mgmt/admin.py Normal file
View File

@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Igw
admin.site.register(Igw)

6
nhnc_mgmt/apps.py Normal file
View File

@ -0,0 +1,6 @@
from django.apps import AppConfig
class NhncMgmtConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'nhnc_mgmt'

View File

@ -0,0 +1,23 @@
# Generated by Django 4.2.14 on 2024-11-15 15:47
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Igw',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, unique=True)),
('routing_table', models.CharField(max_length=200, unique=True)),
('external_network_name', models.CharField(max_length=50, null=True)),
],
),
]

View File

@ -0,0 +1,31 @@
# Generated by Django 4.2.14 on 2024-11-15 15:48
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('nhnc_mgmt', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='igw',
name='author',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='igw',
name='created_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='igw',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
]

View File

@ -0,0 +1,32 @@
# Generated by Django 4.2.14 on 2024-11-15 16:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('nhnc_mgmt', '0002_igw_author_igw_created_at_igw_updated_at'),
]
operations = [
migrations.RenameField(
model_name='igw',
old_name='title',
new_name='igw_name',
),
migrations.RemoveField(
model_name='igw',
name='external_network_name',
),
migrations.AddField(
model_name='igw',
name='igw_id',
field=models.CharField(max_length=100, null=True),
),
migrations.AlterField(
model_name='igw',
name='routing_table',
field=models.CharField(max_length=200, null=True, unique=True),
),
]

View File

15
nhnc_mgmt/models.py Normal file
View File

@ -0,0 +1,15 @@
from django.db import models
from django.conf import settings
class Igw(models.Model):
igw_name = models.CharField(max_length=100, unique=True)
igw_id = models.CharField(max_length=100, null=True)
routing_table = models.CharField(max_length=200, unique=True, null=True)
created_at = models.DateTimeField(auto_now=True)
updated_at = models.DateTimeField(auto_now=True)
author = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete=models.CASCADE)
def __str__(self):
return f'[{self.pk}] {self.igw_name}'

View File

@ -0,0 +1,116 @@
{% extends "components/base.html" %}
{% block igw_name %}IP Management{% endblock %}
{% block main_area %}
<h2 class="fw-bold pt-3 pb-2">Igw 관리 대장</h2>
{% if not request.user.is_authenticated %}
<p class="text-danger">비로그인 익명사용자로 접근 중입니다.
{% endif %}
<form id="recordForm" method="post" action="">
{% csrf_token %}
<table class="table table-striped table-hover table-bordered">
<thead class="table-dark">
<tr>
<th scope="col">Select</th>
<th scope="col">Igw Name</th>
<th scope="col">Igw ID</th>
<th scope="col">routing_table</th>
</tr>
</thead>
<tbody>
{% for record in records %}
<tr data-record-id="{{ record.id }}">
<td class="text-center">
<input type="checkbox" name="selected_records" value="{{ record.id }}" class="form-check-input record-checkbox">
</td>
<td>{{ record.igw_name }}</td>
<td>{{ record.igw_id }}</td>
<td>{{ record.routing_table }}</td>
</tr>
{% empty %}
<tr>
<td colspan="9" class="text-center">No records found.</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if request.user.is_authenticated %}
<!-- 버튼 컨테이너 -->
<div class="d-flex justify-content-between align-items-center mb-3">
<!-- 데이터 등록 버튼 -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addDataModal">
<i class="bi bi-plus-lg"></i>
Add New Igw Record
</button>
<!-- 전체 삭제 버튼 -->
<button type="submit" formaction="{% url 'nhnc_mgmt:igw_delete' %}" class="btn btn-danger">
<i class="bi bi-trash"></i>
Delete Selected
</button>
</div>
{% endif %}
</form>
<!-- 데이터 등록 모달 -->
<div class="modal fade" id="addDataModal" tabindex="-1" aria-labelledby="addDataModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-success text-white">
<h5 class="modal-igw_name" id="addDataModalLabel">Add New IP Record</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- 데이터 등록 폼 -->
<form id="addDataForm" method="post" action="{% url 'nhnc_mgmt:igw_add' %}">
{% csrf_token %}
<div class="mb-3">
<label for="igw_name" class="form-label">Igw Name</label>
<input type="text" class="form-control" id="igw_name" name="igw_name" required="required">
</div>
<div class="mb-3">
<label for="routing_table" class="form-label">routing_table</label>
<input type="text" class="form-control" id="routing_table" name="routing_table" required="required">
</div>
<div class="mb-3">
<label for="igw_id" class="form-label">igw_id</label>
<input type="text" class="form-control" id="igw_id" name="igw_id" required="required">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const editButton = document.getElementById('editSelectedButton');
const checkboxes = document.querySelectorAll('.record-checkbox');
// Event listener to enable/disable the edit button
document.addEventListener('change', function () {
const selected = [...checkboxes].filter(checkbox => checkbox.checked);
if (selected.length === 1) {
editButton.disabled = false;
editButton.dataset.recordId = selected[0].value;
} else {
editButton.disabled = true;
delete editButton.dataset.recordId;
}
});
// Event listener to open the edit modal
editButton.addEventListener('click', function () {
const recordId = editButton.dataset.recordId;
if (recordId) {
const modal = new bootstrap.Modal(document.getElementById(`editDataModal-${recordId}`));
modal.show();
}
});
});
</script>
{% endblock %}

3
nhnc_mgmt/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
nhnc_mgmt/urls.py Normal file
View File

@ -0,0 +1,10 @@
from django.urls import path
from . import views
app_name = 'nhnc_mgmt'
urlpatterns = [
path('igw', views.igw_view, name='igw'),
path('igw/add/', views.add_igw_record, name='igw_add'), # 데이터 추가 경로
path('igw/delete/', views.delete_igw_records, name='igw_delete'), # 삭제 URL 추가
]

37
nhnc_mgmt/views.py Normal file
View File

@ -0,0 +1,37 @@
from django.shortcuts import render, redirect, get_object_or_404
from .models import Igw
def igw_view(request):
if request.user.is_authenticated:
records = Igw.objects.filter(author=request.user)
else:
records = Igw.objects.all()
return render(
request,
'nhnc_mgmt/network_igw.html',
{
'records' : records
})
def add_igw_record(request):
if request.method == 'POST':
igw_name = request.POST.get('igw_name')
routing_table = request.POST.get('routing_table')
igw_id = request.POST.get('igw_id')
author = request.user
# 데이터 저장
Igw.objects.create(
igw_name=igw_name,
routing_table=routing_table,
igw_id=igw_id,
author=author
)
return redirect('/nhnc_mgmt/igw')
def delete_igw_records(request):
print(f"삭제동작")
if request.method == 'POST':
selected_ids = request.POST.getlist('selected_records')
if selected_ids:
Igw.objects.filter(id__in=selected_ids).delete()
return redirect('/nhnc_mgmt/igw')