From 9c367509ddfd8a5832e203b3373d79282dc7f372 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 15 Feb 2012 10:43:08 +0100 Subject: [PATCH] reorder poll --- openslides/application/views.py | 2 +- openslides/poll/__init__.py | 3 +- openslides/poll/admin.py | 17 ---------- openslides/poll/forms.py | 58 ++++++++------------------------- openslides/poll/models.py | 55 ------------------------------- openslides/poll/tests.py | 28 ---------------- 6 files changed, 16 insertions(+), 147 deletions(-) delete mode 100644 openslides/poll/admin.py delete mode 100644 openslides/poll/tests.py diff --git a/openslides/application/views.py b/openslides/application/views.py index 52c2868de..dd9a9a8bb 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -30,7 +30,7 @@ from application.forms import ApplicationForm, \ ApplicationImportForm from openslides.participant.models import Profile -from poll.models import PollFormView +from poll.views import PollFormView from openslides.utils.utils import template, permission_required, \ render_to_forbitten, del_confirm_form, gen_confirm_form diff --git a/openslides/poll/__init__.py b/openslides/poll/__init__.py index 53035f305..bd6a1282e 100644 --- a/openslides/poll/__init__.py +++ b/openslides/poll/__init__.py @@ -1,6 +1,7 @@ from django.utils.translation import ugettext as _ -from models import PollFormView, BasePoll +from models import BasePoll +from views import PollFormView class DesicionPoll(PollFormView): diff --git a/openslides/poll/admin.py b/openslides/poll/admin.py deleted file mode 100644 index 8d195a63d..000000000 --- a/openslides/poll/admin.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - openslides.poll.admin - ~~~~~~~~~~~~~~~~~~~~~ - - Register app for admin site. - - :copyright: 2011 by the OpenSlides team, see AUTHORS. - :license: GNU GPL, see LICENSE for more details. -""" - -from django.contrib import admin -from poll.models import Poll, Option - -admin.site.register(Poll) -admin.site.register(Option) diff --git a/openslides/poll/forms.py b/openslides/poll/forms.py index 34a1c6082..a4f53b55d 100644 --- a/openslides/poll/forms.py +++ b/openslides/poll/forms.py @@ -1,47 +1,15 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - openslides.poll.forms - ~~~~~~~~~~~~~~~~~~~~~ +from django import forms - Forms for the poll app. +class OptionForm(forms.Form): + def __init__(self, *args, **kwargs): + extra = kwargs.pop('extra') + formid = kwargs.pop('formid') + kwargs['prefix'] = "option-%s" % formid + super(OptionForm, self).__init__(*args, **kwargs) - :copyright: 2011 by the OpenSlides team, see AUTHORS. - :license: GNU GPL, see LICENSE for more details. -""" - -from django.forms import Form, ModelForm, TextInput, Textarea, IntegerField, CharField, DecimalField, ModelChoiceField -from django.utils.translation import ugettext as _ -from poll.models import Poll, Option -from application.models import Application - - -class PollForm(ModelForm): - error_css_class = 'error' - required_css_class = 'required' - - votescast = IntegerField(required=False, min_value=-2, widget=TextInput(attrs={'class':'small-input'}),label=_("Votes cast")) - invalid = IntegerField(required=False, min_value=-2, widget=TextInput(attrs={'class': 'small-input'}), label=_("Invalid")) - - class Meta: - model = Poll - -class OptionForm(ModelForm): - error_css_class = 'error' - required_css_class = 'required' - - voteyes = IntegerField(required=False, min_value=0,widget=TextInput(attrs={'class':'small-input'}),label=_("Votes in favour")) - voteno = IntegerField(required=False, min_value=0,widget=TextInput(attrs={'class':'small-input'}),label=_("Votes against")) - voteundesided = IntegerField(required=False, min_value=0,widget=TextInput(attrs={'class':'small-input'}),label=_("Abstention")) - - class Meta: - model = Option - - -class OptionResultForm(Form): - error_css_class = 'error' - required_css_class = 'required' - - yes = IntegerField(min_value=-2, widget=TextInput(attrs={'class': 'small-input'}), label=_("Yes")) - no = IntegerField(min_value=-2, required=False, widget=TextInput(attrs={'class': 'small-input'}), label=_("No")) - undesided = IntegerField(min_value=-2, required=False, widget=TextInput(attrs={'class': 'small-input'}), label=_("Abstention")) + for key, value in extra: + self.fields[key] = forms.IntegerField( + widget=forms.TextInput(attrs={'class': 'small-input'}), + label=_(key), + initial=value, + ) diff --git a/openslides/poll/models.py b/openslides/poll/models.py index 0ba4b299f..ec63a30a3 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -12,25 +12,8 @@ from django.db import models from django.utils.translation import ugettext as _ -from django import forms -from django.views.generic import TemplateView -from django.http import HttpResponseRedirect -class OptionForm(forms.Form): - def __init__(self, *args, **kwargs): - extra = kwargs.pop('extra') - formid = kwargs.pop('formid') - kwargs['prefix'] = "option-%s" % formid - super(OptionForm, self).__init__(*args, **kwargs) - - for key, value in extra: - self.fields[key] = forms.IntegerField( - widget=forms.TextInput(attrs={'class': 'small-input'}), - label=_(key), - initial=value, - ) - class BaseOption(models.Model): poll = models.ForeignKey('BasePoll') @@ -113,41 +96,3 @@ class BasePoll(models.Model): return forms -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()) - diff --git a/openslides/poll/tests.py b/openslides/poll/tests.py deleted file mode 100644 index 3d528b206..000000000 --- a/openslides/poll/tests.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -""" - openslides.poll.tests - ~~~~~~~~~~~~~~~~~~~~~ - - Unit tests for the poll app. - - :copyright: 2011 by the OpenSlides team, see AUTHORS. - :license: GNU GPL, see LICENSE for more details. -""" - -from django.test import TestCase - -class SimpleTest(TestCase): - def test_basic_addition(self): - """ - Tests that 1 + 1 always equals 2. - """ - self.failUnlessEqual(1 + 1, 2) - -__test__ = {"doctest": """ -Another way to test that 1 + 1 is equal to 2. - ->>> 1 + 1 == 2 -True -"""} -