annotate gpp/gcalendar/admin.py @ 159:416353def4ca

Added a new posts template tag for the home page.
author Brian Neal <bgneal@gmail.com>
date Sun, 20 Dec 2009 20:42:19 +0000
parents bc657962941e
children b4305e18d3af
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
gremmie@1 10
gremmie@1 11
gremmie@1 12 class EventAdmin(admin.ModelAdmin):
gremmie@1 13 list_display = ('what', 'user', 'start_date', 'where', 'date_submitted',
bgneal@139 14 'status', 'is_approved')
gremmie@1 15 list_filter = ('start_date', 'status')
bgneal@152 16 date_hierarchy = 'start_date'
gremmie@1 17 search_fields = ('what', 'where', 'description')
gremmie@1 18 raw_id_fields = ('user', )
gremmie@1 19 exclude = ('html', 'google_id')
gremmie@1 20 save_on_top = True
bgneal@152 21 actions = ('approve_events', )
bgneal@152 22
bgneal@152 23 pending_states = {
bgneal@152 24 Event.NEW: Event.NEW_APRV,
bgneal@152 25 Event.EDIT_REQ: Event.EDIT_APRV,
bgneal@152 26 Event.DEL_REQ: Event.DEL_APRV,
bgneal@152 27 }
gremmie@1 28
gremmie@1 29 def get_urls(self):
gremmie@1 30 urls = super(EventAdmin, self).get_urls()
gremmie@1 31 my_urls = patterns('',
gremmie@1 32 url(r'^google_sync/$',
gremmie@1 33 self.admin_site.admin_view(google_sync),
gremmie@1 34 name="gcalendar-google_sync")
gremmie@1 35 )
gremmie@1 36 return my_urls + urls
gremmie@1 37
bgneal@152 38 def approve_events(self, request, qs):
bgneal@152 39 """
bgneal@152 40 Ratchets the selected events forward to the approved state.
bgneal@152 41 Ignores events that aren't in the proper state.
bgneal@152 42 """
bgneal@152 43 for event in qs:
bgneal@152 44 count = 0
bgneal@152 45 if event.status in self.pending_states:
bgneal@152 46 event.status = self.pending_states[event.status]
bgneal@152 47 event.save()
bgneal@152 48 count += 1
bgneal@152 49
bgneal@152 50 msg = "1 event was" if count == 1 else "%d events were" % count
bgneal@152 51 msg += " approved."
bgneal@152 52 self.message_user(request, msg)
bgneal@152 53
bgneal@152 54 approve_events.short_description = "Approve selected events"
bgneal@152 55
gremmie@1 56
gremmie@1 57 admin.site.register(Event, EventAdmin)
gremmie@1 58