diff bandmap/admin.py @ 823:5892c05886a9

Band map WIP: add approve new band map entries in admin.
author Brian Neal <bgneal@gmail.com>
date Wed, 24 Sep 2014 20:09:05 -0500
parents 9a0df7bd2409
children d7e4c08b2e8b
line wrap: on
line diff
--- a/bandmap/admin.py	Wed Sep 24 19:53:36 2014 -0500
+++ b/bandmap/admin.py	Wed Sep 24 20:09:05 2014 -0500
@@ -1,9 +1,12 @@
 """Admin definitions for the bandmap application.
 
 """
+import datetime
+
 from django.contrib import admin
 
 from bandmap.models import BandEntry
+import bio.badges
 
 
 class BandEntryAdmin(admin.ModelAdmin):
@@ -14,5 +17,24 @@
     readonly_fields = ['lat', 'lon']
     search_fields = ['name', 'location', 'note']
     raw_id_fields = ['user']
+    actions = ['approve_bands']
+
+    def approve_bands(self, request, qs):
+        """This admin action awards a map pin to the user who added the band.
+        The band is then published and will be available for display on the map.
+
+        """
+        count = qs.count()
+        now = datetime.datetime.now()
+        for band in qs:
+            bio.badges.award_badge(bio.badges.MAP_PIN, band.user)
+            band.date_approved = now
+            band.is_approved = True
+            band.save()
+
+        self.message_user(request, "%d band(s) approved." % count)
+
+    approve_bands.short_description = "Approve selected band map entries"
+
 
 admin.site.register(BandEntry, BandEntryAdmin)