Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ea3039d6
authored
Sep 15, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'issue-282' into 'master'
Make request.user the initial owner in network.* forms Closes
#282
parents
1138a614
9a062596
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
58 deletions
+52
-58
circle/network/forms.py
+32
-29
circle/network/views.py
+20
-29
No files found.
circle/network/forms.py
View file @
ea3039d6
...
...
@@ -17,6 +17,7 @@
from
django.forms
import
ModelForm
from
django.core.urlresolvers
import
reverse_lazy
from
django.utils.translation
import
ugettext_lazy
as
_
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.layout
import
Layout
,
Fieldset
,
Div
,
Submit
,
BaseInput
...
...
@@ -56,8 +57,9 @@ class BlacklistItemForm(ModelForm):
)
),
FormActions
(
Submit
(
'submit'
,
'Save changes'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.blacklist_list'
))
Submit
(
'submit'
,
_
(
'Save changes'
)),
LinkButton
(
'back'
,
_
(
"Back"
),
reverse_lazy
(
'network.blacklist_list'
))
)
)
...
...
@@ -77,8 +79,8 @@ class DomainForm(ModelForm):
),
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.domain_list'
))
Submit
(
'submit'
,
_
(
'Save'
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.domain_list'
))
)
)
...
...
@@ -91,15 +93,15 @@ class GroupForm(ModelForm):
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
'
Identity
'
,
''
,
'name'
,
'description'
,
'owner'
,
),
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.group_list'
))
Submit
(
'submit'
,
_
(
'Save'
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.group_list'
))
)
)
...
...
@@ -112,13 +114,13 @@ class HostForm(ModelForm):
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
'
Identity
'
,
''
,
'hostname'
,
'reverse'
,
'mac'
,
),
Fieldset
(
'Network'
,
_
(
'Network'
)
,
'vlan'
,
'ipv4'
,
'ipv6'
,
...
...
@@ -126,7 +128,7 @@ class HostForm(ModelForm):
'external_ipv4'
,
),
Fieldset
(
'Information'
,
_
(
'Information'
)
,
'description'
,
'location'
,
'comment'
,
...
...
@@ -134,8 +136,8 @@ class HostForm(ModelForm):
),
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.host_list'
)))
Submit
(
'submit'
,
_
(
'Save'
)
),
LinkButton
(
'back'
,
_
(
'Back'
)
,
reverse_lazy
(
'network.host_list'
)))
)
class
Meta
:
...
...
@@ -159,8 +161,8 @@ class RecordForm(ModelForm):
)
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.record_list'
))
Submit
(
'submit'
,
_
(
"Save"
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.record_list'
))
)
)
...
...
@@ -173,7 +175,7 @@ class RuleForm(ModelForm):
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
'
Identity
'
,
''
,
'direction'
,
'description'
,
'foreign_network'
,
...
...
@@ -189,7 +191,7 @@ class RuleForm(ModelForm):
'nat_external_ipv4'
,
),
Fieldset
(
'External'
,
_
(
'External'
)
,
'vlan'
,
'vlangroup'
,
'host'
,
...
...
@@ -198,8 +200,8 @@ class RuleForm(ModelForm):
)
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.rule_list'
))
Submit
(
'submit'
,
_
(
"Save"
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.rule_list'
))
)
)
...
...
@@ -219,8 +221,8 @@ class SwitchPortForm(ModelForm):
)
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
Submit
(
'submit'
,
_
(
"Save"
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.switch_port_list'
))
)
)
...
...
@@ -234,41 +236,42 @@ class VlanForm(ModelForm):
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
'
Identity
'
,
''
,
'name'
,
'vid'
,
'network_type'
,
'managed'
,
),
Fieldset
(
'IPv4'
,
_
(
'IPv4'
)
,
'network4'
,
'snat_to'
,
'snat_ip'
,
'dhcp_pool'
,
),
Fieldset
(
'IPv6'
,
_
(
'IPv6'
)
,
'network6'
,
'ipv6_template'
,
'host_ipv6_prefixlen'
,
),
Fieldset
(
'Domain name service'
,
_
(
'Domain name service'
)
,
'domain'
,
'reverse_domain'
,
),
Fieldset
(
'Info'
,
_
(
'Info'
)
,
'description'
,
'comment'
,
'owner'
,
# 'created_at',
# 'modified_at',
),
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
'network.vlan_list'
))
Submit
(
'submit'
,
_
(
"Save"
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.vlan_list'
))
)
)
...
...
@@ -289,8 +292,8 @@ class VlanGroupForm(ModelForm):
)
),
FormActions
(
Submit
(
'submit'
,
'Save'
),
LinkButton
(
'back'
,
'Back'
,
reverse_lazy
(
Submit
(
'submit'
,
_
(
"Save"
)
),
LinkButton
(
'back'
,
_
(
"Back"
)
,
reverse_lazy
(
'network.vlan_group_list'
))
)
)
...
...
circle/network/views.py
View file @
ea3039d6
...
...
@@ -34,6 +34,7 @@ from .forms import (HostForm, VlanForm, DomainForm, GroupForm, RecordForm,
BlacklistItemForm
,
RuleForm
,
VlanGroupForm
,
SwitchPortForm
)
from
django.contrib
import
messages
from
django.contrib.messages.views
import
SuccessMessageMixin
from
django.views.generic.edit
import
FormMixin
from
django.utils.translation
import
ugettext_lazy
as
_
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
...
...
@@ -45,22 +46,11 @@ from dashboard.views import AclUpdateView
from
dashboard.forms
import
AclUserOrGroupAddForm
class
SuccessMessageMixin
(
FormMixin
):
"""
Adds a success message on successful form submission.
From django/contrib/messages/views.py@9a85ad89
"""
success_message
=
''
def
form_valid
(
self
,
form
):
response
=
super
(
SuccessMessageMixin
,
self
)
.
form_valid
(
form
)
success_message
=
self
.
get_success_message
(
form
.
cleaned_data
)
if
success_message
:
messages
.
success
(
self
.
request
,
success_message
)
return
response
def
get_success_message
(
self
,
cleaned_data
):
return
self
.
success_message
%
cleaned_data
class
InitialOwnerMixin
(
FormMixin
):
def
get_initial
(
self
):
initial
=
super
(
InitialOwnerMixin
,
self
)
.
get_initial
()
initial
[
'owner'
]
=
self
.
request
.
user
return
initial
class
IndexView
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
TemplateView
):
...
...
@@ -190,7 +180,7 @@ class DomainDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
DomainCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Domain
template_name
=
"network/domain-create.html"
form_class
=
DomainForm
...
...
@@ -274,7 +264,7 @@ class GroupList(LoginRequiredMixin, SuperuserRequiredMixin, SingleTableView):
class
GroupCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Group
template_name
=
"network/group-create.html"
form_class
=
GroupForm
...
...
@@ -413,7 +403,7 @@ class HostDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
HostCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Host
template_name
=
"network/host-create.html"
form_class
=
HostForm
...
...
@@ -497,7 +487,7 @@ class RecordDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
RecordCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Record
template_name
=
"network/record-create.html"
form_class
=
RecordForm
...
...
@@ -505,21 +495,21 @@ class RecordCreate(LoginRequiredMixin, SuperuserRequiredMixin,
success_message
=
_
(
u'Successfully created record!'
)
def
get_initial
(
self
):
initial
=
super
(
RecordCreate
,
self
)
.
get_initial
()
initial
[
'domain'
]
=
self
.
request
.
GET
.
get
(
'domain'
)
host_pk
=
self
.
request
.
GET
.
get
(
"host"
)
try
:
host
=
Host
.
objects
.
get
(
pk
=
host_pk
)
except
(
Host
.
DoesNotExist
,
ValueError
):
host
=
None
initial
=
{
'owner'
:
self
.
request
.
user
}
if
host
:
initial
.
update
({
'type'
:
"CNAME"
,
'host'
:
host
,
'address'
:
host
.
get_fqdn
(),
})
else
:
initial
[
'domain'
]
=
self
.
request
.
GET
.
get
(
'domain'
)
return
initial
...
...
@@ -569,18 +559,19 @@ class RuleDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
RuleCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Rule
template_name
=
"network/rule-create.html"
form_class
=
RuleForm
success_message
=
_
(
u'Successfully created rule!'
)
def
get_initial
(
self
):
return
{
# 'owner': 1,
initial
=
super
(
RuleCreate
,
self
)
.
get_initial
()
initial
.
update
({
'host'
:
self
.
request
.
GET
.
get
(
'host'
),
'hostgroup'
:
self
.
request
.
GET
.
get
(
'hostgroup'
)
}
})
return
initial
class
RuleDelete
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DeleteView
):
...
...
@@ -680,7 +671,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
VlanCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Vlan
template_name
=
"network/vlan-create.html"
form_class
=
VlanForm
...
...
@@ -760,7 +751,7 @@ class VlanGroupDetail(LoginRequiredMixin, SuperuserRequiredMixin,
class
VlanGroupCreate
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
CreateView
):
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
VlanGroup
template_name
=
"network/vlan-group-create.html"
form_class
=
VlanGroupForm
...
...
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