2022-11-28 20:41:36 -08:00
|
|
|
from asgiref.sync import async_to_sync
|
2022-11-11 21:02:43 -08:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2022-11-16 22:00:10 -08:00
|
|
|
from activities.models import (
|
|
|
|
FanOut,
|
2022-11-28 20:41:36 -08:00
|
|
|
Hashtag,
|
2022-11-16 22:00:10 -08:00
|
|
|
Post,
|
|
|
|
PostAttachment,
|
|
|
|
PostInteraction,
|
|
|
|
TimelineEvent,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-11-28 20:41:36 -08:00
|
|
|
@admin.register(Hashtag)
|
|
|
|
class HashtagAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["hashtag", "name_override", "state", "stats_updated", "created"]
|
|
|
|
|
|
|
|
readonly_fields = ["created", "updated", "stats_updated"]
|
|
|
|
|
|
|
|
actions = ["force_execution"]
|
|
|
|
|
|
|
|
@admin.action(description="Force Execution")
|
|
|
|
def force_execution(self, request, queryset):
|
|
|
|
for instance in queryset:
|
|
|
|
instance.transition_perform("outdated")
|
|
|
|
|
|
|
|
|
2022-12-01 17:46:49 -08:00
|
|
|
@admin.register(PostAttachment)
|
|
|
|
class PostAttachmentAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["id", "post", "created"]
|
|
|
|
|
|
|
|
|
2022-11-16 22:00:10 -08:00
|
|
|
class PostAttachmentInline(admin.StackedInline):
|
|
|
|
model = PostAttachment
|
|
|
|
extra = 0
|
2022-11-11 21:02:43 -08:00
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Post)
|
|
|
|
class PostAdmin(admin.ModelAdmin):
|
2022-11-11 22:04:43 -08:00
|
|
|
list_display = ["id", "state", "author", "created"]
|
2022-11-15 17:30:30 -08:00
|
|
|
raw_id_fields = ["to", "mentions", "author"]
|
2022-11-28 20:41:36 -08:00
|
|
|
actions = ["force_fetch", "reparse_hashtags"]
|
2022-11-16 22:00:10 -08:00
|
|
|
search_fields = ["content"]
|
|
|
|
inlines = [PostAttachmentInline]
|
2022-11-15 17:30:30 -08:00
|
|
|
readonly_fields = ["created", "updated", "object_json"]
|
2022-11-13 18:03:43 -08:00
|
|
|
|
|
|
|
@admin.action(description="Force Fetch")
|
|
|
|
def force_fetch(self, request, queryset):
|
|
|
|
for instance in queryset:
|
|
|
|
instance.debug_fetch()
|
2022-11-11 21:02:43 -08:00
|
|
|
|
2022-11-28 20:41:36 -08:00
|
|
|
@admin.action(description="Reprocess content for hashtags")
|
|
|
|
def reparse_hashtags(self, request, queryset):
|
|
|
|
for instance in queryset:
|
|
|
|
instance.hashtags = Hashtag.hashtags_from_content(instance.content) or None
|
|
|
|
instance.save()
|
|
|
|
async_to_sync(instance.ensure_hashtags)()
|
|
|
|
|
2022-11-15 17:30:30 -08:00
|
|
|
@admin.display(description="ActivityPub JSON")
|
|
|
|
def object_json(self, instance):
|
|
|
|
return instance.to_ap()
|
|
|
|
|
2022-11-20 10:18:42 -08:00
|
|
|
def has_add_permission(self, request, obj=None):
|
|
|
|
"""
|
|
|
|
Disables admin creation of posts as it will skip steps
|
|
|
|
"""
|
|
|
|
return False
|
|
|
|
|
2022-11-11 21:02:43 -08:00
|
|
|
|
|
|
|
@admin.register(TimelineEvent)
|
|
|
|
class TimelineEventAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["id", "identity", "created", "type"]
|
2022-11-17 17:52:00 -08:00
|
|
|
readonly_fields = ["created"]
|
2022-11-15 17:30:30 -08:00
|
|
|
raw_id_fields = [
|
|
|
|
"identity",
|
|
|
|
"subject_post",
|
|
|
|
"subject_identity",
|
|
|
|
"subject_post_interaction",
|
|
|
|
]
|
2022-11-11 22:04:43 -08:00
|
|
|
|
2022-11-27 16:16:09 -08:00
|
|
|
def has_add_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
2022-11-11 22:04:43 -08:00
|
|
|
|
|
|
|
@admin.register(FanOut)
|
|
|
|
class FanOutAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["id", "state", "state_attempted", "type", "identity"]
|
2022-11-15 17:30:30 -08:00
|
|
|
raw_id_fields = ["identity", "subject_post", "subject_post_interaction"]
|
|
|
|
readonly_fields = ["created", "updated"]
|
|
|
|
actions = ["force_execution"]
|
|
|
|
|
|
|
|
@admin.action(description="Force Execution")
|
|
|
|
def force_execution(self, request, queryset):
|
|
|
|
for instance in queryset:
|
|
|
|
instance.transition_perform("new")
|
2022-11-13 17:42:47 -08:00
|
|
|
|
2022-11-27 16:16:09 -08:00
|
|
|
def has_add_permission(self, request, obj=None):
|
|
|
|
return False
|
|
|
|
|
2022-11-13 17:42:47 -08:00
|
|
|
|
|
|
|
@admin.register(PostInteraction)
|
|
|
|
class PostInteractionAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ["id", "state", "state_attempted", "type", "identity", "post"]
|
|
|
|
raw_id_fields = ["identity", "post"]
|
2022-11-27 16:16:09 -08:00
|
|
|
|
|
|
|
def has_add_permission(self, request, obj=None):
|
|
|
|
return False
|