Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
a86d7f52
authored
Sep 10, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: add default owners for network forms
Also remove copypasted SuccessMessageMixin
parent
efdebdff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
29 deletions
+19
-29
circle/network/views.py
+19
-29
No files found.
circle/network/views.py
View file @
a86d7f52
...
...
@@ -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
AclUserAddForm
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,10 +495,9 @@ class RecordCreate(LoginRequiredMixin, SuperuserRequiredMixin,
success_message
=
_
(
u'Successfully created record!'
)
def
get_initial
(
self
):
return
{
# 'owner': 1,
'domain'
:
self
.
request
.
GET
.
get
(
'domain'
),
}
initial
=
super
(
RecordCreate
,
self
)
.
get_initial
()
initial
[
'domain'
]
=
self
.
request
.
GET
.
get
(
'domain'
)
return
initial
class
RecordDelete
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DeleteView
):
...
...
@@ -556,18 +545,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
):
...
...
@@ -747,7 +737,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