Merge pull request #719 from normanjaeckel/TranslateWorkflow

Insert LocalizedModelChoiceField for use in MotionSetWorkflowMixin.
This commit is contained in:
Oskar Hahn 2013-06-09 07:58:53 -07:00
commit 76a0d232dc
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)