Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
237d51cf
Commit
237d51cf
authored
Oct 16, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 拆分filter org
parent
31280a38
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
21 deletions
+28
-21
api.py
apps/orgs/mixins/api.py
+4
-2
models.py
apps/orgs/mixins/models.py
+2
-19
utils.py
apps/orgs/utils.py
+22
-0
No files found.
apps/orgs/mixins/api.py
View file @
237d51cf
...
...
@@ -5,7 +5,7 @@ from rest_framework.viewsets import ModelViewSet
from
rest_framework_bulk
import
BulkModelViewSet
from
common.mixins
import
CommonApiMixin
from
..utils
import
set_to_root_org
from
..utils
import
set_to_root_org
,
filter_org_queryset
from
..models
import
Organization
__all__
=
[
...
...
@@ -22,7 +22,9 @@ class RootOrgViewMixin:
class
OrgQuerySetMixin
:
def
get_queryset
(
self
):
queryset
=
super
()
.
get_queryset
()
.
all
()
queryset
=
super
()
.
get_queryset
()
queryset
=
filter_org_queryset
(
queryset
)
if
hasattr
(
self
,
'swagger_fake_view'
):
return
queryset
[:
1
]
if
hasattr
(
self
,
'action'
)
and
self
.
action
==
'list'
and
\
...
...
apps/orgs/mixins/models.py
View file @
237d51cf
# -*- coding: utf-8 -*-
#
import
traceback
from
django.db
import
models
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.core.exceptions
import
ValidationError
...
...
@@ -9,6 +8,7 @@ from django.core.exceptions import ValidationError
from
common.utils
import
get_logger
from
..utils
import
(
set_current_org
,
get_current_org
,
current_org
,
filter_org_queryset
,
)
from
..models
import
Organization
...
...
@@ -23,24 +23,7 @@ class OrgManager(models.Manager):
def
get_queryset
(
self
):
queryset
=
super
(
OrgManager
,
self
)
.
get_queryset
()
kwargs
=
{}
_current_org
=
get_current_org
()
if
_current_org
is
None
:
kwargs
[
'id'
]
=
None
elif
_current_org
.
is_real
():
kwargs
[
'org_id'
]
=
_current_org
.
id
elif
_current_org
.
is_default
():
queryset
=
queryset
.
filter
(
org_id
=
""
)
#
# lines = traceback.format_stack()
# print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>")
# for line in lines[-10:-1]:
# print(line)
# print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
queryset
=
queryset
.
filter
(
**
kwargs
)
return
queryset
return
filter_org_queryset
(
queryset
)
def
all
(
self
):
if
not
current_org
:
...
...
apps/orgs/utils.py
View file @
237d51cf
# -*- coding: utf-8 -*-
#
import
traceback
from
werkzeug.local
import
LocalProxy
from
contextlib
import
contextmanager
...
...
@@ -82,4 +83,25 @@ def tmp_to_org(org):
set_current_org
(
ori_org
)
def
filter_org_queryset
(
queryset
):
kwargs
=
{}
_current_org
=
get_current_org
()
if
_current_org
is
None
:
return
queryset
.
none
()
if
_current_org
.
is_real
():
kwargs
[
'org_id'
]
=
_current_org
.
id
elif
_current_org
.
is_default
():
kwargs
[
"org_id"
]
=
''
#
# lines = traceback.format_stack()
# print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>")
# for line in lines[-10:-1]:
# print(line)
# print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
queryset
=
queryset
.
filter
(
**
kwargs
)
return
queryset
current_org
=
LocalProxy
(
get_current_org
)
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