diff 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
line wrap: on
line diff
--- a/gpp/downloads/admin.py	Wed Apr 28 03:00:31 2010 +0000
+++ b/gpp/downloads/admin.py	Sat May 01 21:53:59 2010 +0000
@@ -1,9 +1,12 @@
 """
 This file contains the automatic admin site definitions for the downloads models.
 """
+import datetime
+
 from django.contrib import admin
 from django.conf import settings
 
+from downloads.models import PendingDownload
 from downloads.models import Download
 from downloads.models import Category
 from downloads.models import AllowedExtension
@@ -15,6 +18,39 @@
     readonly_fields = ('count', )
 
 
+class PendingDownloadAdmin(admin.ModelAdmin):
+    exclude = ('html', )
+    list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size')
+    ordering = ('date_added', )
+    raw_id_fields = ('user', )
+
+    actions = ('approve_downloads', )
+
+    def approve_downloads(self, request, qs):
+        for pending_dl in qs:
+            dl = Download(
+                    title=pending_dl.title,
+                    category=pending_dl.category,
+                    description=pending_dl.description,
+                    html=pending_dl.html,
+                    file=pending_dl.file,
+                    user=pending_dl.user,
+                    date_added=datetime.datetime.now(),
+                    ip_address=pending_dl.ip_address,
+                    hits=0,
+                    average_score=0.0,
+                    total_votes=0,
+                    is_public=True)
+            dl.save()
+
+            # If we don't do this, the actual file will be deleted when
+            # the pending download is deleted.
+            pending_dl.file = None
+            pending_dl.delete()
+
+    approve_downloads.short_description = "Approve selected downloads"
+
+
 class DownloadAdmin(admin.ModelAdmin):
     exclude = ('html', )
     list_display = ('title', 'user', 'category', 'date_added', 'ip_address',
@@ -33,6 +69,7 @@
     date_hierarchy = 'vote_date'
 
 
+admin.site.register(PendingDownload, PendingDownloadAdmin)
 admin.site.register(Download, DownloadAdmin)
 admin.site.register(Category, CategoryAdmin)
 admin.site.register(AllowedExtension)