gremmie@1: """ gremmie@1: Admin views for the gcalendar application. gremmie@1: """ gremmie@1: from django.shortcuts import render_to_response gremmie@1: from django.template import RequestContext gremmie@1: gremmie@1: from gcalendar.models import Event gremmie@1: from gcalendar.forms import PasswordForm gremmie@1: from gcalendar.calendar import Calendar gremmie@1: from gcalendar.calendar import CalendarError gremmie@1: import gcalendar.settings gremmie@1: gremmie@1: gremmie@1: def google_sync(request): gremmie@1: """View to synchronize approved event changes with Google calendar.""" gremmie@1: events = Event.pending_events.all() gremmie@1: messages = [] gremmie@1: errors = [] gremmie@1: if request.method == 'POST': gremmie@1: form = PasswordForm(request.POST) gremmie@1: if form.is_valid(): gremmie@1: try: gremmie@1: cal = Calendar(gcalendar.settings.EMAIL, gremmie@1: form.cleaned_data['password'], gremmie@1: gcalendar.settings.CALENDAR_ID) gremmie@1: cal.sync_events(events) gremmie@1: except CalendarError, e: gremmie@1: errors = e.errs gremmie@1: events = Event.pending_events.all() gremmie@1: form = PasswordForm() gremmie@1: else: gremmie@1: messages.append('All events processed successfully.') gremmie@1: events = Event.objects.none() gremmie@1: form = PasswordForm() gremmie@1: gremmie@1: else: gremmie@1: form = PasswordForm() gremmie@1: gremmie@1: return render_to_response('gcalendar/google_sync.html', { gremmie@1: 'messages': messages, gremmie@1: 'errors': errors, gremmie@1: 'events': events, gremmie@1: 'form': form, gremmie@1: }, gremmie@1: context_instance=RequestContext(request)) gremmie@1: gremmie@1: # vim: ts=4 sw=4