Insert LocalizedModelChoiceField for use in MotionSetWorkflowMixin. Fixed #713.

This commit is contained in:
Norman Jäckel 2013-06-09 16:41:58 +02:00
parent 3aec652882
commit 0d1db941b8
2 changed files with 15 additions and 4 deletions

View File

@ -14,8 +14,7 @@ from django import forms
from django.utils.translation import ugettext as _, ugettext_lazy
from openslides.config.api import config
from openslides.utils.forms import CssClassMixin
from openslides.utils.forms import CleanHtmlFormMixin
from openslides.utils.forms import CssClassMixin, CleanHtmlFormMixin, LocalizedModelChoiceField
from openslides.utils.person import PersonFormField, MultiplePersonFormField
from .models import Motion, Category, Workflow
@ -144,7 +143,7 @@ class MotionSetWorkflowMixin(forms.ModelForm):
so, the motion's state is reset.
"""
set_workflow = forms.ModelChoiceField(
set_workflow = LocalizedModelChoiceField(
queryset=Workflow.objects.all(),
required=False,
label=ugettext_lazy('Workflow'),

View File

@ -13,7 +13,7 @@
import bleach
from django import forms
from django.utils.translation import ugettext_lazy
from django.utils.translation import ugettext as _, ugettext_lazy
# Allowed tags, attributes and styles allowed in textareas edited with a JS
@ -48,6 +48,18 @@ class CssClassMixin(object):
required_css_class = 'required'
class LocalizedModelChoiceField(forms.ModelChoiceField):
"""
Subclass of Django's ModelChoiceField to translate the labels of the
model's objects.
"""
def label_from_instance(self, *args, **kwargs):
"""
Translates the output from Django's label_from_instance method.
"""
return _(super(LocalizedModelChoiceField, self).label_from_instance(*args, **kwargs))
class LocalizedModelMultipleChoiceField(forms.ModelMultipleChoiceField):
def __init__(self, *args, **kwargs):
self.to_field_name = kwargs.get('to_field_name', None)