def test_calendar_process_form(self): '''this function tests the process form function... just make sure it gets the right stuff from an object with the same contents as the one we're dealing with''' this_form = self.Form() calendar_name, requestor_1, requestor_2 = calendar_process_form(this_form) assert (calendar_name == 'some_cal_name') assert (requestor_1 == 'some_cal_user') assert (requestor_2 == 'other_cal_user')
def index(request): '''this is the index method, it serves and handles the calendar creation owner addition functionality''' #check for correct permission if not request.user.has_perm('mysite.psu_gcal'): return render_to_response('invalid.html') else: #check if form submitted if not request.method == 'POST': #if the user wants the calendar form if request.path == '/calendar_form/': calendar_form = CalendarForm() template = loader.get_template("calendar_form.html") context = Context() return render_to_response('calendar_form.html', {'calendar_form': calendar_form}, context_instance=RequestContext(request)) #if the user wants the group form elif request.path == '/group_form/': group_form = GroupForm() template = loader.get_template("group_form.html") context = Context() return render_to_response('group_form.html', {'group_form': group_form}, context_instance=RequestContext(request)) #no more alias form... handled with the other alias create scripts #alias_form = AliasForm() #the generic case else: template = loader.get_template( 'index.html' ) context = Context() return render_to_response( 'index.html', {}, context_instance=RequestContext(request) ) #if it's the calendar form that they submitted elif (u'calendar_name' in request.POST.keys()): form = CalendarForm( request.POST ) #check if form valid if not form.is_valid(): return HttpResponse("form not valid...") #handle form submission else: calendar_name, calendar_requestor_1, calendar_requestor_2 = \ calendar_process_form(form) print 'calendar_name: {0}'.format(calendar_name)#debug print 'calendar_requestor_1: {0}'.format(calendar_requestor_1)#debug print 'calendar_requestor_2: {0}'.format(calendar_requestor_2)#debug try: #client = CalendarResource( google.keys()[0] ) client = CalendarResource(domain=calendar.keys()[0],adminuser=calendar[calendar.keys()[0]]['adminuser'],password=calendar[calendar.keys()[0]]['password']) print 'client: {0}'.format(client)#debug #print str(client) #debug try: calendar_already_exists, success, acl = \ calendar_validate( calendar_name, client ) __logger__.info('calendar_already_exists: '+str(calendar_already_exists)+'\nsuccess: '+str(success)+'\nclient: '+str(client)) #debug except Exception, err: __logger__.info('err: '+str(err)) #debug #create success message response = process_calendar( calendar_name, calendar_already_exists, success ) __logger__.info('response: '+response) #debug if calendar_requestor_1: if requestor_validate( calendar_requestor_1, client ): requestor_1_already_owner = calendar_already_owner( calendar_requestor_1, acl, client ) response += calendar_process_requestor( calendar_requestor_1, calendar_name, requestor_1_already_owner, client ) else: response += '\n<br/>' + calendar_requestor_1 + \ ' is not a valid user' if calendar_requestor_2: if requestor_validate( calendar_requestor_2, client ): requestor_2_already_owner = calendar_already_owner( calendar_requestor_2, acl, client ) response += calendar_process_requestor( calendar_requestor_2, calendar_name, requestor_2_already_owner, client ) else: response += '\n<br/>' + calendar_requestor_2 + \ ' is not a valid user' __logger__.info('user: '******' has made the following request:\n' + str(response) + \ '\n') #return HttpResponse( response ) template = loader.get_template("success.html") context = Context() return render_to_response('success.html', {'success_msg': response}, context_instance=RequestContext(request)) except Exception, err: response = str(err) response += '\n<br/>calendar name: ' + str(calendar_name) response += '\n<br/>requestor_1: ' + str(calendar_requestor_1) response += '\n<br/>requestor_2: ' + str(calendar_requestor_2) template = loader.get_template("success.html") context = Context() return render_to_response('success.html', {'success_msg': response}, context_instance=RequestContext(request))