# HG changeset patch
# User Brian Neal <bgneal@gmail.com>
# Date 1411607345 18000
# Node ID 5892c05886a94c5c10f6df6bc025ba576aacdd2c
# Parent  2c4f28b1c12a6e9e8b3d07b9e2d41f1acccc609f
Band map WIP: add approve new band map entries in admin.

diff -r 2c4f28b1c12a -r 5892c05886a9 bandmap/admin.py
--- 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)
diff -r 2c4f28b1c12a -r 5892c05886a9 bio/badges.py
--- a/bio/badges.py	Wed Sep 24 19:53:36 2014 -0500
+++ b/bio/badges.py	Wed Sep 24 20:09:05 2014 -0500
@@ -7,7 +7,7 @@
 
 # Numeric ID's for badges that are awarded for user actions:
 (CONTRIBUTOR_PIN, CALENDAR_PIN, NEWS_PIN, LINK_PIN, DOWNLOAD_PIN,
-        SECURITY_PIN, POTD_PIN) = range(7)
+        SECURITY_PIN, POTD_PIN, MAP_PIN) = range(8)
 
 
 def award_badge(badge_id, user):