def do_confirm_ok(self, candidate_id): caller_id = models.caller_id_if_valid(self.call_id()) models.record_vote(caller_id, candidate_id) t = Tropo() t.say("Great, your vote has been counted. Goodbye.") t.message("Thanks for voting! Tropo <3 you!", channel="TEXT", to=caller_id) return t.RenderJson()
def do_text(self): caller_id = models.caller_id_if_valid(self.call_id()) if models.caller_id_can_vote(caller_id): session_info = json.loads(web.data())['session'] msg = session_info['initialText'] m = re.match("^(v|V|vote|VOTE)\s+([0-9]{2})$", msg) if m: vote_code = m.groups()[1] candidate = models.find_candidate_by_code(vote_code) if candidate: models.record_vote(caller_id, candidate['id']) t = Tropo() t.message( "You have voted for %s as most disruptive startup. Thanks for voting! Tropo <3s you!" % candidate['name'], to=caller_id, channel='TEXT') return t.RenderJson() else: return self.do_help_text("Sorry, there's no candidate %s. " % vote_code) else: return self.do_help_text("Sorry, we didn't understand your text message. ") elif not caller_id: return self.do_help_text("You need to have caller ID enabled to vote.") else: t = Tropo() t.message("Oops, it looks like you have voted already.", to=caller_id, channel='TEXT') return t.RenderJson()
def post(request, pk): poll = get_object_or_404(Poll, pk = pk) tag = request.POST.get('msg_id', 'polls') if not poll.approved: messages.error(request, 'Anketa nie je schválená.', extra_tags = tag) return HttpResponseRedirect(request.POST['next']) if not 'choice' in request.POST: messages.error(request, 'Vyberte prosím odpoveď.', extra_tags = tag) return HttpResponseRedirect(request.POST['next']) if not poll.checkbox: choices = [int(request.POST['choice'])] if poll.checkbox: choices = [int(choice) for choice in request.POST.getlist('choice')] if len(choices) == 0: messages.error(request, 'Vyberte prosím odpoveď.', extra_tags = tag) return HttpResponseRedirect(request.POST['next']) if not check_can_vote(request, poll): messages.error(request, 'Hlasovať je možné len raz.', extra_tags = tag) return HttpResponseRedirect(request.POST['next']) choice_objects = poll.choice_set.order_by('pk').values_list('pk', flat = True) update_choice_objects = [] for choice in choices: update_choice_objects.append(choice_objects[choice]) Poll.objects.filter(pk = poll.pk).update(choice_count = F('choice_count') + 1) poll.choice_set.filter(pk__in = update_choice_objects).update(votes = F('votes') + 1) record_vote(request, poll) messages.success(request, 'Hlas bol prijatý.', extra_tags = tag) return HttpResponseRedirect(request.POST['next'])