forked from guohongze/adminset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.py
96 lines (83 loc) · 2.72 KB
/
group.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django.shortcuts import render
from models import HostGroup
from forms import GroupForm
from django.contrib.auth.decorators import login_required
from accounts.permission import permission_verify
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
@login_required()
@permission_verify()
def group(request):
temp_name = "cmdb/cmdb-header.html"
allgroup = HostGroup.objects.all()
context = {
'temp_name': temp_name,
'allgroup': allgroup
}
return render(request, 'cmdb/group.html', context)
@login_required()
@permission_verify()
def group_add(request):
temp_name = "cmdb/cmdb-header.html"
if request.method == "POST":
group_form = GroupForm(request.POST)
if group_form.is_valid():
group_form.save()
tips = u"增加成功!"
display_control = ""
else:
tips = u"增加失败!"
display_control = ""
return render(request, "cmdb/group_base.html", locals())
else:
display_control = "none"
group_form = GroupForm()
return render(request, "cmdb/group_base.html", locals())
@login_required()
@permission_verify()
def group_del(request):
temp_name = "cmdb/cmdb-header.html"
group_id = request.GET.get('id', '')
if group_id:
HostGroup.objects.filter(id=group_id).delete()
if request.method == 'POST':
group_items = request.POST.getlist('g_check', [])
if group_items:
for n in group_items:
HostGroup.objects.filter(id=n).delete()
allgroup = HostGroup.objects.all()
return render(request, "cmdb/group.html", locals())
@login_required()
@permission_verify()
def group_edit(request, group_id):
project = HostGroup.objects.get(id=group_id)
temp_name = "cmdb/cmdb-header.html"
if request.method == 'POST':
form = GroupForm(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('group'))
else:
form = GroupForm(instance=project)
display_control = "none"
results = {
'group_form': form,
'group_id': group_id,
'request': request,
'temp_name': temp_name,
'display_control': display_control,
}
return render(request, 'cmdb/group_base.html', results)
@login_required
@permission_verify()
def server_list(request, group_id):
temp_name = "cmdb/cmdb-header.html"
grp = HostGroup.objects.get(id=group_id)
servers = grp.serverList.all()
results = {
'temp_name': temp_name,
'server_list': servers,
}
return render(request, 'cmdb/group_server_list.html', results)