def vote_all(request): sunetid = request.user.webauth_username # protect against XSS form = None ballot = get_object_or_404(Ballot, voter_id=get_voter_id(request)) if request.method == 'POST': ballotform = ballot_form_factory(ballot)(request.POST, instance=ballot) if ballotform.is_valid(): record = VoteRecord() record.sunetid = sunetid if 'HTTP_X_FORWARDED_FOR' in request.META: record.ip = request.META['HTTP_X_FORWARDED_FOR'] else: record.ip = request.META['REMOTE_ADDR'] record.datetime = datetime.now() record.type = "success-vote" record.save() ballotform.save() vrecord = render_to_string('ballot/ballot_record.txt', {'ballot': ballot, 'request': request, 'form': form, 'sunetid': sunetid}) f = open(settings.BALLOT_ROOT + '/%s-%d' % (sunetid,record.pk), 'w') f.write(vrecord.encode('utf8')) f.close() else: record = VoteRecord() record.sunetid = sunetid if 'HTTP_X_FORWARDED_FOR' in request.META: record.ip = request.META['HTTP_X_FORWARDED_FOR'] else: record.ip = request.META['REMOTE_ADDR'] record.datetime = datetime.now() record.type = "failed-vote" record.details = str(ballotform.errors) record.save() return render_to_response('ballot/ballot.html', {'ballotform': ballotform, 'ballot': ballot, 'cp_slates': get_cp_slates(ballot), 'csac_members': get_csac_members(), 'exec_slates': get_exec_slates(),'is_submitted': True, 'sunetid': sunetid}, context_instance=RequestContext(request)) #WebauthLogout(request) # not necessary. return render_to_response('ballot/done.html', {'sunetid': sunetid, 'ballot': ballot, 'request': request,}, context_instance=RequestContext(request))
def index(request): sunetid = request.user.webauth_username ballot, c = Ballot.get_or_create_by_sunetid(sunetid) if ballot.needs_ballot_choice(): return HttpResponseRedirect('/ballot/choose') ballotform = ballot_form_factory(ballot)(instance=ballot) record = VoteRecord() record.sunetid = sunetid if 'HTTP_X_FORWARDED_FOR' in request.META: record.ip = request.META['HTTP_X_FORWARDED_FOR'] else: record.ip = request.META['REMOTE_ADDR'] record.datetime = datetime.now() record.type = "start" record.save() return render_to_response('ballot/ballot.html', {'ballotform': ballotform, 'ballot': ballot, 'cp_slates': get_cp_slates(ballot), 'csac_members': get_csac_members(), 'exec_slates': get_exec_slates(),'sunetid': sunetid}, context_instance=RequestContext(request))
def choose_ballot(request): sunetid = request.user.webauth_username ballot = get_object_or_404(Ballot, voter_id=get_voter_id(request)) form = None if request.method == 'POST': form = BallotElectorateForm(request.POST, instance=ballot) if form.is_valid(): form.save() record = VoteRecord() record.sunetid = sunetid if 'HTTP_X_FORWARDED_FOR' in request.META: record.ip = request.META['HTTP_X_FORWARDED_FOR'] else: record.ip = request.META['REMOTE_ADDR'] record.datetime = datetime.now() record.type = "choose" record.details = "chose " + ballot.get_electorate_slugs() record.save() return HttpResponseRedirect('/ballot/') else: form = BallotElectorateForm(instance=ballot) return render_to_response('ballot/choose.html', {'form': form, 'ballot': ballot}, context_instance=RequestContext(request))