Improve djadmin filtering and search (#149)
This commit is contained in:
parent
08dae900b7
commit
a576c5b5ed
@ -1,5 +1,6 @@
|
|||||||
from asgiref.sync import async_to_sync
|
from asgiref.sync import async_to_sync
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from activities.models import (
|
from activities.models import (
|
||||||
FanOut,
|
FanOut,
|
||||||
@ -11,9 +12,33 @@ from activities.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class IdentityLocalFilter(admin.SimpleListFilter):
|
||||||
|
title = _("Local Identity")
|
||||||
|
parameter_name = "islocal"
|
||||||
|
|
||||||
|
identity_field_name = "identity"
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return (
|
||||||
|
("1", _("Yes")),
|
||||||
|
("0", _("No")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
match self.value():
|
||||||
|
case "1":
|
||||||
|
return queryset.filter(**{f"{self.identity_field_name}__local": True})
|
||||||
|
case "0":
|
||||||
|
return queryset.filter(**{f"{self.identity_field_name}__local": False})
|
||||||
|
case _:
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Hashtag)
|
@admin.register(Hashtag)
|
||||||
class HashtagAdmin(admin.ModelAdmin):
|
class HashtagAdmin(admin.ModelAdmin):
|
||||||
list_display = ["hashtag", "name_override", "state", "stats_updated", "created"]
|
list_display = ["hashtag", "name_override", "state", "stats_updated", "created"]
|
||||||
|
list_filter = ("public", "state", "stats_updated")
|
||||||
|
search_fields = ["hashtag", "aliases"]
|
||||||
|
|
||||||
readonly_fields = ["created", "updated", "stats_updated"]
|
readonly_fields = ["created", "updated", "stats_updated"]
|
||||||
|
|
||||||
@ -38,6 +63,7 @@ class PostAttachmentInline(admin.StackedInline):
|
|||||||
@admin.register(Post)
|
@admin.register(Post)
|
||||||
class PostAdmin(admin.ModelAdmin):
|
class PostAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "state", "author", "created"]
|
list_display = ["id", "state", "author", "created"]
|
||||||
|
list_filter = ("local", "visibility", "state", "created")
|
||||||
raw_id_fields = ["to", "mentions", "author"]
|
raw_id_fields = ["to", "mentions", "author"]
|
||||||
actions = ["force_fetch", "reparse_hashtags"]
|
actions = ["force_fetch", "reparse_hashtags"]
|
||||||
search_fields = ["content"]
|
search_fields = ["content"]
|
||||||
@ -70,6 +96,7 @@ class PostAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(TimelineEvent)
|
@admin.register(TimelineEvent)
|
||||||
class TimelineEventAdmin(admin.ModelAdmin):
|
class TimelineEventAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "identity", "created", "type"]
|
list_display = ["id", "identity", "created", "type"]
|
||||||
|
list_filter = (IdentityLocalFilter, "type")
|
||||||
readonly_fields = ["created"]
|
readonly_fields = ["created"]
|
||||||
raw_id_fields = [
|
raw_id_fields = [
|
||||||
"identity",
|
"identity",
|
||||||
@ -85,6 +112,7 @@ class TimelineEventAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(FanOut)
|
@admin.register(FanOut)
|
||||||
class FanOutAdmin(admin.ModelAdmin):
|
class FanOutAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "state", "state_attempted", "type", "identity"]
|
list_display = ["id", "state", "state_attempted", "type", "identity"]
|
||||||
|
list_filter = (IdentityLocalFilter, "type", "state", "state_attempted")
|
||||||
raw_id_fields = ["identity", "subject_post", "subject_post_interaction"]
|
raw_id_fields = ["identity", "subject_post", "subject_post_interaction"]
|
||||||
readonly_fields = ["created", "updated"]
|
readonly_fields = ["created", "updated"]
|
||||||
actions = ["force_execution"]
|
actions = ["force_execution"]
|
||||||
@ -101,6 +129,7 @@ class FanOutAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(PostInteraction)
|
@admin.register(PostInteraction)
|
||||||
class PostInteractionAdmin(admin.ModelAdmin):
|
class PostInteractionAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "state", "state_attempted", "type", "identity", "post"]
|
list_display = ["id", "state", "state_attempted", "type", "identity", "post"]
|
||||||
|
list_filter = (IdentityLocalFilter, "type", "state")
|
||||||
raw_id_fields = ["identity", "post"]
|
raw_id_fields = ["identity", "post"]
|
||||||
|
|
||||||
def has_add_permission(self, request, obj=None):
|
def has_add_permission(self, request, obj=None):
|
||||||
|
@ -1,8 +1,33 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import Config
|
from core.models import Config
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigOptionsTypeFilter(admin.SimpleListFilter):
|
||||||
|
title = _("config options type")
|
||||||
|
parameter_name = "type"
|
||||||
|
|
||||||
|
def lookups(self, request, model_admin):
|
||||||
|
return (
|
||||||
|
("system", _("System")),
|
||||||
|
("identity", _("Identity")),
|
||||||
|
("user", _("User")),
|
||||||
|
)
|
||||||
|
|
||||||
|
def queryset(self, request, queryset):
|
||||||
|
match self.value():
|
||||||
|
case "system":
|
||||||
|
return queryset.filter(user__isnull=True, identity__isnull=True)
|
||||||
|
case "identity":
|
||||||
|
return queryset.exclude(identity__isnull=True)
|
||||||
|
case "user":
|
||||||
|
return queryset.exclude(user__isnull=True)
|
||||||
|
case _:
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Config)
|
@admin.register(Config)
|
||||||
class ConfigAdmin(admin.ModelAdmin):
|
class ConfigAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "key", "user", "identity"]
|
list_display = ["id", "key", "user", "identity"]
|
||||||
|
list_filter = (ConfigOptionsTypeFilter,)
|
||||||
|
@ -13,6 +13,7 @@ class DomainAdmin(admin.ModelAdmin):
|
|||||||
"state",
|
"state",
|
||||||
"error",
|
"error",
|
||||||
]
|
]
|
||||||
|
list_filter = ["model_label", "date"]
|
||||||
ordering = ["-date"]
|
ordering = ["-date"]
|
||||||
|
|
||||||
def has_add_permission(self, request, obj=None):
|
def has_add_permission(self, request, obj=None):
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from activities.admin import IdentityLocalFilter
|
||||||
from users.models import (
|
from users.models import (
|
||||||
Domain,
|
Domain,
|
||||||
Follow,
|
Follow,
|
||||||
@ -15,12 +17,15 @@ from users.models import (
|
|||||||
@admin.register(Domain)
|
@admin.register(Domain)
|
||||||
class DomainAdmin(admin.ModelAdmin):
|
class DomainAdmin(admin.ModelAdmin):
|
||||||
list_display = ["domain", "service_domain", "local", "blocked", "public"]
|
list_display = ["domain", "service_domain", "local", "blocked", "public"]
|
||||||
|
list_filter = ("local", "blocked")
|
||||||
|
search_fields = ("domain", "service_domain")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(User)
|
@admin.register(User)
|
||||||
class UserAdmin(admin.ModelAdmin):
|
class UserAdmin(admin.ModelAdmin):
|
||||||
list_display = ["email", "created", "last_seen", "admin", "moderator", "banned"]
|
list_display = ["email", "created", "last_seen", "admin", "moderator", "banned"]
|
||||||
search_fields = ["email"]
|
search_fields = ["email"]
|
||||||
|
list_filter = ("admin", "moderator", "banned")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(UserEvent)
|
@admin.register(UserEvent)
|
||||||
@ -32,7 +37,7 @@ class UserEventAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(Identity)
|
@admin.register(Identity)
|
||||||
class IdentityAdmin(admin.ModelAdmin):
|
class IdentityAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "handle", "actor_uri", "state", "local"]
|
list_display = ["id", "handle", "actor_uri", "state", "local"]
|
||||||
list_filter = ["local"]
|
list_filter = ("local", "state", "discoverable")
|
||||||
raw_id_fields = ["users"]
|
raw_id_fields = ["users"]
|
||||||
actions = ["force_update"]
|
actions = ["force_update"]
|
||||||
readonly_fields = ["actor_json"]
|
readonly_fields = ["actor_json"]
|
||||||
@ -51,9 +56,22 @@ class IdentityAdmin(admin.ModelAdmin):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class LocalSourceFilter(IdentityLocalFilter):
|
||||||
|
title = _("Local Source Identity")
|
||||||
|
parameter_name = "srclocal"
|
||||||
|
identity_field_name = "source"
|
||||||
|
|
||||||
|
|
||||||
|
class LocalTargetFilter(IdentityLocalFilter):
|
||||||
|
title = _("Local Target Identity")
|
||||||
|
parameter_name = "tgtlocal"
|
||||||
|
identity_field_name = "target"
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Follow)
|
@admin.register(Follow)
|
||||||
class FollowAdmin(admin.ModelAdmin):
|
class FollowAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "source", "target", "state"]
|
list_display = ["id", "source", "target", "state"]
|
||||||
|
list_filter = [LocalSourceFilter, LocalTargetFilter, "state"]
|
||||||
raw_id_fields = ["source", "target"]
|
raw_id_fields = ["source", "target"]
|
||||||
|
|
||||||
def has_add_permission(self, request, obj=None):
|
def has_add_permission(self, request, obj=None):
|
||||||
@ -72,6 +90,7 @@ class PasswordResetAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(InboxMessage)
|
@admin.register(InboxMessage)
|
||||||
class InboxMessageAdmin(admin.ModelAdmin):
|
class InboxMessageAdmin(admin.ModelAdmin):
|
||||||
list_display = ["id", "state", "state_changed", "message_type", "message_actor"]
|
list_display = ["id", "state", "state_changed", "message_type", "message_actor"]
|
||||||
|
list_filter = ("state",)
|
||||||
search_fields = ["message"]
|
search_fields = ["message"]
|
||||||
actions = ["reset_state"]
|
actions = ["reset_state"]
|
||||||
readonly_fields = ["state_changed"]
|
readonly_fields = ["state_changed"]
|
||||||
|
Reference in New Issue
Block a user