comparison 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
comparison
equal deleted inserted replaced
822:2c4f28b1c12a 823:5892c05886a9
1 """Admin definitions for the bandmap application. 1 """Admin definitions for the bandmap application.
2 2
3 """ 3 """
4 import datetime
5
4 from django.contrib import admin 6 from django.contrib import admin
5 7
6 from bandmap.models import BandEntry 8 from bandmap.models import BandEntry
9 import bio.badges
7 10
8 11
9 class BandEntryAdmin(admin.ModelAdmin): 12 class BandEntryAdmin(admin.ModelAdmin):
10 list_display = ['name', 'date_submitted', 'date_approved', 'is_active', 13 list_display = ['name', 'date_submitted', 'date_approved', 'is_active',
11 'is_approved'] 14 'is_approved']
12 date_hierarchy = 'date_submitted' 15 date_hierarchy = 'date_submitted'
13 list_filter = ['date_submitted', 'is_active', 'is_approved'] 16 list_filter = ['date_submitted', 'is_active', 'is_approved']
14 readonly_fields = ['lat', 'lon'] 17 readonly_fields = ['lat', 'lon']
15 search_fields = ['name', 'location', 'note'] 18 search_fields = ['name', 'location', 'note']
16 raw_id_fields = ['user'] 19 raw_id_fields = ['user']
20 actions = ['approve_bands']
21
22 def approve_bands(self, request, qs):
23 """This admin action awards a map pin to the user who added the band.
24 The band is then published and will be available for display on the map.
25
26 """
27 count = qs.count()
28 now = datetime.datetime.now()
29 for band in qs:
30 bio.badges.award_badge(bio.badges.MAP_PIN, band.user)
31 band.date_approved = now
32 band.is_approved = True
33 band.save()
34
35 self.message_user(request, "%d band(s) approved." % count)
36
37 approve_bands.short_description = "Approve selected band map entries"
38
17 39
18 admin.site.register(BandEntry, BandEntryAdmin) 40 admin.site.register(BandEntry, BandEntryAdmin)