Mercurial > public > sg101
comparison gpp/gcalendar/admin.py @ 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 | e04d91babfcf |
children | b4305e18d3af |
comparison
equal
deleted
inserted
replaced
151:e1d1a70d312d | 152:bc657962941e |
---|---|
11 | 11 |
12 class EventAdmin(admin.ModelAdmin): | 12 class EventAdmin(admin.ModelAdmin): |
13 list_display = ('what', 'user', 'start_date', 'where', 'date_submitted', | 13 list_display = ('what', 'user', 'start_date', 'where', 'date_submitted', |
14 'status', 'is_approved') | 14 'status', 'is_approved') |
15 list_filter = ('start_date', 'status') | 15 list_filter = ('start_date', 'status') |
16 date_hierarchy = 'start_date' | |
16 search_fields = ('what', 'where', 'description') | 17 search_fields = ('what', 'where', 'description') |
17 raw_id_fields = ('user', ) | 18 raw_id_fields = ('user', ) |
18 exclude = ('html', 'google_id') | 19 exclude = ('html', 'google_id') |
19 save_on_top = True | 20 save_on_top = True |
21 actions = ('approve_events', ) | |
22 | |
23 pending_states = { | |
24 Event.NEW: Event.NEW_APRV, | |
25 Event.EDIT_REQ: Event.EDIT_APRV, | |
26 Event.DEL_REQ: Event.DEL_APRV, | |
27 } | |
20 | 28 |
21 def get_urls(self): | 29 def get_urls(self): |
22 urls = super(EventAdmin, self).get_urls() | 30 urls = super(EventAdmin, self).get_urls() |
23 my_urls = patterns('', | 31 my_urls = patterns('', |
24 url(r'^google_sync/$', | 32 url(r'^google_sync/$', |
25 self.admin_site.admin_view(google_sync), | 33 self.admin_site.admin_view(google_sync), |
26 name="gcalendar-google_sync") | 34 name="gcalendar-google_sync") |
27 ) | 35 ) |
28 return my_urls + urls | 36 return my_urls + urls |
29 | 37 |
38 def approve_events(self, request, qs): | |
39 """ | |
40 Ratchets the selected events forward to the approved state. | |
41 Ignores events that aren't in the proper state. | |
42 """ | |
43 for event in qs: | |
44 count = 0 | |
45 if event.status in self.pending_states: | |
46 event.status = self.pending_states[event.status] | |
47 event.save() | |
48 count += 1 | |
49 | |
50 msg = "1 event was" if count == 1 else "%d events were" % count | |
51 msg += " approved." | |
52 self.message_user(request, msg) | |
53 | |
54 approve_events.short_description = "Approve selected events" | |
55 | |
30 | 56 |
31 admin.site.register(Event, EventAdmin) | 57 admin.site.register(Event, EventAdmin) |
32 | 58 |
33 # vim: ts=4 sw=4 |