OpenSlides/openslides/poll/forms.py

37 lines
988 B
Python
Raw Normal View History

2012-04-25 22:29:19 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.poll.forms
~~~~~~~~~~~~~~~~~~~~~
Forms for the poll app.
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
2012-02-15 10:43:08 +01:00
from django import forms
from utils.forms import CssClassMixin
2012-07-10 01:33:03 +02:00
from utils.translation_ext import ugettext_lazy as _
2012-04-17 17:35:50 +02:00
from models import Vote
class OptionForm(forms.Form, CssClassMixin):
2012-02-15 10:43:08 +01:00
def __init__(self, *args, **kwargs):
extra = kwargs.pop('extra')
formid = kwargs.pop('formid')
kwargs['prefix'] = "option-%s" % formid
super(OptionForm, self).__init__(*args, **kwargs)
2012-04-17 17:35:50 +02:00
for vote in extra:
key = vote.value
value = vote.get_value()
weight = vote.get_weight(raw=True)
2012-02-15 10:43:08 +01:00
self.fields[key] = forms.IntegerField(
2012-04-17 17:35:50 +02:00
label=value,
initial=weight,
2012-06-23 12:05:09 +02:00
min_value=-2,
2012-06-24 22:34:11 +02:00
required=False,
2012-02-15 10:43:08 +01:00
)