Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8232e6dd
authored
Oct 06, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: separate generic acl-update view
parent
8dfcbde6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
8 deletions
+14
-8
circle/dashboard/urls.py
+5
-1
circle/dashboard/views.py
+9
-7
No files found.
circle/dashboard/urls.py
View file @
8232e6dd
from
django.conf.urls
import
patterns
,
url
from
django.conf.urls
import
patterns
,
url
from
.views
import
IndexView
,
VmDetailView
,
VmList
from
vm.models
import
Instance
from
.views
import
IndexView
,
VmDetailView
,
VmList
,
AclUpdateView
urlpatterns
=
patterns
(
urlpatterns
=
patterns
(
''
,
''
,
url
(
r'^$'
,
IndexView
.
as_view
()),
url
(
r'^$'
,
IndexView
.
as_view
()),
url
(
r'^vm/(?P<pk>\d+)/$'
,
VmDetailView
.
as_view
(),
url
(
r'^vm/(?P<pk>\d+)/$'
,
VmDetailView
.
as_view
(),
name
=
'dashboard.views.detail'
),
name
=
'dashboard.views.detail'
),
url
(
r'^vm/(?P<pk>\d+)/acl/$'
,
AclUpdateView
.
as_view
(
model
=
Instance
),
name
=
'dashboard.views.vm-acl'
),
url
(
r'^vm/list/$'
,
VmList
.
as_view
(),
name
=
'dashboard.views.vm-list'
),
url
(
r'^vm/list/$'
,
VmList
.
as_view
(),
name
=
'dashboard.views.vm-list'
),
)
)
circle/dashboard/views.py
View file @
8232e6dd
...
@@ -2,8 +2,10 @@ import re
...
@@ -2,8 +2,10 @@ import re
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
from
django.core
import
signing
from
django.core
import
signing
from
django.core.urlresolvers
import
reverse
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.views.generic
import
TemplateView
,
DetailView
,
UpdateView
from
django.views.generic
import
TemplateView
,
DetailView
,
View
from
django.views.generic.detail
import
SingleObjectMixin
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
from
guardian.shortcuts
import
(
get_users_with_perms
,
get_groups_with_perms
,
from
guardian.shortcuts
import
(
get_users_with_perms
,
get_groups_with_perms
,
...
@@ -63,7 +65,7 @@ def get_acl_data(obj):
...
@@ -63,7 +65,7 @@ def get_acl_data(obj):
'perm'
:
first_common_element
(
levelids
,
get_perms
(
g
,
obj
))}
'perm'
:
first_common_element
(
levelids
,
get_perms
(
g
,
obj
))}
for
g
in
groups
]
for
g
in
groups
]
return
{
'users'
:
users
,
'groups'
:
groups
,
'levels'
:
levels
,
return
{
'users'
:
users
,
'groups'
:
groups
,
'levels'
:
levels
,
'url'
:
obj
.
get_absolute_url
(
)}
'url'
:
reverse
(
'dashboard.views.vm-acl'
,
args
=
[
obj
.
pk
]
)}
def
set_acl_level
(
obj
,
whom
,
level
):
def
set_acl_level
(
obj
,
whom
,
level
):
...
@@ -76,9 +78,9 @@ def set_acl_level(obj, whom, level):
...
@@ -76,9 +78,9 @@ def set_acl_level(obj, whom, level):
assign_perm
(
p
,
whom
,
obj
)
assign_perm
(
p
,
whom
,
obj
)
class
VmDetailView
(
Update
View
):
class
VmDetailView
(
Detail
View
):
template_name
=
"dashboard/vm-detail.html"
template_name
=
"dashboard/vm-detail.html"
queryset
=
Instance
.
objects
.
all
()
model
=
Instance
def
get_context_data
(
self
,
**
kwargs
):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VmDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
context
=
super
(
VmDetailView
,
self
)
.
get_context_data
(
**
kwargs
)
...
@@ -94,10 +96,10 @@ class VmDetailView(UpdateView):
...
@@ -94,10 +96,10 @@ class VmDetailView(UpdateView):
context
[
'acl'
]
=
get_acl_data
(
instance
)
context
[
'acl'
]
=
get_acl_data
(
instance
)
return
context
return
context
class
AclUpdateView
(
View
,
SingleObjectMixin
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
super
(
VmDetailView
,
self
)
.
post
(
request
,
*
args
,
**
kwargs
)
instance
=
self
.
get_object
()
context
=
self
.
get_context_data
(
**
kwargs
)
instance
=
context
[
'instance'
]
for
key
,
value
in
request
.
POST
.
items
():
for
key
,
value
in
request
.
POST
.
items
():
m
=
re
.
match
(
'perm-([ug])-(
\
d+)'
,
key
)
m
=
re
.
match
(
'perm-([ug])-(
\
d+)'
,
key
)
if
m
:
if
m
:
...
...
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