From 77b11d8edf74b5d7a4ba1f609048c4b6666546e0 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 15 Feb 2012 10:46:55 +0100 Subject: [PATCH] forgot to add some files --- openslides/poll/templates/poll/poll.html | 29 +++++++++++++++++ openslides/poll/views.py | 40 ++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 openslides/poll/templates/poll/poll.html create mode 100644 openslides/poll/views.py diff --git a/openslides/poll/templates/poll/poll.html b/openslides/poll/templates/poll/poll.html new file mode 100644 index 000000000..129d8d859 --- /dev/null +++ b/openslides/poll/templates/poll/poll.html @@ -0,0 +1,29 @@ +{% extends 'base.html' %} + +{% block content %} +
{% csrf_token %} + + + + {% for value in poll.get_vote_values %} + + {% endfor %} + + {% for form in forms %} + + + {% for value in form %} + + {% endfor %} + + {% endfor %} +
Option{{ value }}
{{ form.option }} + {{ value.errors }} + {{ value }} +
+ +

+
+{% endblock %} diff --git a/openslides/poll/views.py b/openslides/poll/views.py new file mode 100644 index 000000000..ac6d8352b --- /dev/null +++ b/openslides/poll/views.py @@ -0,0 +1,40 @@ +from django.views.generic import TemplateView +from django.http import HttpResponseRedirect + +class PollFormView(TemplateView): + template_name = 'poll/poll.html' + poll_argument = 'poll_id' + + def set_poll(self, poll_id): + poll_id = poll_id + self.poll = self.poll_class.objects.get(pk=poll_id) + self.poll.vote_values = self.vote_values + + def get_context_data(self, **kwargs): + context = super(PollFormView, self).get_context_data(**kwargs) + self.set_poll(self.kwargs['poll_id']) + context['poll'] = self.poll + if not 'forms' in context: + context['forms'] = context['poll'].get_vote_forms() + return context + + def get_success_url(self): + return self.success_url + + def post(self, request, *args, **kwargs): + context = self.get_context_data(**kwargs) + forms = self.poll.get_vote_forms(data=self.request.POST) + error = False + for form in forms: + if not form.is_valid(): + error = True + if error: + return self.render_to_response(self.get_context_data(forms=forms)) + + for form in forms: + data = {} + for value in self.poll.vote_values: + data[value] = form.cleaned_data[value] + print data + self.poll.set_form_values(form.option, data) + return HttpResponseRedirect(self.get_success_url())