summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
authorMichael Manfre2022-12-08 12:29:51 -0500
committerGitHub2022-12-08 10:29:51 -0700
commita576c5b5ed716b8068c02914fd47f38473610590 (patch)
tree001448f79005826bb7609d1568d9e89b6f675371 /activities
parent08dae900b72e7fdad56cd8d2a7a75422f289e993 (diff)
downloadtakahe-a576c5b5ed716b8068c02914fd47f38473610590.tar.gz
takahe-a576c5b5ed716b8068c02914fd47f38473610590.tar.bz2
takahe-a576c5b5ed716b8068c02914fd47f38473610590.zip
Improve djadmin filtering and search (#149)
Diffstat (limited to 'activities')
-rw-r--r--activities/admin.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/activities/admin.py b/activities/admin.py
index fe7b52f..edc7365 100644
--- a/activities/admin.py
+++ b/activities/admin.py
@@ -1,5 +1,6 @@
from asgiref.sync import async_to_sync
from django.contrib import admin
+from django.utils.translation import gettext_lazy as _
from activities.models import (
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)
class HashtagAdmin(admin.ModelAdmin):
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"]
@@ -38,6 +63,7 @@ class PostAttachmentInline(admin.StackedInline):
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ["id", "state", "author", "created"]
+ list_filter = ("local", "visibility", "state", "created")
raw_id_fields = ["to", "mentions", "author"]
actions = ["force_fetch", "reparse_hashtags"]
search_fields = ["content"]
@@ -70,6 +96,7 @@ class PostAdmin(admin.ModelAdmin):
@admin.register(TimelineEvent)
class TimelineEventAdmin(admin.ModelAdmin):
list_display = ["id", "identity", "created", "type"]
+ list_filter = (IdentityLocalFilter, "type")
readonly_fields = ["created"]
raw_id_fields = [
"identity",
@@ -85,6 +112,7 @@ class TimelineEventAdmin(admin.ModelAdmin):
@admin.register(FanOut)
class FanOutAdmin(admin.ModelAdmin):
list_display = ["id", "state", "state_attempted", "type", "identity"]
+ list_filter = (IdentityLocalFilter, "type", "state", "state_attempted")
raw_id_fields = ["identity", "subject_post", "subject_post_interaction"]
readonly_fields = ["created", "updated"]
actions = ["force_execution"]
@@ -101,6 +129,7 @@ class FanOutAdmin(admin.ModelAdmin):
@admin.register(PostInteraction)
class PostInteractionAdmin(admin.ModelAdmin):
list_display = ["id", "state", "state_attempted", "type", "identity", "post"]
+ list_filter = (IdentityLocalFilter, "type", "state")
raw_id_fields = ["identity", "post"]
def has_add_permission(self, request, obj=None):