annotate weblinks/admin.py @ 834:89a3a6433f6f

Bandmap admin tweaks: display lat/lon. Admin dashboard link takes you to unapproved entries.
author Brian Neal <bgneal@gmail.com>
date Tue, 30 Sep 2014 19:05:42 -0500
parents 6e6492468bb8
children
rev   line source
gremmie@1 1 """This file contains the automatic admin site definitions for the weblinks models"""
bgneal@204 2 import datetime
gremmie@1 3
gremmie@1 4 from django.contrib import admin
gremmie@1 5 from weblinks.models import Category
bgneal@204 6 from weblinks.models import PendingLink
gremmie@1 7 from weblinks.models import Link
gremmie@1 8 from weblinks.models import FlaggedLink
gremmie@1 9
bgneal@193 10
bgneal@193 11 class CategoryAdmin(admin.ModelAdmin):
bgneal@675 12 list_display = ['title', 'slug', 'description', 'count']
bgneal@675 13 prepopulated_fields = {'slug': ['title', ]}
bgneal@675 14 readonly_fields = ['count']
bgneal@193 15
bgneal@193 16
bgneal@204 17 class PendingLinkAdmin(admin.ModelAdmin):
bgneal@675 18 list_display = ['title', 'url', 'user', 'category', 'date_added']
bgneal@675 19 raw_id_fields = ['user']
bgneal@675 20 actions = ['approve_links']
bgneal@675 21 readonly_fields = ['update_date']
bgneal@204 22
bgneal@204 23 def approve_links(self, request, qs):
bgneal@204 24 for pending_link in qs:
bgneal@204 25 link = Link(category=pending_link.category,
bgneal@204 26 title=pending_link.title,
bgneal@204 27 url=pending_link.url,
bgneal@204 28 description=pending_link.description,
bgneal@204 29 user=pending_link.user,
bgneal@204 30 date_added=datetime.datetime.now(),
bgneal@204 31 hits=0,
bgneal@204 32 is_public=True)
bgneal@204 33 link.save()
bgneal@204 34 pending_link.delete()
bgneal@204 35
bgneal@398 36 count = len(qs)
bgneal@398 37 msg = "1 link" if count == 1 else "%d links" % count
bgneal@398 38 self.message_user(request, "%s approved." % msg)
bgneal@398 39
bgneal@204 40 approve_links.short_description = "Approve selected links"
bgneal@204 41
bgneal@204 42
gremmie@1 43 class LinkAdmin(admin.ModelAdmin):
bgneal@675 44 list_display = ['title', 'url', 'category', 'date_added', 'hits', 'is_public']
bgneal@675 45 list_filter = ['date_added', 'is_public', 'category']
gremmie@1 46 date_hierarchy = 'date_added'
bgneal@675 47 ordering = ['-date_added']
bgneal@675 48 search_fields = ['title', 'description', 'url', 'user__username']
bgneal@675 49 raw_id_fields = ['user']
bgneal@675 50 readonly_fields = ['update_date']
gremmie@1 51 save_on_top = True
gremmie@1 52
bgneal@193 53
gremmie@1 54 class FlaggedLinkAdmin(admin.ModelAdmin):
bgneal@675 55 list_display = ['__unicode__', 'url', 'get_link_url', 'user', 'date_flagged']
gremmie@1 56 date_hierarchy = 'date_flagged'
bgneal@675 57 raw_id_fields = ['user']
bgneal@675 58
bgneal@675 59 actions = ['hide_links']
bgneal@675 60
bgneal@675 61 def hide_links(self, request, qs):
bgneal@675 62 for flagged_link in qs:
bgneal@675 63 flagged_link.link.is_public = False
bgneal@675 64 flagged_link.link.save()
bgneal@675 65
bgneal@675 66 count = len(qs)
bgneal@675 67 qs.delete()
bgneal@675 68 msg = "1 link" if count == 1 else "%d links" % count
bgneal@675 69 self.message_user(request, "%s hidden." % msg)
bgneal@675 70
bgneal@675 71 hide_links.short_description = "Accept flags & hide links"
bgneal@675 72
gremmie@1 73
bgneal@193 74 admin.site.register(Category, CategoryAdmin)
bgneal@204 75 admin.site.register(PendingLink, PendingLinkAdmin)
gremmie@1 76 admin.site.register(Link, LinkAdmin)
gremmie@1 77 admin.site.register(FlaggedLink, FlaggedLinkAdmin)