annotate gpp/gcalendar/admin_views.py @ 286:72fd300685d5

For #95. You can now make posts with no text in the body if you have attachments. And now if you create a new topic with an attachment, and the POST fails (say you forgot the topic title), we will now re-attach attachments. Also fixed a bug in the smiley code that would arise if it was asked to markup an empty string.
author Brian Neal <bgneal@gmail.com>
date Sat, 23 Oct 2010 20:19:46 +0000
parents 9fb8e804652b
children
rev   line source
gremmie@1 1 """
gremmie@1 2 Admin views for the gcalendar application.
gremmie@1 3 """
gremmie@1 4 from django.shortcuts import render_to_response
gremmie@1 5 from django.template import RequestContext
gremmie@1 6
gremmie@1 7 from gcalendar.models import Event
gremmie@1 8 from gcalendar.forms import PasswordForm
gremmie@1 9 from gcalendar.calendar import Calendar
gremmie@1 10 from gcalendar.calendar import CalendarError
gremmie@1 11 import gcalendar.settings
gremmie@1 12
gremmie@1 13
gremmie@1 14 def google_sync(request):
gremmie@1 15 """View to synchronize approved event changes with Google calendar."""
gremmie@1 16 events = Event.pending_events.all()
gremmie@1 17 messages = []
bgneal@69 18 err_msg = ''
gremmie@1 19 if request.method == 'POST':
gremmie@1 20 form = PasswordForm(request.POST)
gremmie@1 21 if form.is_valid():
gremmie@1 22 try:
gremmie@1 23 cal = Calendar(gcalendar.settings.EMAIL,
gremmie@1 24 form.cleaned_data['password'],
gremmie@1 25 gcalendar.settings.CALENDAR_ID)
gremmie@1 26 cal.sync_events(events)
gremmie@1 27 except CalendarError, e:
bgneal@69 28 err_msg = e.msg
gremmie@1 29 events = Event.pending_events.all()
gremmie@1 30 form = PasswordForm()
gremmie@1 31 else:
gremmie@1 32 messages.append('All events processed successfully.')
gremmie@1 33 events = Event.objects.none()
gremmie@1 34 form = PasswordForm()
gremmie@1 35
gremmie@1 36 else:
gremmie@1 37 form = PasswordForm()
gremmie@1 38
gremmie@1 39 return render_to_response('gcalendar/google_sync.html', {
gremmie@1 40 'messages': messages,
bgneal@69 41 'err_msg': err_msg,
gremmie@1 42 'events': events,
gremmie@1 43 'form': form,
gremmie@1 44 },
gremmie@1 45 context_instance=RequestContext(request))
gremmie@1 46