changeset 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 2c4f28b1c12a
children 704b47356a49
files bandmap/admin.py bio/badges.py
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
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)
--- 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):