reorder poll
This commit is contained in:
parent
0957de83a9
commit
9c367509dd
@ -30,7 +30,7 @@ from application.forms import ApplicationForm, \
|
|||||||
ApplicationImportForm
|
ApplicationImportForm
|
||||||
from openslides.participant.models import Profile
|
from openslides.participant.models import Profile
|
||||||
|
|
||||||
from poll.models import PollFormView
|
from poll.views import PollFormView
|
||||||
|
|
||||||
from openslides.utils.utils import template, permission_required, \
|
from openslides.utils.utils import template, permission_required, \
|
||||||
render_to_forbitten, del_confirm_form, gen_confirm_form
|
render_to_forbitten, del_confirm_form, gen_confirm_form
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from models import PollFormView, BasePoll
|
from models import BasePoll
|
||||||
|
from views import PollFormView
|
||||||
|
|
||||||
|
|
||||||
class DesicionPoll(PollFormView):
|
class DesicionPoll(PollFormView):
|
||||||
|
@ -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)
|
|
@ -1,47 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
from django import forms
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
openslides.poll.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.
|
for key, value in extra:
|
||||||
:license: GNU GPL, see LICENSE for more details.
|
self.fields[key] = forms.IntegerField(
|
||||||
"""
|
widget=forms.TextInput(attrs={'class': 'small-input'}),
|
||||||
|
label=_(key),
|
||||||
from django.forms import Form, ModelForm, TextInput, Textarea, IntegerField, CharField, DecimalField, ModelChoiceField
|
initial=value,
|
||||||
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"))
|
|
||||||
|
@ -12,25 +12,8 @@
|
|||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext as _
|
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):
|
class BaseOption(models.Model):
|
||||||
poll = models.ForeignKey('BasePoll')
|
poll = models.ForeignKey('BasePoll')
|
||||||
|
|
||||||
@ -113,41 +96,3 @@ class BasePoll(models.Model):
|
|||||||
return forms
|
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())
|
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
"""}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user