Skip to content

Commit

Permalink
#43 サービス情報と接続情報の登録機能の実装.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoneyan committed Sep 14, 2024
1 parent 66f50e7 commit 832fbad
Show file tree
Hide file tree
Showing 41 changed files with 2,506 additions and 126 deletions.
44 changes: 40 additions & 4 deletions custom_auth/admin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
from django.contrib import admin
from django.urls import reverse
from django.utils.html import format_html

from custom_auth.models import Group, TOTPDevice, User, UserActivateToken
from ip.models import JPNICUser
from service.models import Service


class TermInlineUserAdmin(admin.TabularInline):
model = User.groups.through
extra = 1
extra = 0


class TermInlineGroupAdmin(admin.TabularInline):
model = Group.users.through
extra = 1
extra = 0


class TermInlineGroupServiceAdmin(admin.TabularInline):
model = Service
extra = 0
fields = ("service_code", "service_type", "service_number", "is_active", "is_pass")
readonly_fields = ("service_code", "service_type", "service_number", "is_active", "is_pass")

def service_code(self, obj):
# 管理ページの編集ページへのリンクを生成
url = reverse("admin:service_service_change", args=[obj.id])
return format_html('<a href="{}" target="__blank__">{}</a>', url, obj.service_code)

service_code.short_description = "ServiceCode"


class TermInlineGroupJPNICAdmin(admin.TabularInline):
model = JPNICUser
extra = 0
fields = ("id_link", "jpnic_handle", "name", "org", "is_pass")
readonly_fields = ("id_link", "jpnic_handle", "name", "org", "is_pass")

def id_link(self, obj):
# 管理ページの編集ページへのリンクを生成
url = reverse("admin:ip_jpnicuser_change", args=[obj.id])
return format_html('<a href="{}" target="__blank__">{}</a>', url, obj.id)

id_link.short_description = "ID"


@admin.register(User)
Expand Down Expand Up @@ -47,7 +79,7 @@ def get_groups(self, obj):
@admin.register(Group)
class Group(admin.ModelAdmin):
fieldsets = (
(None, {"fields": ("name", "name_jp", "allow_service_add", "is_pass", "comment")}),
(None, {"fields": ("name", "name_jp", "allow_service_add", "allow_jpnic_add", "is_pass", "comment")}),
("Membership", {"fields": ("membership_type", "membership_expired_at")}),
("Question", {"fields": ("agree", "question")}),
("Stripe", {"fields": ("stripe_customer_id", "stripe_subscription_id")}),
Expand Down Expand Up @@ -85,7 +117,11 @@ class Group(admin.ModelAdmin):
"updated_at",
)

inlines = (TermInlineGroupAdmin,)
inlines = (
TermInlineGroupAdmin,
TermInlineGroupServiceAdmin,
TermInlineGroupJPNICAdmin,
)


@admin.register(UserActivateToken)
Expand Down
18 changes: 18 additions & 0 deletions custom_auth/migrations/0006_group_allow_jpnic_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-09-13 16:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('custom_auth', '0005_alter_group_status'),
]

operations = [
migrations.AddField(
model_name='group',
name='allow_jpnic_add',
field=models.BooleanField(default=False, verbose_name='JPNIC情報追加許可'),
),
]
1 change: 1 addition & 0 deletions custom_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Group(models.Model): # noqa: F811
comment = models.CharField("comment", max_length=250, default="", blank=True)
status = models.IntegerField("ステータス", default=1, choices=GROUP_STATUS_CHOICES)
allow_service_add = models.BooleanField("サービス追加許可", default=False)
allow_jpnic_add = models.BooleanField("JPNIC情報追加許可", default=False)
membership_type = models.IntegerField("会員種別", default=1, choices=MEMBERSHIP_TYPE_CHOICES)
membership_expired_at = models.DateTimeField("有効期限", blank=True, null=True)

Expand Down
2 changes: 1 addition & 1 deletion custom_auth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
app_name = "custom_auth"
urlpatterns = [
path("", views.index, name="index"),
path("passwor", views.password_change, name="password_change"),
path("password", views.password_change, name="password_change"),
path("email", views.change_email, name="email_change"),
path("edit", views.edit_profile, name="edit_profile"),
path("two_auth", views.list_two_auth, name="list_two_auth"),
Expand Down
2 changes: 2 additions & 0 deletions dsbd/templates/base2.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<!-- jquery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<style>
#parent {
Expand Down
218 changes: 218 additions & 0 deletions dsbd/templates/connection/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
{% extends 'base2.html' %}
{% block content %}
<div class="container">
<div class="row">
<div class="container py-4 mb-auto">
<div class="h-900 p-2 rounded-3">
<h2 class="card-title">接続情報新規申請</h2>
<br/>
<form method="post" class="h-adr">
{% csrf_token %}
<h4>0. サービス情報</h4>
<input type="text" class="form-control" value="{{ service_code }}" disabled>
<br/>
<h4>{{ form.connection_type.label }}</h4>
{{ form.connection_type }}
{% if form.connection_type.errors %}
<p class="link-danger">{{ form.connection_type.errors | striptags }}</p>
{% endif %}
<div id="connectionCommentField" style="display: none;">
<h5>{{ form.connection_comment.label }}</h5>
{{ form.connection_comment }}
{% if form.connection_comment.errors %}
<p class="link-danger">{{ form.connection_comment.errors | striptags }}</p>
{% endif %}
</div>
<br/>
{% if is_ipv4_bgp or is_ipv6_bgp %}
<h5>1.2.広報する経路</h5>
<div class="container">
<div class="row align-items-start">
{% if is_ipv4_bgp %}
<div class="col">
<h5>{{ form.ipv4_route.label }}</h5>
{{ form.ipv4_route }}
{% if form.ipv4_route.errors %}
<p class="link-danger">{{ form.ipv4_route.errors | striptags }}</p>
{% endif %}
<br/>
<h5>{{ form.ipv4_route_comment.label }}</h5>
{{ form.ipv4_route_comment }}
{% if form.ipv4_route_comment.errors %}
<p class="link-danger">{{ form.ipv4_route_comment.errors | striptags }}</p>
{% endif %}
</div>
{% endif %}
{% if is_ipv6_bgp %}
<div class="col">
<h5>{{ form.ipv6_route.label }}</h5>
{{ form.ipv6_route }}
{% if form.ipv6_route.errors %}
<p class="link-danger">{{ form.ipv6_route.errors | striptags }}</p>
{% endif %}
<br/>
<h5>{{ form.ipv6_route_comment.label }}</h5>
{{ form.ipv6_route_comment }}
{% if form.ipv6_route_comment.errors %}
<p class="link-danger">{{ form.ipv6_route_comment.errors | striptags }}</p>
{% endif %}
</div>
{% endif %}
</div>
</div>
<br/>
{% endif %}
<h4>2. 接続情報や場所など</h4>
<h5>{{ form.hope_location.label }}</h5>
{{ form.hope_location }}
{% if form.hope_location.errors %}
<p class="link-danger">{{ form.hope_location.errors | striptags }}</p>
{% endif %}
<br/>
<h5>{{ form.term_location.label }}</h5>
{{ form.term_location }}
{% if form.term_location.errors %}
<p class="link-danger">{{ form.term_location.errors | striptags }}</p>
{% endif %}
<br/>
<div id="termField" style="display: none;">
<h5>{{ form.term_ip.label }}</h5>
{{ form.term_ip }}
{% if form.term_ip.errors %}
<p class="link-danger">{{ form.term_ip.errors | striptags }}</p>
{% endif %}
<br/>
<h5>{{ form.ntt_type.label }}</h5>
{{ form.ntt_type }}
{% if form.ntt_type.errors %}
<p class="link-danger">{{ form.ntt_type.errors | striptags }}</p>
{% endif %}
<br/>
<div id="nttCommentField" style="display: none;">
<h5>{{ form.ntt_comment.label }}</h5>
{{ form.ntt_comment }}
{% if form.ntt_comment.errors %}
<p class="link-danger">{{ form.ntt_comment.errors | striptags }}</p>
{% endif %}
<br/>
</div>
<br/>
</div>
<h4>3. 利用開始・終了日</h4>
<p>(最短で1週間後から選択できます)</p>
<div class="container">
<div class="row align-items-start">
<div class="col">
<h5>{{ form.start_date.label }}</h5>
{{ form.start_date }}
{% if form.start_date.errors %}
<p class="link-danger">{{ form.start_date.errors | striptags }}</p>
{% endif %}
</div>
<div class="col">
<h5>{{ form.end_date.label }}</h5>
<div id="endDateField" style="display: none;">
{{ form.end_date }}
{% if form.end_date.errors %}
<p class="link-danger">{{ form.end_date.errors | striptags }}</p>
{% endif %}
</div>
<div class="form-check">
{{ form.no_end_date }}
<label class="form-check-label">
{{ form.no_end_date.label }}
</label>
{% if form.no_end_date.errors %}
<p class="link-danger">{{ form.no_end_date.errors | striptags }}</p>
{% endif %}
</div>
</div>
</div>
</div>
<br/>
<h4>{{ form.is_monitor.label }}</h4>
<div class="form-check">
{{ form.is_monitor }}
<label class="form-check-label">監視あり</label>
{% if form.is_monitor.errors %}
<p class="link-danger">{{ form.is_monitor.errors | striptags }}</p>
{% endif %}
</div>
<br/>
<h4>{{ form.comment.label }}</h4>
{{ form.comment }}
{% if form.comment.errors %}
<p class="link-danger">{{ form.comment.errors | striptags }}</p>
{% endif %}
<br/>
<br/>
<button type="submit" class="btn btn-primary">登録</button>
</form>
{% if request.user.allow_group_add %}
{% else %}
<p>
<b>新規にグループを登録したい又は既存の登録グループを紐づけたい方は、チケットページよりお問い合わせください</b>
</p>
{% endif %}
</div>
</div>
</div>
</div>
{% endblock content %}
{% block javascript %}
<script>
$(document).ready(function () {
checkConnectionTypeForm();
checkNoEndDateForm();
checkNTTCommentForm();

// サービス種別フォーム変化時
$('#id_connection_type').change(function () {
checkConnectionTypeForm();
});
// 終了未定種別フォーム変化時
$('#id_no_end_date').change(function () {
checkNoEndDateForm();
});
// 終了未定種別フォーム変化時
$('#id_ntt_type').change(function () {
checkNTTCommentForm();
});


// サービス種別からIP3B,ET00かどうかを判別する
function checkConnectionTypeForm() {
const selectedValue = $('#id_connection_type').val();
if (selectedValue === 'ETC') {
$('#connectionCommentField').show();
} else {
$('#connectionCommentField').hide();
}

if (selectedValue !== 'CC0') {
$('#termField').show();
} else {
$('#termField').hide();
}
}

// 終了未定種別がFalseの場合に利用終了日のフォームを出す
function checkNoEndDateForm() {
if ($('#id_no_end_date').is(':checked')) {
$('#endDateField').hide();
} else {
$('#endDateField').show();
}
}

function checkNTTCommentForm() {
const selectedValue = $('#id_ntt_type').val();
if (selectedValue === 'etc') {
$('#nttCommentField').show();
} else {
$('#nttCommentField').hide();
}
}
});
</script>
{% endblock javascript %}
Loading

0 comments on commit 832fbad

Please sign in to comment.