2012-02-15 10:43:08 +01:00
|
|
|
from django import forms
|
2012-02-15 12:36:50 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
2012-02-15 10:43:08 +01:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
from utils.forms import CssClassMixin
|
2012-04-17 17:35:50 +02:00
|
|
|
from models import Vote
|
2012-02-19 17:31:17 +01:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
|
|
|
|
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:
|
|
|
|
if type(vote) is Vote:
|
|
|
|
key = vote.value
|
|
|
|
value = vote.get_value()
|
|
|
|
weight = vote.get_weight()
|
|
|
|
else:
|
|
|
|
key = vote
|
|
|
|
value = _(vote)
|
|
|
|
weight = None
|
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-02-15 10:43:08 +01:00
|
|
|
)
|