comparison gpp/weblinks/admin.py @ 204:b4305e18d3af

Resolve ticket #74. Add user badges. Some extra credit was done here: also refactored how pending news, links, and downloads are handled.
author Brian Neal <bgneal@gmail.com>
date Sat, 01 May 2010 21:53:59 +0000
parents fa7d82bfb100
children 7e8d2dda99e3
comparison
equal deleted inserted replaced
203:40e5903903e1 204:b4305e18d3af
1 """This file contains the automatic admin site definitions for the weblinks models""" 1 """This file contains the automatic admin site definitions for the weblinks models"""
2 import datetime
2 3
3 from django.contrib import admin 4 from django.contrib import admin
4 from weblinks.models import Category 5 from weblinks.models import Category
6 from weblinks.models import PendingLink
5 from weblinks.models import Link 7 from weblinks.models import Link
6 from weblinks.models import FlaggedLink 8 from weblinks.models import FlaggedLink
7 9
8 10
9 class CategoryAdmin(admin.ModelAdmin): 11 class CategoryAdmin(admin.ModelAdmin):
10 list_display = ('title', 'description', 'count') 12 list_display = ('title', 'description', 'count')
11 readonly_fields = ('count', ) 13 readonly_fields = ('count', )
14
15
16 class PendingLinkAdmin(admin.ModelAdmin):
17 list_display = ('title', 'url', 'user', 'category', 'date_added')
18 raw_id_fields = ('user', )
19 actions = ('approve_links', )
20
21 def approve_links(self, request, qs):
22 for pending_link in qs:
23 link = Link(category=pending_link.category,
24 title=pending_link.title,
25 url=pending_link.url,
26 description=pending_link.description,
27 user=pending_link.user,
28 date_added=datetime.datetime.now(),
29 hits=0,
30 is_public=True)
31 link.save()
32 pending_link.delete()
33
34 approve_links.short_description = "Approve selected links"
12 35
13 36
14 class LinkAdmin(admin.ModelAdmin): 37 class LinkAdmin(admin.ModelAdmin):
15 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') 38 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public')
16 list_filter = ('date_added', 'is_public', 'category') 39 list_filter = ('date_added', 'is_public', 'category')
25 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') 48 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged')
26 date_hierarchy = 'date_flagged' 49 date_hierarchy = 'date_flagged'
27 raw_id_fields = ('user', ) 50 raw_id_fields = ('user', )
28 51
29 admin.site.register(Category, CategoryAdmin) 52 admin.site.register(Category, CategoryAdmin)
53 admin.site.register(PendingLink, PendingLinkAdmin)
30 admin.site.register(Link, LinkAdmin) 54 admin.site.register(Link, LinkAdmin)
31 admin.site.register(FlaggedLink, FlaggedLinkAdmin) 55 admin.site.register(FlaggedLink, FlaggedLinkAdmin)