comparison gpp/gcalendar/admin_views.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children 9fb8e804652b
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """
2 Admin views for the gcalendar application.
3 """
4 from django.shortcuts import render_to_response
5 from django.template import RequestContext
6
7 from gcalendar.models import Event
8 from gcalendar.forms import PasswordForm
9 from gcalendar.calendar import Calendar
10 from gcalendar.calendar import CalendarError
11 import gcalendar.settings
12
13
14 def google_sync(request):
15 """View to synchronize approved event changes with Google calendar."""
16 events = Event.pending_events.all()
17 messages = []
18 errors = []
19 if request.method == 'POST':
20 form = PasswordForm(request.POST)
21 if form.is_valid():
22 try:
23 cal = Calendar(gcalendar.settings.EMAIL,
24 form.cleaned_data['password'],
25 gcalendar.settings.CALENDAR_ID)
26 cal.sync_events(events)
27 except CalendarError, e:
28 errors = e.errs
29 events = Event.pending_events.all()
30 form = PasswordForm()
31 else:
32 messages.append('All events processed successfully.')
33 events = Event.objects.none()
34 form = PasswordForm()
35
36 else:
37 form = PasswordForm()
38
39 return render_to_response('gcalendar/google_sync.html', {
40 'messages': messages,
41 'errors': errors,
42 'events': events,
43 'form': form,
44 },
45 context_instance=RequestContext(request))
46
47 # vim: ts=4 sw=4