Exemple #1
0
def start_voting(request, discussion_pk):
    if request.POST and discussion_pk:
        discussion = Discussion.objects.get(id=discussion_pk)
        # check if there's a vote in progress
        if Voting.objects.get_started(discussion=discussion):
            return HttpResponseServerError(_("Hold it, there is a vote in progress."))
        voting_form = VotingForm(request.POST)
        if voting_form.is_valid():
            voting = open_voting_from_data(request.user, discussion, voting_form.cleaned_data)
        else:
            return HttpResponseServerError(voting_form.as_p())
        return HttpResponse(
            '{"ballots":%d,"time_left":"%s"}' % (voting.votes_per_participant, voting.end_time - voting.start_time)
        )
    else:
        return HttpResponseServerError(_("Bad usage. Need post params with a discussion's pk."))
Exemple #2
0
def get_voting_form(request, discussion_pk):
    # check if there's a vote in progress
    if Voting.objects.get_started(discussion=discussion_pk):
        return HttpResponseServerError(_('{"VOTE_STARTED":"Hold it, there is a vote in progress."}'))
    voting_form = VotingForm()
    return HttpResponse(voting_form.as_p())