annotate gpp/gcalendar/admin.py @ 301:ee451ad46af1

Fixing #140; limit topic notification emails to at most 1 per day, or more if the user visits the topic.
author Brian Neal <bgneal@gmail.com>
date Thu, 13 Jan 2011 03:27:42 +0000
parents d77e0dc772ad
children 3fa61786abf1
rev   line source
gremmie@1 1 """
gremmie@1 2 This file contains the automatic admin site definitions for the gcalendar application.
gremmie@1 3 """
gremmie@1 4 from django.contrib import admin
gremmie@1 5 from django.http import HttpResponse
gremmie@1 6 from django.conf.urls.defaults import *
gremmie@1 7
gremmie@1 8 from gcalendar.models import Event
gremmie@1 9 from gcalendar.admin_views import google_sync
bgneal@204 10 import bio.badges
gremmie@1 11
gremmie@1 12
gremmie@1 13 class EventAdmin(admin.ModelAdmin):
gremmie@1 14 list_display = ('what', 'user', 'start_date', 'where', 'date_submitted',
bgneal@228 15 'status', 'is_approved', 'google_html')
gremmie@1 16 list_filter = ('start_date', 'status')
bgneal@152 17 date_hierarchy = 'start_date'
gremmie@1 18 search_fields = ('what', 'where', 'description')
gremmie@1 19 raw_id_fields = ('user', )
bgneal@228 20 exclude = ('html', 'google_id', 'google_url')
gremmie@1 21 save_on_top = True
bgneal@152 22 actions = ('approve_events', )
bgneal@152 23
bgneal@152 24 pending_states = {
bgneal@152 25 Event.NEW: Event.NEW_APRV,
bgneal@152 26 Event.EDIT_REQ: Event.EDIT_APRV,
bgneal@152 27 Event.DEL_REQ: Event.DEL_APRV,
bgneal@152 28 }
gremmie@1 29
gremmie@1 30 def get_urls(self):
gremmie@1 31 urls = super(EventAdmin, self).get_urls()
gremmie@1 32 my_urls = patterns('',
gremmie@1 33 url(r'^google_sync/$',
gremmie@1 34 self.admin_site.admin_view(google_sync),
gremmie@1 35 name="gcalendar-google_sync")
gremmie@1 36 )
gremmie@1 37 return my_urls + urls
gremmie@1 38
bgneal@152 39 def approve_events(self, request, qs):
bgneal@152 40 """
bgneal@152 41 Ratchets the selected events forward to the approved state.
bgneal@152 42 Ignores events that aren't in the proper state.
bgneal@152 43 """
bgneal@152 44 for event in qs:
bgneal@152 45 count = 0
bgneal@152 46 if event.status in self.pending_states:
bgneal@152 47 event.status = self.pending_states[event.status]
bgneal@152 48 event.save()
bgneal@152 49 count += 1
bgneal@152 50
bgneal@204 51 if event.status == Event.NEW_APRV:
bgneal@204 52 bio.badges.award_badge(bio.badges.CALENDAR_PIN, event.user)
bgneal@204 53
bgneal@152 54 msg = "1 event was" if count == 1 else "%d events were" % count
bgneal@152 55 msg += " approved."
bgneal@152 56 self.message_user(request, msg)
bgneal@152 57
bgneal@152 58 approve_events.short_description = "Approve selected events"
bgneal@152 59
gremmie@1 60
gremmie@1 61 admin.site.register(Event, EventAdmin)
gremmie@1 62