annotate downloads/admin.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/downloads/admin.py@6144023ebea8
children 0dd84cff2477
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@277 27 readonly_fields = ('update_date', )
bgneal@204 28
bgneal@204 29 actions = ('approve_downloads', )
bgneal@204 30
bgneal@204 31 def approve_downloads(self, request, qs):
bgneal@204 32 for pending_dl in qs:
bgneal@204 33 dl = Download(
bgneal@204 34 title=pending_dl.title,
bgneal@204 35 category=pending_dl.category,
bgneal@204 36 description=pending_dl.description,
bgneal@204 37 html=pending_dl.html,
bgneal@204 38 file=pending_dl.file,
bgneal@204 39 user=pending_dl.user,
bgneal@204 40 date_added=datetime.datetime.now(),
bgneal@204 41 ip_address=pending_dl.ip_address,
bgneal@204 42 hits=0,
bgneal@204 43 average_score=0.0,
bgneal@204 44 total_votes=0,
bgneal@204 45 is_public=True)
bgneal@204 46 dl.save()
bgneal@204 47
bgneal@204 48 # If we don't do this, the actual file will be deleted when
bgneal@204 49 # the pending download is deleted.
bgneal@204 50 pending_dl.file = None
bgneal@204 51 pending_dl.delete()
bgneal@204 52
bgneal@204 53 approve_downloads.short_description = "Approve selected downloads"
bgneal@204 54
bgneal@204 55
gremmie@1 56 class DownloadAdmin(admin.ModelAdmin):
bgneal@192 57 exclude = ('html', )
bgneal@192 58 list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
bgneal@192 59 'hits', 'average_score', 'size', 'is_public')
bgneal@413 60 list_filter = ('date_added', 'is_public', 'category')
bgneal@413 61 list_editable = ('is_public', )
bgneal@192 62 date_hierarchy = 'date_added'
bgneal@192 63 ordering = ('-date_added', )
bgneal@192 64 search_fields = ('title', 'description', 'user__username')
bgneal@192 65 raw_id_fields = ('user', )
bgneal@277 66 readonly_fields = ('update_date', )
bgneal@192 67 save_on_top = True
gremmie@1 68
gremmie@1 69
gremmie@1 70 class VoteRecordAdmin(admin.ModelAdmin):
bgneal@192 71 list_display = ('user', 'download', 'vote_date')
bgneal@192 72 list_filter = ('user', 'download')
bgneal@192 73 date_hierarchy = 'vote_date'
gremmie@1 74
gremmie@1 75
bgneal@204 76 admin.site.register(PendingDownload, PendingDownloadAdmin)
gremmie@1 77 admin.site.register(Download, DownloadAdmin)
bgneal@192 78 admin.site.register(Category, CategoryAdmin)
gremmie@1 79 admin.site.register(AllowedExtension)
gremmie@1 80 admin.site.register(VoteRecord, VoteRecordAdmin)
bgneal@8 81