Mercurial > public > sg101
comparison gpp/downloads/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 | 341759e1cda1 |
children | 27bee3ac85e6 |
comparison
equal
deleted
inserted
replaced
203:40e5903903e1 | 204:b4305e18d3af |
---|---|
1 """ | 1 """ |
2 This file contains the automatic admin site definitions for the downloads models. | 2 This file contains the automatic admin site definitions for the downloads models. |
3 """ | 3 """ |
4 import datetime | |
5 | |
4 from django.contrib import admin | 6 from django.contrib import admin |
5 from django.conf import settings | 7 from django.conf import settings |
6 | 8 |
9 from downloads.models import PendingDownload | |
7 from downloads.models import Download | 10 from downloads.models import Download |
8 from downloads.models import Category | 11 from downloads.models import Category |
9 from downloads.models import AllowedExtension | 12 from downloads.models import AllowedExtension |
10 from downloads.models import VoteRecord | 13 from downloads.models import VoteRecord |
11 | 14 |
12 | 15 |
13 class CategoryAdmin(admin.ModelAdmin): | 16 class CategoryAdmin(admin.ModelAdmin): |
14 list_display = ('title', 'description', 'count') | 17 list_display = ('title', 'description', 'count') |
15 readonly_fields = ('count', ) | 18 readonly_fields = ('count', ) |
19 | |
20 | |
21 class PendingDownloadAdmin(admin.ModelAdmin): | |
22 exclude = ('html', ) | |
23 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size') | |
24 ordering = ('date_added', ) | |
25 raw_id_fields = ('user', ) | |
26 | |
27 actions = ('approve_downloads', ) | |
28 | |
29 def approve_downloads(self, request, qs): | |
30 for pending_dl in qs: | |
31 dl = Download( | |
32 title=pending_dl.title, | |
33 category=pending_dl.category, | |
34 description=pending_dl.description, | |
35 html=pending_dl.html, | |
36 file=pending_dl.file, | |
37 user=pending_dl.user, | |
38 date_added=datetime.datetime.now(), | |
39 ip_address=pending_dl.ip_address, | |
40 hits=0, | |
41 average_score=0.0, | |
42 total_votes=0, | |
43 is_public=True) | |
44 dl.save() | |
45 | |
46 # If we don't do this, the actual file will be deleted when | |
47 # the pending download is deleted. | |
48 pending_dl.file = None | |
49 pending_dl.delete() | |
50 | |
51 approve_downloads.short_description = "Approve selected downloads" | |
16 | 52 |
17 | 53 |
18 class DownloadAdmin(admin.ModelAdmin): | 54 class DownloadAdmin(admin.ModelAdmin): |
19 exclude = ('html', ) | 55 exclude = ('html', ) |
20 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', | 56 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', |
31 list_display = ('user', 'download', 'vote_date') | 67 list_display = ('user', 'download', 'vote_date') |
32 list_filter = ('user', 'download') | 68 list_filter = ('user', 'download') |
33 date_hierarchy = 'vote_date' | 69 date_hierarchy = 'vote_date' |
34 | 70 |
35 | 71 |
72 admin.site.register(PendingDownload, PendingDownloadAdmin) | |
36 admin.site.register(Download, DownloadAdmin) | 73 admin.site.register(Download, DownloadAdmin) |
37 admin.site.register(Category, CategoryAdmin) | 74 admin.site.register(Category, CategoryAdmin) |
38 admin.site.register(AllowedExtension) | 75 admin.site.register(AllowedExtension) |
39 admin.site.register(VoteRecord, VoteRecordAdmin) | 76 admin.site.register(VoteRecord, VoteRecordAdmin) |
40 | 77 |