Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
oser-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamza Touizrat
oser-backend
Commits
94442a5d
Commit
94442a5d
authored
4 years ago
by
Bidot-Naude Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Ajout filtre participation
parent
2213ce8e
Branches
Branches containing commit
No related tags found
7 merge requests
!39
Solve public permission files on AWS
,
!41
Rectification Exportation excel sorties
,
!32
Sortie thomas
,
!37
Add context_sheet for visits
,
!33
Sortie thomas (export CSV sorties)
,
!38
Add context sheet for visits V4
,
!35
Notifications for Sec-Gen
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/MultiSelectFieldListFilter.py
+68
-0
68 additions, 0 deletions
projects/MultiSelectFieldListFilter.py
with
68 additions
and
0 deletions
projects/MultiSelectFieldListFilter.py
0 → 100644
+
68
−
0
View file @
94442a5d
from
django.contrib
import
admin
from
django.contrib.admin.utils
import
reverse_field_path
from
django.utils.translation
import
gettext_lazy
as
_
class
MultiSelectFieldListFilter
(
admin
.
FieldListFilter
):
def
__init__
(
self
,
field
,
request
,
params
,
model
,
model_admin
,
field_path
):
self
.
lookup_kwarg
=
field_path
+
'
__in
'
self
.
lookup_kwarg_isnull
=
field_path
+
'
__isnull
'
super
().
__init__
(
field
,
request
,
params
,
model
,
model_admin
,
field_path
)
self
.
lookup_val
=
self
.
used_parameters
.
get
(
self
.
lookup_kwarg
,
[])
if
len
(
self
.
lookup_val
)
==
1
and
self
.
lookup_val
[
0
]
==
''
:
self
.
lookup_val
=
[]
self
.
lookup_val_isnull
=
self
.
used_parameters
.
get
(
self
.
lookup_kwarg_isnull
)
self
.
empty_value_display
=
model_admin
.
get_empty_value_display
()
parent_model
,
reverse_path
=
reverse_field_path
(
model
,
field_path
)
# Obey parent ModelAdmin queryset when deciding which options to show
if
model
==
parent_model
:
queryset
=
model_admin
.
get_queryset
(
request
)
else
:
queryset
=
parent_model
.
_default_manager
.
all
()
self
.
lookup_choices
=
queryset
.
distinct
().
order_by
(
field
.
name
).
values_list
(
field
.
name
,
flat
=
True
)
def
expected_parameters
(
self
):
return
[
self
.
lookup_kwarg
,
self
.
lookup_kwarg_isnull
]
def
choices
(
self
,
changelist
):
yield
{
'
selected
'
:
not
self
.
lookup_val
and
self
.
lookup_val_isnull
is
None
,
'
query_string
'
:
changelist
.
get_query_string
(
remove
=
[
self
.
lookup_kwarg
,
self
.
lookup_kwarg_isnull
]),
'
display
'
:
_
(
'
All
'
),
}
include_none
=
False
for
val
in
self
.
lookup_choices
:
if
val
is
None
:
include_none
=
True
continue
val
=
str
(
val
)
if
val
in
self
.
lookup_val
:
values
=
[
v
for
v
in
self
.
lookup_val
if
v
!=
val
]
else
:
values
=
self
.
lookup_val
+
[
val
]
if
values
:
yield
{
'
selected
'
:
val
in
self
.
lookup_val
,
'
query_string
'
:
changelist
.
get_query_string
({
self
.
lookup_kwarg
:
'
,
'
.
join
(
values
)},
[
self
.
lookup_kwarg_isnull
]),
'
display
'
:
val
,
}
else
:
yield
{
'
selected
'
:
val
in
self
.
lookup_val
,
'
query_string
'
:
changelist
.
get_query_string
(
remove
=
[
self
.
lookup_kwarg
]),
'
display
'
:
val
,
}
if
include_none
:
yield
{
'
selected
'
:
bool
(
self
.
lookup_val_isnull
),
'
query_string
'
:
changelist
.
get_query_string
({
self
.
lookup_kwarg_isnull
:
'
True
'
},
[
self
.
lookup_kwarg
]),
'
display
'
:
self
.
empty_value_display
,
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment