Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e0580823
authored
May 09, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall_gui: code refactored
Autocomplete functions are dynamically generated
parent
b86b3414
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
47 deletions
+25
-47
cloud/urls.py
+1
-7
firewall_gui/views.py
+24
-40
No files found.
cloud/urls.py
View file @
e0580823
...
@@ -110,13 +110,7 @@ urlpatterns = patterns('',
...
@@ -110,13 +110,7 @@ urlpatterns = patterns('',
url
(
r'^firewall/vlangroups/(?P<id>\d+)/$'
,
'firewall_gui.views.show_vlangroup'
),
url
(
r'^firewall/vlangroups/(?P<id>\d+)/$'
,
'firewall_gui.views.show_vlangroup'
),
url
(
r'^firewall/hostgroups/(?P<id>\d+)/$'
,
'firewall_gui.views.show_hostgroup'
),
url
(
r'^firewall/hostgroups/(?P<id>\d+)/$'
,
'firewall_gui.views.show_hostgroup'
),
url
(
r'^firewall/autocomplete/vlan/$'
,
'firewall_gui.views.autocomplete_vlan'
),
url
(
r'^firewall/autocomplete/(?P<entity>\w+)/$'
,
'firewall_gui.views.autocomplete'
),
url
(
r'^firewall/autocomplete/vlangroup/$'
,
'firewall_gui.views.autocomplete_vlangroup'
),
url
(
r'^firewall/autocomplete/host/$'
,
'firewall_gui.views.autocomplete_host'
),
url
(
r'^firewall/autocomplete/hostgroup/$'
,
'firewall_gui.views.autocomplete_hostgroup'
),
url
(
r'^firewall/autocomplete/firewall/$'
,
'firewall_gui.views.autocomplete_firewall'
),
url
(
r'^firewall/autocomplete/domain/$'
,
'firewall_gui.views.autocomplete_domain'
),
url
(
r'^firewall/autocomplete/record/$'
,
'firewall_gui.views.autocomplete_record'
),
url
(
r'^firewall/rules/save/$'
,
'firewall_gui.views.save_rule'
),
url
(
r'^firewall/rules/save/$'
,
'firewall_gui.views.save_rule'
),
)
)
firewall_gui/views.py
View file @
e0580823
...
@@ -400,47 +400,31 @@ def show_hostgroup(request, id):
...
@@ -400,47 +400,31 @@ def show_hostgroup(request, id):
return
HttpResponse
(
json
.
dumps
(
group
),
content_type
=
'application/json'
)
return
HttpResponse
(
json
.
dumps
(
group
),
content_type
=
'application/json'
)
def
autocomplete_vlan
(
request
):
def
make_autocomplete
(
entity
,
name
=
'name'
):
return
HttpResponse
(
json
.
dumps
([{
def
autocomplete
(
request
):
'id'
:
vlan
.
id
,
return
HttpResponse
(
json
.
dumps
([{
'name'
:
vlan
.
name
'id'
:
object
.
id
,
}
for
vlan
in
Vlan
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
'name'
:
getattr
(
object
,
name
)
}
for
object
in
entity
.
objects
.
filter
(
**
{
def
autocomplete_vlangroup
(
request
):
name
+
'__icontains'
:
request
.
POST
[
'name'
]
return
HttpResponse
(
json
.
dumps
([{
})[:
5
]]),
content_type
=
'application/json'
)
'id'
:
vlangroup
.
id
,
return
autocomplete
'name'
:
vlangroup
.
name
}
for
vlangroup
in
VlanGroup
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
def
autocomplete
(
request
,
entity
):
def
autocomplete_hostgroup
(
request
):
try
:
return
HttpResponse
(
json
.
dumps
([{
return
{
'id'
:
hostgroup
.
id
,
'vlan'
:
make_autocomplete
(
Vlan
),
'name'
:
hostgroup
.
name
'vlangroup'
:
make_autocomplete
(
VlanGroup
),
}
for
hostgroup
in
Group
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
'host'
:
make_autocomplete
(
Host
,
'hostname'
),
'hostgroup'
:
make_autocomplete
(
Group
),
def
autocomplete_host
(
request
):
'firewall'
:
make_autocomplete
(
Firewall
),
return
HttpResponse
(
json
.
dumps
([{
'domain'
:
make_autocomplete
(
Domain
),
'id'
:
host
.
id
,
'record'
:
make_autocomplete
(
Record
),
'name'
:
host
.
hostname
}[
entity
](
request
)
}
for
host
in
Host
.
objects
.
filter
(
hostname__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
except
Exception
as
e
:
return
HttpResponse
(
'>:-3'
,
status
=
500
)
def
autocomplete_firewall
(
request
):
return
HttpResponse
(
json
.
dumps
([{
'id'
:
firewall
.
id
,
'name'
:
firewall
.
name
}
for
firewall
in
Firewall
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
def
autocomplete_domain
(
request
):
return
HttpResponse
(
json
.
dumps
([{
'id'
:
domain
.
id
,
'name'
:
domain
.
name
}
for
domain
in
Domain
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
def
autocomplete_record
(
request
):
return
HttpResponse
(
json
.
dumps
([{
'id'
:
record
.
id
,
'name'
:
record
.
name
}
for
record
in
Record
.
objects
.
filter
(
name__icontains
=
request
.
POST
[
'name'
])[:
5
]]),
content_type
=
'application/json'
)
def
save_rule
(
request
):
def
save_rule
(
request
):
data
=
json
.
loads
(
request
.
body
)
data
=
json
.
loads
(
request
.
body
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment