annotate gpp/downloads/admin.py @ 271:4746df47a538

Follow on to last rev (r292) for #126. Missed updating a shoutbox template. Also the repoze.timeago package uses UTC time by default. Change this to local time for now until we decide to switch over to UTC for everything.
author Brian Neal <bgneal@gmail.com>
date Sun, 26 Sep 2010 17:42:00 +0000
parents 27bee3ac85e6
children d424b8bae71d
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the automatic admin site definitions for the downloads models.
gremmie@1 3 """
bgneal@204 4 import datetime
bgneal@204 5
gremmie@1 6 from django.contrib import admin
bgneal@6 7 from django.conf import settings
bgneal@6 8
bgneal@204 9 from downloads.models import PendingDownload
gremmie@1 10 from downloads.models import Download
gremmie@1 11 from downloads.models import Category
gremmie@1 12 from downloads.models import AllowedExtension
gremmie@1 13 from downloads.models import VoteRecord
gremmie@1 14
bgneal@192 15
bgneal@192 16 class CategoryAdmin(admin.ModelAdmin):
bgneal@241 17 list_display = ('title', 'slug', 'description', 'count')
bgneal@241 18 prepopulated_fields = {'slug': ('title', )}
bgneal@192 19 readonly_fields = ('count', )
bgneal@192 20
bgneal@192 21
bgneal@204 22 class PendingDownloadAdmin(admin.ModelAdmin):
bgneal@204 23 exclude = ('html', )
bgneal@204 24 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size')
bgneal@204 25 ordering = ('date_added', )
bgneal@204 26 raw_id_fields = ('user', )
bgneal@204 27
bgneal@204 28 actions = ('approve_downloads', )
bgneal@204 29
bgneal@204 30 def approve_downloads(self, request, qs):
bgneal@204 31 for pending_dl in qs:
bgneal@204 32 dl = Download(
bgneal@204 33 title=pending_dl.title,
bgneal@204 34 category=pending_dl.category,
bgneal@204 35 description=pending_dl.description,
bgneal@204 36 html=pending_dl.html,
bgneal@204 37 file=pending_dl.file,
bgneal@204 38 user=pending_dl.user,
bgneal@204 39 date_added=datetime.datetime.now(),
bgneal@204 40 ip_address=pending_dl.ip_address,
bgneal@204 41 hits=0,
bgneal@204 42 average_score=0.0,
bgneal@204 43 total_votes=0,
bgneal@204 44 is_public=True)
bgneal@204 45 dl.save()
bgneal@204 46
bgneal@204 47 # If we don't do this, the actual file will be deleted when
bgneal@204 48 # the pending download is deleted.
bgneal@204 49 pending_dl.file = None
bgneal@204 50 pending_dl.delete()
bgneal@204 51
bgneal@204 52 approve_downloads.short_description = "Approve selected downloads"
bgneal@204 53
bgneal@204 54
gremmie@1 55 class DownloadAdmin(admin.ModelAdmin):
bgneal@192 56 exclude = ('html', )
bgneal@192 57 list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
bgneal@192 58 'hits', 'average_score', 'size', 'is_public')
bgneal@192 59 list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address')
bgneal@192 60 date_hierarchy = 'date_added'
bgneal@192 61 ordering = ('-date_added', )
bgneal@192 62 search_fields = ('title', 'description', 'user__username')
bgneal@192 63 raw_id_fields = ('user', )
bgneal@192 64 save_on_top = True
gremmie@1 65
gremmie@1 66
gremmie@1 67 class VoteRecordAdmin(admin.ModelAdmin):
bgneal@192 68 list_display = ('user', 'download', 'vote_date')
bgneal@192 69 list_filter = ('user', 'download')
bgneal@192 70 date_hierarchy = 'vote_date'
gremmie@1 71
gremmie@1 72
bgneal@204 73 admin.site.register(PendingDownload, PendingDownloadAdmin)
gremmie@1 74 admin.site.register(Download, DownloadAdmin)
bgneal@192 75 admin.site.register(Category, CategoryAdmin)
gremmie@1 76 admin.site.register(AllowedExtension)
gremmie@1 77 admin.site.register(VoteRecord, VoteRecordAdmin)
bgneal@8 78