cmsplugin-poll / cmsplugin_poll /

# -*- coding: utf-8 -*-

from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from models import Poll, Choice
from django.utils import simplejson
from django.http import HttpResponse
from django.core import serializers

def index(request):
    polls = Poll.objects.iterator()
    c = RequestContext(request, {'polls': polls})
    return render_to_response('cmsplugin_poll/latest_polls.html', c)

def detail(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    c = RequestContext(request, {'poll': poll})
    return render_to_response('cmsplugin_poll/detail.html', c)

def vote(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    if poll.close_date is not None:
        messages.error(request, _("This poll is closed"))
    elif request.session.get("poll_%d" %, False):
        messages.error(request, _("You already vote for this poll"))
            selected_choice = poll.choice_set.get(pk=request.POST['choice'])
        except (KeyError, Choice.DoesNotExist):
            messages.error(request, _("You didn't select a choice"))
            selected_choice.votes += 1
  , _("Thank you for your vote"))
            request.session["poll_%d" %] = True
    url = request.POST.get('next', poll.get_absolute_url())
    return HttpResponseRedirect(url)

def results(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    c = RequestContext(request, {'poll': poll})
    return render_to_response('cmsplugin_poll/results.html', c)

def results_json(request, poll_id):
    polls = Poll.objects.filter(pk=poll_id)
    polls_data = serializers.serialize("json", polls)

    choices = Choice.objects.filter(poll=poll_id)
    choices_data = serializers.serialize("json", choices)

    data = {'poll': polls_data, 'choices': choices_data}
    return HttpResponse(simplejson.dumps(data), mimetype="application/json")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.