changeset 152:bc657962941e

Implement #42; add admin actions to GCalendar.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Dec 2009 04:59:06 +0000
parents e1d1a70d312d
children 13d052fbe4f1
files gpp/gcalendar/admin.py
diffstat 1 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/gcalendar/admin.py	Fri Dec 18 04:30:49 2009 +0000
+++ b/gpp/gcalendar/admin.py	Sat Dec 19 04:59:06 2009 +0000
@@ -13,10 +13,18 @@
     list_display = ('what', 'user', 'start_date', 'where', 'date_submitted',
             'status', 'is_approved')
     list_filter = ('start_date', 'status')
+    date_hierarchy = 'start_date'
     search_fields = ('what', 'where', 'description')
     raw_id_fields = ('user', )
     exclude = ('html', 'google_id')
     save_on_top = True
+    actions = ('approve_events', )
+
+    pending_states = {
+        Event.NEW: Event.NEW_APRV,
+        Event.EDIT_REQ: Event.EDIT_APRV,
+        Event.DEL_REQ: Event.DEL_APRV,
+    }
 
     def get_urls(self):
         urls = super(EventAdmin, self).get_urls()
@@ -27,7 +35,24 @@
         )
         return my_urls + urls
 
+    def approve_events(self, request, qs):
+        """
+        Ratchets the selected events forward to the approved state.
+        Ignores events that aren't in the proper state.
+        """
+        for event in qs:
+            count = 0
+            if event.status in self.pending_states:
+                event.status = self.pending_states[event.status]
+                event.save()
+                count += 1
+
+        msg = "1 event was" if count == 1 else "%d events were" % count
+        msg += " approved."
+        self.message_user(request, msg)
+
+    approve_events.short_description = "Approve selected events"
+
 
 admin.site.register(Event, EventAdmin)
 
-# vim: ts=4 sw=4