##// END OF EJS Templates
Show image previews in post's admin page
Show image previews in post's admin page

File last commit:

r1541:344601de default
r1541:344601de default
Show More
admin.py
114 lines | 3.7 KiB | text/x-python | PythonLexer
neko259
Initial commit. One test doesn't work, missing posting form.
r0 from django.contrib import admin
neko259
Added admin action to ban user that posted given messages
r968 from django.utils.translation import ugettext_lazy as _
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 from django.core.urlresolvers import reverse
from boards.models import Post, Tag, Ban, Thread, Banner, PostImage
neko259
Initial commit. One test doesn't work, missing posting form.
r0
neko259
Moved some settings to boards.settings
r333
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 @admin.register(Post)
neko259
Added a better admin interface.
r305 class PostAdmin(admin.ModelAdmin):
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 list_display = ('id', 'title', 'text', 'poster_ip', 'linked_images')
neko259
Don't list all threads to filter posts by
r969 list_filter = ('pub_time',)
neko259
Allow searching posts by IP in the admin site
r1130 search_fields = ('id', 'title', 'text', 'poster_ip')
neko259
Don't allow modifying post's images list from admin page
r1540 exclude = ('referenced_posts', 'refmap', 'images')
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 readonly_fields = ('poster_ip', 'threads', 'thread', 'linked_images',
neko259
Made some fields in post admin read-only. Show attachment as its url
r1389 'attachments', 'uid', 'url', 'pub_time', 'opening')
neko259
Added a better admin interface.
r305
neko259
Added admin action to ban user that posted given messages
r968 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))
neko259
Allow banning user and hiding all its (by IP) posts
r1495 def ban_with_hiding(self, request, queryset):
bans = 0
hidden = 0
for post in queryset:
poster_ip = post.poster_ip
ban, created = Ban.objects.get_or_create(ip=poster_ip)
if created:
bans += 1
neko259
Hide only posts later than the specified ones when banning a user
r1496 posts = Post.objects.filter(poster_ip=poster_ip, id__gte=post.id)
neko259
Allow banning user and hiding all its (by IP) posts
r1495 hidden += posts.count()
posts.update(hidden=True)
self.message_user(request, _('{} posters were banned, {} messages were hidden').format(bans, hidden))
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 def linked_images(self, obj: Post):
images = obj.images.all()
neko259
Show image previews in post's admin page
r1541 image_urls = ['<a href="{}"><img src="{}" /></a>'.format(
reverse('admin:%s_%s_change' % (image._meta.app_label,
image._meta.model_name),
args=[image.id]), image.image.url_200x150) for image in images]
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500 return ', '.join(image_urls)
linked_images.allow_tags = True
neko259
Allow banning user and hiding all its (by IP) posts
r1495
actions = ['ban_poster', 'ban_with_hiding']
neko259
Added admin action to ban user that posted given messages
r968
neko259
Moved some settings to boards.settings
r333
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 @admin.register(Tag)
neko259
Added a better admin interface.
r305 class TagAdmin(admin.ModelAdmin):
neko259
Small admin changes
r910 def thread_count(self, obj: Tag) -> int:
return obj.get_thread_count()
neko259
More columns for tag and thread admin
r1356 def display_children(self, obj: Tag):
return ', '.join([str(child) for child in obj.get_children().all()])
neko259
Update tag threads' tags when the tag's parent is changed
r1471 def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)
for thread in obj.get_threads().all():
thread.refresh_tags()
neko259
More columns for tag and thread admin
r1356 list_display = ('name', 'thread_count', 'display_children')
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 search_fields = ('name',)
neko259
Added a better admin interface.
r305
neko259
Cosmetic changes to the admin models
r883
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 @admin.register(Thread)
neko259
Added thread admin interface
r604 class ThreadAdmin(admin.ModelAdmin):
neko259
Small admin changes
r910 def title(self, obj: Thread) -> str:
neko259
Cosmetic changes to the admin models
r883 return obj.get_opening_post().get_title()
neko259
Added thread admin interface
r604
neko259
Small admin changes
r910 def reply_count(self, obj: Thread) -> int:
neko259
Added thread admin interface
r604 return obj.get_reply_count()
neko259
Small admin changes
r910 def ip(self, obj: Thread):
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 return obj.get_opening_post().poster_ip
neko259
More columns for tag and thread admin
r1356 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()
neko259
When editing tags in admin, add their parents as in a thread creation form
r1470 # Save parent tags when editing tags
def save_related(self, request, form, formsets, change):
super().save_related(request, form, formsets, change)
neko259
Update tag threads' tags when the tag's parent is changed
r1471 form.instance.refresh_tags()
neko259
When editing tags in admin, add their parents as in a thread creation form
r1470
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 list_display = ('id', 'op', 'title', 'reply_count', 'status', 'ip',
neko259
More columns for tag and thread admin
r1356 'display_tags')
neko259
Thread status field instead of bumpable and archived fields (per BB-73)
r1414 list_filter = ('bump_time', 'status')
neko259
Added thread admin interface
r604 search_fields = ('id', 'title')
neko259
Better interface for the thread admin tags list
r921 filter_horizontal = ('tags',)
neko259
Added thread admin interface
r604
neko259
Cosmetic changes to the admin models
r883
neko259
Cleaned up admin site. Update thread's tags list when it is saved
r906 @admin.register(Ban)
neko259
Updated ban admin to search by ip
r804 class BanAdmin(admin.ModelAdmin):
list_display = ('ip', 'can_read')
list_filter = ('can_read',)
neko259
Better interface for the thread admin tags list
r921 search_fields = ('ip',)
neko259
Added banner to show the site news. Returned the message middleware because it...
r1148
@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
list_display = ('title', 'text')
neko259
Added image aliases to upload the same images (like "fake" or "gtfo")
r1500
@admin.register(PostImage)
class PostImageAdmin(admin.ModelAdmin):
search_fields = ('alias',)