##// END OF EJS Templates
Do not pass over perms variable manually to the post template. Fixed thread...
Do not pass over perms variable manually to the post template. Fixed thread diff using old method to check permissions

File last commit:

r1389:c9a1cd47 default
r1390:1252678f default
Show More
admin.py
75 lines | 2.2 KiB | text/x-python | PythonLexer
from django.contrib import admin
from boards.models import Post, Tag, Ban, Thread, Banner
from django.utils.translation import ugettext_lazy as _
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'text', 'poster_ip')
list_filter = ('pub_time',)
search_fields = ('id', 'title', 'text', 'poster_ip')
exclude = ('referenced_posts', 'refmap')
readonly_fields = ('poster_ip', 'threads', 'thread', 'images',
'attachments', 'uid', 'url', 'pub_time', 'opening')
def ban_poster(self, request, queryset):
bans = 0
for post in queryset:
poster_ip = post.poster_ip
ban, created = Ban.objects.get_or_create(ip=poster_ip)
if created:
bans += 1
self.message_user(request, _('{} posters were banned').format(bans))
actions = ['ban_poster']
@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
def thread_count(self, obj: Tag) -> int:
return obj.get_thread_count()
def display_children(self, obj: Tag):
return ', '.join([str(child) for child in obj.get_children().all()])
list_display = ('name', 'thread_count', 'display_children')
search_fields = ('name',)
@admin.register(Thread)
class ThreadAdmin(admin.ModelAdmin):
def title(self, obj: Thread) -> str:
return obj.get_opening_post().get_title()
def reply_count(self, obj: Thread) -> int:
return obj.get_reply_count()
def ip(self, obj: Thread):
return obj.get_opening_post().poster_ip
def display_tags(self, obj: Thread):
return ', '.join([str(tag) for tag in obj.get_tags().all()])
def op(self, obj: Thread):
return obj.get_opening_post_id()
list_display = ('id', 'op', 'title', 'reply_count', 'archived', 'ip',
'display_tags')
list_filter = ('bump_time', 'archived', 'bumpable')
search_fields = ('id', 'title')
filter_horizontal = ('tags',)
@admin.register(Ban)
class BanAdmin(admin.ModelAdmin):
list_display = ('ip', 'can_read')
list_filter = ('can_read',)
search_fields = ('ip',)
@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
list_display = ('title', 'text')