cleanup poll app

This commit is contained in:
Oskar Hahn 2012-07-10 11:48:03 +02:00
parent 01f0823ed7
commit e22467b06e
3 changed files with 19 additions and 33 deletions

View File

@ -11,10 +11,10 @@
""" """
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _
from utils.forms import CssClassMixin from openslides.utils.forms import CssClassMixin
from utils.translation_ext import ugettext_lazy as _ from openslides.poll.models import Vote
from models import Vote
class OptionForm(forms.Form, CssClassMixin): class OptionForm(forms.Form, CssClassMixin):

View File

@ -11,10 +11,8 @@
""" """
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.projector.api import register_slidemodel
from openslides.projector.models import SlideMixin
from openslides.utils.translation_ext import ugettext_lazy as _
from openslides.utils.modelfields import MinMaxIntegerField from openslides.utils.modelfields import MinMaxIntegerField
@ -51,7 +49,8 @@ class Vote(models.Model):
class CountVotesCast(models.Model): class CountVotesCast(models.Model):
votescast = MinMaxIntegerField(null=True, blank=True, min_value=-2, verbose_name=_("Votes cast")) votescast = MinMaxIntegerField(null=True, blank=True, min_value=-2,
verbose_name=_("Votes cast"))
def append_pollform_fields(self, fields): def append_pollform_fields(self, fields):
fields.append('votescast') fields.append('votescast')
@ -64,7 +63,8 @@ class CountVotesCast(models.Model):
class CountInvalid(models.Model): class CountInvalid(models.Model):
votesinvalid = MinMaxIntegerField(null=True, blank=True, min_value=-2, verbose_name=_("Votes invalid")) votesinvalid = MinMaxIntegerField(null=True, blank=True, min_value=-2,
verbose_name=_("Votes invalid"))
def append_pollform_fields(self, fields): def append_pollform_fields(self, fields):
fields.append('votesinvalid') fields.append('votesinvalid')
@ -87,15 +87,9 @@ class PublishPollMixin(models.Model):
abstract = True abstract = True
class BasePoll(models.Model, SlideMixin): class BasePoll(models.Model):
#TODO: It would be nice if this class wouldn't be a subclass from models.Model. But it is needet aslong
# BaseOption has a foreignKey on BasePoll
prefix = 'BasePoll'
description = models.TextField(null=True, blank=True, verbose_name=_("Description")) #TODO: Use this field or delete it.
option_class = TextOption option_class = TextOption
vote_values = [_('votes', fixstr=True)] vote_values = [ugettext_noop('votes')]
def has_votes(self): def has_votes(self):
""" """
@ -150,7 +144,8 @@ class BasePoll(models.Model, SlideMixin):
def get_form_values(self, option_id): def get_form_values(self, option_id):
# TODO: recall this function. It has nothing to do with a form # TODO: recall this function. It has nothing to do with a form
""" """
Return a the values and the weight of the values as a list with two elements. Return a the values and the weight of the values as a list with two
elements.
""" """
values = [] values = []
for value in self.get_vote_values(): for value in self.get_vote_values():
@ -166,7 +161,8 @@ class BasePoll(models.Model, SlideMixin):
Return the form for one option of the poll. Return the form for one option of the poll.
""" """
from poll.forms import OptionForm from poll.forms import OptionForm
return OptionForm(extra=self.get_form_values(kwargs['formid']), **kwargs) return OptionForm(extra=self.get_form_values(kwargs['formid']),
**kwargs)
def get_vote_forms(self, **kwargs): def get_vote_forms(self, **kwargs):
""" """
@ -179,17 +175,6 @@ class BasePoll(models.Model, SlideMixin):
forms.append(form) forms.append(form)
return forms return forms
def slide(self):
"""
show a Slide for the Poll.
"""
data = super(BasePoll, self).slide()
# data['template'] = 'projector/TODO.html'
return data
def get_absolute_url(self):
return ''
def print_value(value): def print_value(value):
if value == -1: if value == -1:
@ -199,4 +184,3 @@ def print_value(value):
elif value is None: elif value is None:
value = '' value = ''
return unicode(value) return unicode(value)

View File

@ -13,7 +13,7 @@
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.forms.models import modelform_factory from django.forms.models import modelform_factory
from utils.views import TemplateView from openslides.utils.views import TemplateView
class PollFormView(TemplateView): class PollFormView(TemplateView):
@ -34,7 +34,8 @@ class PollFormView(TemplateView):
else: else:
context['forms'] = self.poll.get_vote_forms() context['forms'] = self.poll.get_vote_forms()
FormClass = self.get_modelform_class() FormClass = self.get_modelform_class()
context['pollform'] = FormClass(instance=self.poll, prefix='pollform') context['pollform'] = FormClass(instance=self.poll,
prefix='pollform')
return context return context
def get_success_url(self): def get_success_url(self):
@ -50,7 +51,8 @@ class PollFormView(TemplateView):
forms = self.poll.get_vote_forms(data=self.request.POST) forms = self.poll.get_vote_forms(data=self.request.POST)
FormClass = self.get_modelform_class() FormClass = self.get_modelform_class()
pollform = FormClass(data=self.request.POST, instance=self.poll, prefix='pollform') pollform = FormClass(data=self.request.POST, instance=self.poll,
prefix='pollform')
error = False error = False
for form in forms: for form in forms: