gremmie@1: """ gremmie@1: This file contains the automatic admin site definitions for the gcalendar application. gremmie@1: """ gremmie@1: from django.contrib import admin gremmie@1: from django.http import HttpResponse gremmie@1: from django.conf.urls.defaults import * gremmie@1: gremmie@1: from gcalendar.models import Event gremmie@1: from gcalendar.admin_views import google_sync bgneal@204: import bio.badges gremmie@1: gremmie@1: gremmie@1: class EventAdmin(admin.ModelAdmin): gremmie@1: list_display = ('what', 'user', 'start_date', 'where', 'date_submitted', bgneal@139: 'status', 'is_approved') gremmie@1: list_filter = ('start_date', 'status') bgneal@152: date_hierarchy = 'start_date' gremmie@1: search_fields = ('what', 'where', 'description') gremmie@1: raw_id_fields = ('user', ) gremmie@1: exclude = ('html', 'google_id') gremmie@1: save_on_top = True bgneal@152: actions = ('approve_events', ) bgneal@152: bgneal@152: pending_states = { bgneal@152: Event.NEW: Event.NEW_APRV, bgneal@152: Event.EDIT_REQ: Event.EDIT_APRV, bgneal@152: Event.DEL_REQ: Event.DEL_APRV, bgneal@152: } gremmie@1: gremmie@1: def get_urls(self): gremmie@1: urls = super(EventAdmin, self).get_urls() gremmie@1: my_urls = patterns('', gremmie@1: url(r'^google_sync/$', gremmie@1: self.admin_site.admin_view(google_sync), gremmie@1: name="gcalendar-google_sync") gremmie@1: ) gremmie@1: return my_urls + urls gremmie@1: bgneal@152: def approve_events(self, request, qs): bgneal@152: """ bgneal@152: Ratchets the selected events forward to the approved state. bgneal@152: Ignores events that aren't in the proper state. bgneal@152: """ bgneal@152: for event in qs: bgneal@152: count = 0 bgneal@152: if event.status in self.pending_states: bgneal@152: event.status = self.pending_states[event.status] bgneal@152: event.save() bgneal@152: count += 1 bgneal@152: bgneal@204: if event.status == Event.NEW_APRV: bgneal@204: bio.badges.award_badge(bio.badges.CALENDAR_PIN, event.user) bgneal@204: bgneal@152: msg = "1 event was" if count == 1 else "%d events were" % count bgneal@152: msg += " approved." bgneal@152: self.message_user(request, msg) bgneal@152: bgneal@152: approve_events.short_description = "Approve selected events" bgneal@152: gremmie@1: gremmie@1: admin.site.register(Event, EventAdmin) gremmie@1: