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
749d0686
authored
Aug 16, 2016
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: move VmDescFilterMixin into FilterMixin and rewrite query for 'shared' stype
parent
4c5d09d7
Pipeline
#176
passed with stage
in 0 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
23 deletions
+20
-23
circle/dashboard/views/util.py
+18
-21
circle/dashboard/views/vm.py
+2
-2
No files found.
circle/dashboard/views/util.py
View file @
749d0686
...
...
@@ -29,7 +29,7 @@ from django.core.exceptions import PermissionDenied, SuspiciousOperation
from
django.core.urlresolvers
import
reverse
from
django.contrib
import
messages
from
django.contrib.auth.views
import
redirect_to_login
from
django.db.models
import
Q
from
django.db.models
import
Q
,
Count
,
Sum
from
django.http
import
(
HttpResponse
,
Http404
,
HttpResponseRedirect
,
JsonResponse
)
...
...
@@ -159,31 +159,28 @@ class FilterMixin(object):
def
create_acl_queryset
(
self
,
model
):
cleaned_data
=
self
.
search_form
.
cleaned_data
stype
=
cleaned_data
.
get
(
'stype'
,
"all"
)
superuser
=
stype
==
"all"
shared
=
stype
==
"shared"
or
stype
==
"all"
level
=
"owner"
if
stype
==
"owned"
else
"user"
queryset
=
model
.
get_objects_with_level
(
level
,
self
.
request
.
user
,
group_also
=
shared
,
disregard_superuser
=
not
superuser
,
)
return
queryset
class
VmDescFilterMixin
(
FilterMixin
):
def
create_acl_queryset
(
self
,
model
):
cleaned_data
=
self
.
search_form
.
cleaned_data
stype
=
cleaned_data
.
get
(
'stype'
,
'all'
)
queryset
=
super
(
VmDescFilterMixin
,
self
)
.
create_acl_queryset
(
model
)
superuser
=
stype
==
'all'
shared
=
stype
==
'shared'
or
stype
==
'all'
level
=
'owner'
if
stype
==
'owned'
else
'user'
user
=
self
.
request
.
user
queryset
=
model
.
get_objects_with_level
(
level
,
user
,
group_also
=
shared
,
disregard_superuser
=
not
superuser
)
if
stype
==
'owned'
:
queryset
=
queryset
.
filter
(
owner
=
user
)
elif
stype
==
'shared'
:
queryset
=
model
.
get_objects_with_level
(
'owner'
,
self
.
request
.
user
)
pk_list
=
[
record
.
pk
for
record
in
queryset
if
record
.
object_level_set
.
count
()
>
1
]
queryset
=
queryset
.
filter
(
owner
=
user
)
pk_list
=
[]
for
record
in
queryset
:
sum
=
record
.
object_level_set
.
annotate
(
Count
(
'users'
),
Count
(
'groups'
))
.
aggregate
(
Sum
(
'users__count'
),
Sum
(
'groups__count'
))
if
(
sum
[
'users__count__sum'
]
>
1
or
sum
[
'groups__count__sum'
]
>
0
):
pk_list
.
append
(
record
.
pk
)
queryset
=
queryset
.
filter
(
pk__in
=
pk_list
)
elif
stype
==
'shared_with_me'
:
queryset
=
queryset
.
exclude
(
owner
=
user
)
...
...
circle/dashboard/views/vm.py
View file @
749d0686
...
...
@@ -56,7 +56,7 @@ from vm.models import (
)
from
.util
import
(
CheckedDetailView
,
AjaxOperationMixin
,
OperationView
,
AclUpdateView
,
FormOperationMixin
,
VmDesc
FilterMixin
,
GraphMixin
,
FormOperationMixin
,
FilterMixin
,
GraphMixin
,
TransferOwnershipConfirmView
,
TransferOwnershipView
,
)
from
..forms
import
(
...
...
@@ -921,7 +921,7 @@ vm_mass_ops = OrderedDict([
])
class
VmList
(
LoginRequiredMixin
,
VmDesc
FilterMixin
,
ListView
):
class
VmList
(
LoginRequiredMixin
,
FilterMixin
,
ListView
):
template_name
=
"dashboard/vm-list.html"
allowed_filters
=
{
'name'
:
"name__icontains"
,
...
...
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