annotate gpp/downloads/admin.py @ 236:953c71f382df

Created fixtures for initial data for the site.
author Brian Neal <bgneal@gmail.com>
date Fri, 10 Sep 2010 03:22:01 +0000
parents b4305e18d3af
children 27bee3ac85e6
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@192 17 list_display = ('title', 'description', 'count')
bgneal@192 18 readonly_fields = ('count', )
bgneal@192 19
bgneal@192 20
bgneal@204 21 class PendingDownloadAdmin(admin.ModelAdmin):
bgneal@204 22 exclude = ('html', )
bgneal@204 23 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size')
bgneal@204 24 ordering = ('date_added', )
bgneal@204 25 raw_id_fields = ('user', )
bgneal@204 26
bgneal@204 27 actions = ('approve_downloads', )
bgneal@204 28
bgneal@204 29 def approve_downloads(self, request, qs):
bgneal@204 30 for pending_dl in qs:
bgneal@204 31 dl = Download(
bgneal@204 32 title=pending_dl.title,
bgneal@204 33 category=pending_dl.category,
bgneal@204 34 description=pending_dl.description,
bgneal@204 35 html=pending_dl.html,
bgneal@204 36 file=pending_dl.file,
bgneal@204 37 user=pending_dl.user,
bgneal@204 38 date_added=datetime.datetime.now(),
bgneal@204 39 ip_address=pending_dl.ip_address,
bgneal@204 40 hits=0,
bgneal@204 41 average_score=0.0,
bgneal@204 42 total_votes=0,
bgneal@204 43 is_public=True)
bgneal@204 44 dl.save()
bgneal@204 45
bgneal@204 46 # If we don't do this, the actual file will be deleted when
bgneal@204 47 # the pending download is deleted.
bgneal@204 48 pending_dl.file = None
bgneal@204 49 pending_dl.delete()
bgneal@204 50
bgneal@204 51 approve_downloads.short_description = "Approve selected downloads"
bgneal@204 52
bgneal@204 53
gremmie@1 54 class DownloadAdmin(admin.ModelAdmin):
bgneal@192 55 exclude = ('html', )
bgneal@192 56 list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
bgneal@192 57 'hits', 'average_score', 'size', 'is_public')
bgneal@192 58 list_filter = ('date_added', 'is_public', 'category', 'user', 'ip_address')
bgneal@192 59 date_hierarchy = 'date_added'
bgneal@192 60 ordering = ('-date_added', )
bgneal@192 61 search_fields = ('title', 'description', 'user__username')
bgneal@192 62 raw_id_fields = ('user', )
bgneal@192 63 save_on_top = True
gremmie@1 64
gremmie@1 65
gremmie@1 66 class VoteRecordAdmin(admin.ModelAdmin):
bgneal@192 67 list_display = ('user', 'download', 'vote_date')
bgneal@192 68 list_filter = ('user', 'download')
bgneal@192 69 date_hierarchy = 'vote_date'
gremmie@1 70
gremmie@1 71
bgneal@204 72 admin.site.register(PendingDownload, PendingDownloadAdmin)
gremmie@1 73 admin.site.register(Download, DownloadAdmin)
bgneal@192 74 admin.site.register(Category, CategoryAdmin)
gremmie@1 75 admin.site.register(AllowedExtension)
gremmie@1 76 admin.site.register(VoteRecord, VoteRecordAdmin)
bgneal@8 77