Mercurial > public > sg101
comparison weblinks/admin.py @ 675:6e6492468bb8
Add admin action to acknowledge flagged links.
Fix bug where weblinks js wasn't being included on detail page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 03 Aug 2013 22:12:03 -0500 |
parents | ee87ea74d46b |
children |
comparison
equal
deleted
inserted
replaced
673:92101013d5ac | 675:6e6492468bb8 |
---|---|
7 from weblinks.models import Link | 7 from weblinks.models import Link |
8 from weblinks.models import FlaggedLink | 8 from weblinks.models import FlaggedLink |
9 | 9 |
10 | 10 |
11 class CategoryAdmin(admin.ModelAdmin): | 11 class CategoryAdmin(admin.ModelAdmin): |
12 list_display = ('title', 'slug', 'description', 'count') | 12 list_display = ['title', 'slug', 'description', 'count'] |
13 prepopulated_fields = {'slug': ('title', )} | 13 prepopulated_fields = {'slug': ['title', ]} |
14 readonly_fields = ('count', ) | 14 readonly_fields = ['count'] |
15 | 15 |
16 | 16 |
17 class PendingLinkAdmin(admin.ModelAdmin): | 17 class PendingLinkAdmin(admin.ModelAdmin): |
18 list_display = ('title', 'url', 'user', 'category', 'date_added') | 18 list_display = ['title', 'url', 'user', 'category', 'date_added'] |
19 raw_id_fields = ('user', ) | 19 raw_id_fields = ['user'] |
20 actions = ('approve_links', ) | 20 actions = ['approve_links'] |
21 readonly_fields = ('update_date', ) | 21 readonly_fields = ['update_date'] |
22 | 22 |
23 def approve_links(self, request, qs): | 23 def approve_links(self, request, qs): |
24 for pending_link in qs: | 24 for pending_link in qs: |
25 link = Link(category=pending_link.category, | 25 link = Link(category=pending_link.category, |
26 title=pending_link.title, | 26 title=pending_link.title, |
39 | 39 |
40 approve_links.short_description = "Approve selected links" | 40 approve_links.short_description = "Approve selected links" |
41 | 41 |
42 | 42 |
43 class LinkAdmin(admin.ModelAdmin): | 43 class LinkAdmin(admin.ModelAdmin): |
44 list_display = ('title', 'url', 'category', 'date_added', 'hits', 'is_public') | 44 list_display = ['title', 'url', 'category', 'date_added', 'hits', 'is_public'] |
45 list_filter = ('date_added', 'is_public', 'category') | 45 list_filter = ['date_added', 'is_public', 'category'] |
46 date_hierarchy = 'date_added' | 46 date_hierarchy = 'date_added' |
47 ordering = ('-date_added', ) | 47 ordering = ['-date_added'] |
48 search_fields = ('title', 'description', 'url', 'user__username') | 48 search_fields = ['title', 'description', 'url', 'user__username'] |
49 raw_id_fields = ('user', ) | 49 raw_id_fields = ['user'] |
50 readonly_fields = ('update_date', ) | 50 readonly_fields = ['update_date'] |
51 save_on_top = True | 51 save_on_top = True |
52 | 52 |
53 | 53 |
54 class FlaggedLinkAdmin(admin.ModelAdmin): | 54 class FlaggedLinkAdmin(admin.ModelAdmin): |
55 list_display = ('__unicode__', 'url', 'get_link_url', 'user', 'date_flagged') | 55 list_display = ['__unicode__', 'url', 'get_link_url', 'user', 'date_flagged'] |
56 date_hierarchy = 'date_flagged' | 56 date_hierarchy = 'date_flagged' |
57 raw_id_fields = ('user', ) | 57 raw_id_fields = ['user'] |
58 | |
59 actions = ['hide_links'] | |
60 | |
61 def hide_links(self, request, qs): | |
62 for flagged_link in qs: | |
63 flagged_link.link.is_public = False | |
64 flagged_link.link.save() | |
65 | |
66 count = len(qs) | |
67 qs.delete() | |
68 msg = "1 link" if count == 1 else "%d links" % count | |
69 self.message_user(request, "%s hidden." % msg) | |
70 | |
71 hide_links.short_description = "Accept flags & hide links" | |
72 | |
58 | 73 |
59 admin.site.register(Category, CategoryAdmin) | 74 admin.site.register(Category, CategoryAdmin) |
60 admin.site.register(PendingLink, PendingLinkAdmin) | 75 admin.site.register(PendingLink, PendingLinkAdmin) |
61 admin.site.register(Link, LinkAdmin) | 76 admin.site.register(Link, LinkAdmin) |
62 admin.site.register(FlaggedLink, FlaggedLinkAdmin) | 77 admin.site.register(FlaggedLink, FlaggedLinkAdmin) |