Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
django-activity-stream
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
istina
django-activity-stream
Commits
03500192
Commit
03500192
authored
10 years ago
by
Denis Golomazov
Committed by
Dmitry Shachnev
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add ActorListFilter to filter by actor type. Add description column to display.
parent
3d8804ef
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
actstream/admin.py
+49
-2
49 additions, 2 deletions
actstream/admin.py
with
49 additions
and
2 deletions
actstream/admin.py
+
49
−
2
View file @
03500192
from
django.contrib
import
admin
from
django.contrib.admin
import
SimpleListFilter
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.auth.models
import
User
from
django.utils.translation
import
ugettext_lazy
as
_
from
actstream
import
models
...
...
@@ -9,10 +13,53 @@ except ImportError:
ModelAdmin
=
admin
.
ModelAdmin
class
ActorListFilter
(
SimpleListFilter
):
# Human-readable title which will be displayed in the
# right admin sidebar just above the filter options.
title
=
_
(
'
actor type
'
)
# Parameter for the filter that will be used in the URL query.
parameter_name
=
'
actor_type
'
def
lookups
(
self
,
request
,
model_admin
):
"""
Returns a list of tuples. The first element in each
tuple is the coded value for the option that will
appear in the URL query. The second element is the
human-readable name for the option that will appear
in the right sidebar.
"""
return
(
(
'
non-staff
'
,
_
(
'
All excluding staff
'
)),
(
'
anonymous
'
,
_
(
'
Anonymous users
'
)),
(
'
registered
'
,
_
(
'
Registered users
'
)),
(
'
staff
'
,
_
(
'
Staff
'
)),
)
def
queryset
(
self
,
request
,
queryset
):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Compare the requested value (either '80s' or 'other')
# to decide how to filter the queryset.
user_content_type
=
ContentType
.
objects
.
get_for_model
(
User
)
staff
=
User
.
objects
.
filter
(
is_staff
=
True
)
if
self
.
value
()
==
'
non-staff
'
:
return
queryset
.
exclude
(
actor_content_type
=
user_content_type
,
actor_object_id__in
=
staff
)
if
self
.
value
()
==
'
anonymous
'
:
return
queryset
.
exclude
(
actor_content_type
=
user_content_type
)
if
self
.
value
()
==
'
registered
'
:
return
queryset
.
filter
(
actor_content_type
=
user_content_type
).
exclude
(
actor_object_id__in
=
staff
)
if
self
.
value
()
==
'
staff
'
:
return
queryset
.
filter
(
actor_content_type
=
user_content_type
,
actor_object_id__in
=
staff
)
class
ActionAdmin
(
ModelAdmin
):
date_hierarchy
=
'
timestamp
'
list_display
=
(
'
actor
'
,
'
verb
'
,
'
action_object_content_type
'
,
'
action_object
'
,
'
target_content_type
'
,
'
target
'
,
'
timestamp
'
)
list_filter
=
(
'
verb
'
,
'
timestamp
'
)
list_display
=
(
'
actor
'
,
'
verb
'
,
'
description
'
,
'
action_object_content_type
'
,
'
action_object
'
,
'
target_content_type
'
,
'
target
'
,
'
timestamp
'
)
list_filter
=
(
ActorListFilter
,
'
timestamp
'
,
'
verb
'
)
raw_id_fields
=
(
'
actor_content_type
'
,
'
target_content_type
'
,
'
action_object_content_type
'
)
...
...
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