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