Skip to content

Commit 832fbad

Browse files
committed
#43 サービス情報と接続情報の登録機能の実装.
1 parent 66f50e7 commit 832fbad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2506
-126
lines changed

custom_auth/admin.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
from django.contrib import admin
2+
from django.urls import reverse
3+
from django.utils.html import format_html
24

35
from custom_auth.models import Group, TOTPDevice, User, UserActivateToken
6+
from ip.models import JPNICUser
7+
from service.models import Service
48

59

610
class TermInlineUserAdmin(admin.TabularInline):
711
model = User.groups.through
8-
extra = 1
12+
extra = 0
913

1014

1115
class TermInlineGroupAdmin(admin.TabularInline):
1216
model = Group.users.through
13-
extra = 1
17+
extra = 0
18+
19+
20+
class TermInlineGroupServiceAdmin(admin.TabularInline):
21+
model = Service
22+
extra = 0
23+
fields = ("service_code", "service_type", "service_number", "is_active", "is_pass")
24+
readonly_fields = ("service_code", "service_type", "service_number", "is_active", "is_pass")
25+
26+
def service_code(self, obj):
27+
# 管理ページの編集ページへのリンクを生成
28+
url = reverse("admin:service_service_change", args=[obj.id])
29+
return format_html('<a href="{}" target="__blank__">{}</a>', url, obj.service_code)
30+
31+
service_code.short_description = "ServiceCode"
32+
33+
34+
class TermInlineGroupJPNICAdmin(admin.TabularInline):
35+
model = JPNICUser
36+
extra = 0
37+
fields = ("id_link", "jpnic_handle", "name", "org", "is_pass")
38+
readonly_fields = ("id_link", "jpnic_handle", "name", "org", "is_pass")
39+
40+
def id_link(self, obj):
41+
# 管理ページの編集ページへのリンクを生成
42+
url = reverse("admin:ip_jpnicuser_change", args=[obj.id])
43+
return format_html('<a href="{}" target="__blank__">{}</a>', url, obj.id)
44+
45+
id_link.short_description = "ID"
1446

1547

1648
@admin.register(User)
@@ -47,7 +79,7 @@ def get_groups(self, obj):
4779
@admin.register(Group)
4880
class Group(admin.ModelAdmin):
4981
fieldsets = (
50-
(None, {"fields": ("name", "name_jp", "allow_service_add", "is_pass", "comment")}),
82+
(None, {"fields": ("name", "name_jp", "allow_service_add", "allow_jpnic_add", "is_pass", "comment")}),
5183
("Membership", {"fields": ("membership_type", "membership_expired_at")}),
5284
("Question", {"fields": ("agree", "question")}),
5385
("Stripe", {"fields": ("stripe_customer_id", "stripe_subscription_id")}),
@@ -85,7 +117,11 @@ class Group(admin.ModelAdmin):
85117
"updated_at",
86118
)
87119

88-
inlines = (TermInlineGroupAdmin,)
120+
inlines = (
121+
TermInlineGroupAdmin,
122+
TermInlineGroupServiceAdmin,
123+
TermInlineGroupJPNICAdmin,
124+
)
89125

90126

91127
@admin.register(UserActivateToken)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.1 on 2024-09-13 16:58
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('custom_auth', '0005_alter_group_status'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='group',
15+
name='allow_jpnic_add',
16+
field=models.BooleanField(default=False, verbose_name='JPNIC情報追加許可'),
17+
),
18+
]

custom_auth/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Group(models.Model): # noqa: F811
8282
comment = models.CharField("comment", max_length=250, default="", blank=True)
8383
status = models.IntegerField("ステータス", default=1, choices=GROUP_STATUS_CHOICES)
8484
allow_service_add = models.BooleanField("サービス追加許可", default=False)
85+
allow_jpnic_add = models.BooleanField("JPNIC情報追加許可", default=False)
8586
membership_type = models.IntegerField("会員種別", default=1, choices=MEMBERSHIP_TYPE_CHOICES)
8687
membership_expired_at = models.DateTimeField("有効期限", blank=True, null=True)
8788

custom_auth/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
app_name = "custom_auth"
66
urlpatterns = [
77
path("", views.index, name="index"),
8-
path("passwor", views.password_change, name="password_change"),
8+
path("password", views.password_change, name="password_change"),
99
path("email", views.change_email, name="email_change"),
1010
path("edit", views.edit_profile, name="edit_profile"),
1111
path("two_auth", views.list_two_auth, name="list_two_auth"),

dsbd/templates/base2.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
2525
<link rel="stylesheet"
2626
href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
27+
<!-- jquery -->
28+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
2729

2830
<style>
2931
#parent {

dsbd/templates/connection/add.html

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
{% extends 'base2.html' %}
2+
{% block content %}
3+
<div class="container">
4+
<div class="row">
5+
<div class="container py-4 mb-auto">
6+
<div class="h-900 p-2 rounded-3">
7+
<h2 class="card-title">接続情報新規申請</h2>
8+
<br/>
9+
<form method="post" class="h-adr">
10+
{% csrf_token %}
11+
<h4>0. サービス情報</h4>
12+
<input type="text" class="form-control" value="{{ service_code }}" disabled>
13+
<br/>
14+
<h4>{{ form.connection_type.label }}</h4>
15+
{{ form.connection_type }}
16+
{% if form.connection_type.errors %}
17+
<p class="link-danger">{{ form.connection_type.errors | striptags }}</p>
18+
{% endif %}
19+
<div id="connectionCommentField" style="display: none;">
20+
<h5>{{ form.connection_comment.label }}</h5>
21+
{{ form.connection_comment }}
22+
{% if form.connection_comment.errors %}
23+
<p class="link-danger">{{ form.connection_comment.errors | striptags }}</p>
24+
{% endif %}
25+
</div>
26+
<br/>
27+
{% if is_ipv4_bgp or is_ipv6_bgp %}
28+
<h5>1.2.広報する経路</h5>
29+
<div class="container">
30+
<div class="row align-items-start">
31+
{% if is_ipv4_bgp %}
32+
<div class="col">
33+
<h5>{{ form.ipv4_route.label }}</h5>
34+
{{ form.ipv4_route }}
35+
{% if form.ipv4_route.errors %}
36+
<p class="link-danger">{{ form.ipv4_route.errors | striptags }}</p>
37+
{% endif %}
38+
<br/>
39+
<h5>{{ form.ipv4_route_comment.label }}</h5>
40+
{{ form.ipv4_route_comment }}
41+
{% if form.ipv4_route_comment.errors %}
42+
<p class="link-danger">{{ form.ipv4_route_comment.errors | striptags }}</p>
43+
{% endif %}
44+
</div>
45+
{% endif %}
46+
{% if is_ipv6_bgp %}
47+
<div class="col">
48+
<h5>{{ form.ipv6_route.label }}</h5>
49+
{{ form.ipv6_route }}
50+
{% if form.ipv6_route.errors %}
51+
<p class="link-danger">{{ form.ipv6_route.errors | striptags }}</p>
52+
{% endif %}
53+
<br/>
54+
<h5>{{ form.ipv6_route_comment.label }}</h5>
55+
{{ form.ipv6_route_comment }}
56+
{% if form.ipv6_route_comment.errors %}
57+
<p class="link-danger">{{ form.ipv6_route_comment.errors | striptags }}</p>
58+
{% endif %}
59+
</div>
60+
{% endif %}
61+
</div>
62+
</div>
63+
<br/>
64+
{% endif %}
65+
<h4>2. 接続情報や場所など</h4>
66+
<h5>{{ form.hope_location.label }}</h5>
67+
{{ form.hope_location }}
68+
{% if form.hope_location.errors %}
69+
<p class="link-danger">{{ form.hope_location.errors | striptags }}</p>
70+
{% endif %}
71+
<br/>
72+
<h5>{{ form.term_location.label }}</h5>
73+
{{ form.term_location }}
74+
{% if form.term_location.errors %}
75+
<p class="link-danger">{{ form.term_location.errors | striptags }}</p>
76+
{% endif %}
77+
<br/>
78+
<div id="termField" style="display: none;">
79+
<h5>{{ form.term_ip.label }}</h5>
80+
{{ form.term_ip }}
81+
{% if form.term_ip.errors %}
82+
<p class="link-danger">{{ form.term_ip.errors | striptags }}</p>
83+
{% endif %}
84+
<br/>
85+
<h5>{{ form.ntt_type.label }}</h5>
86+
{{ form.ntt_type }}
87+
{% if form.ntt_type.errors %}
88+
<p class="link-danger">{{ form.ntt_type.errors | striptags }}</p>
89+
{% endif %}
90+
<br/>
91+
<div id="nttCommentField" style="display: none;">
92+
<h5>{{ form.ntt_comment.label }}</h5>
93+
{{ form.ntt_comment }}
94+
{% if form.ntt_comment.errors %}
95+
<p class="link-danger">{{ form.ntt_comment.errors | striptags }}</p>
96+
{% endif %}
97+
<br/>
98+
</div>
99+
<br/>
100+
</div>
101+
<h4>3. 利用開始・終了日</h4>
102+
<p>(最短で1週間後から選択できます)</p>
103+
<div class="container">
104+
<div class="row align-items-start">
105+
<div class="col">
106+
<h5>{{ form.start_date.label }}</h5>
107+
{{ form.start_date }}
108+
{% if form.start_date.errors %}
109+
<p class="link-danger">{{ form.start_date.errors | striptags }}</p>
110+
{% endif %}
111+
</div>
112+
<div class="col">
113+
<h5>{{ form.end_date.label }}</h5>
114+
<div id="endDateField" style="display: none;">
115+
{{ form.end_date }}
116+
{% if form.end_date.errors %}
117+
<p class="link-danger">{{ form.end_date.errors | striptags }}</p>
118+
{% endif %}
119+
</div>
120+
<div class="form-check">
121+
{{ form.no_end_date }}
122+
<label class="form-check-label">
123+
{{ form.no_end_date.label }}
124+
</label>
125+
{% if form.no_end_date.errors %}
126+
<p class="link-danger">{{ form.no_end_date.errors | striptags }}</p>
127+
{% endif %}
128+
</div>
129+
</div>
130+
</div>
131+
</div>
132+
<br/>
133+
<h4>{{ form.is_monitor.label }}</h4>
134+
<div class="form-check">
135+
{{ form.is_monitor }}
136+
<label class="form-check-label">監視あり</label>
137+
{% if form.is_monitor.errors %}
138+
<p class="link-danger">{{ form.is_monitor.errors | striptags }}</p>
139+
{% endif %}
140+
</div>
141+
<br/>
142+
<h4>{{ form.comment.label }}</h4>
143+
{{ form.comment }}
144+
{% if form.comment.errors %}
145+
<p class="link-danger">{{ form.comment.errors | striptags }}</p>
146+
{% endif %}
147+
<br/>
148+
<br/>
149+
<button type="submit" class="btn btn-primary">登録</button>
150+
</form>
151+
{% if request.user.allow_group_add %}
152+
{% else %}
153+
<p>
154+
<b>新規にグループを登録したい又は既存の登録グループを紐づけたい方は、チケットページよりお問い合わせください</b>
155+
</p>
156+
{% endif %}
157+
</div>
158+
</div>
159+
</div>
160+
</div>
161+
{% endblock content %}
162+
{% block javascript %}
163+
<script>
164+
$(document).ready(function () {
165+
checkConnectionTypeForm();
166+
checkNoEndDateForm();
167+
checkNTTCommentForm();
168+
169+
// サービス種別フォーム変化時
170+
$('#id_connection_type').change(function () {
171+
checkConnectionTypeForm();
172+
});
173+
// 終了未定種別フォーム変化時
174+
$('#id_no_end_date').change(function () {
175+
checkNoEndDateForm();
176+
});
177+
// 終了未定種別フォーム変化時
178+
$('#id_ntt_type').change(function () {
179+
checkNTTCommentForm();
180+
});
181+
182+
183+
// サービス種別からIP3B,ET00かどうかを判別する
184+
function checkConnectionTypeForm() {
185+
const selectedValue = $('#id_connection_type').val();
186+
if (selectedValue === 'ETC') {
187+
$('#connectionCommentField').show();
188+
} else {
189+
$('#connectionCommentField').hide();
190+
}
191+
192+
if (selectedValue !== 'CC0') {
193+
$('#termField').show();
194+
} else {
195+
$('#termField').hide();
196+
}
197+
}
198+
199+
// 終了未定種別がFalseの場合に利用終了日のフォームを出す
200+
function checkNoEndDateForm() {
201+
if ($('#id_no_end_date').is(':checked')) {
202+
$('#endDateField').hide();
203+
} else {
204+
$('#endDateField').show();
205+
}
206+
}
207+
208+
function checkNTTCommentForm() {
209+
const selectedValue = $('#id_ntt_type').val();
210+
if (selectedValue === 'etc') {
211+
$('#nttCommentField').show();
212+
} else {
213+
$('#nttCommentField').hide();
214+
}
215+
}
216+
});
217+
</script>
218+
{% endblock javascript %}

0 commit comments

Comments
 (0)