Beispiel #1
0
 def __init__(self, component, *args, **kwargs):
     super(MatrixLanguageForm, self).__init__(*args, **kwargs)
     languages = Language.objects.filter(translation__subproject=component)
     self.fields['lang'].choices = sort_choices([
         (l.code, '{0} ({1})'.format(force_text(l), l.code))
         for l in languages
     ])
Beispiel #2
0
 def __init__(self, component, *args, **kwargs):
     super(NewLanguageOwnerForm, self).__init__(*args, **kwargs)
     languages = Language.objects.exclude(translation__subproject=component)
     self.fields['lang'].choices = sort_choices([
         (l.code, '{0} ({1})'.format(force_text(l), l.code))
         for l in languages
     ])
Beispiel #3
0
 def __init__(self, component, *args, **kwargs):
     super(MatrixLanguageForm, self).__init__(*args, **kwargs)
     languages = Language.objects.filter(translation__component=component)
     self.fields['lang'].choices = sort_choices([
         (l.code, '{0} ({1})'.format(force_text(l), l.code))
         for l in languages
     ])
Beispiel #4
0
 def formfield_for_foreignkey(self, db_field, request, **kwargs):
     """Wrapper to sort languages by localized names"""
     result = super(ProjectAdmin, self).formfield_for_foreignkey(
         db_field, request, **kwargs
     )
     if db_field.name == 'source_language':
         result.choices = sort_choices(result.choices)
     return result
Beispiel #5
0
 def __init__(self, component, *args, **kwargs):
     super(NewLanguageOwnerForm, self).__init__(*args, **kwargs)
     languages = Language.objects.exclude(translation__component=component)
     self.component = component
     self.fields['lang'].choices = sort_choices([
         (l.code, '{0} ({1})'.format(force_text(l), l.code))
         for l in languages
     ])
Beispiel #6
0
 def formfield_for_foreignkey(self, db_field, request, **kwargs):
     """Wrapper to sort languages by localized names"""
     result = super(ProjectAdmin, self).formfield_for_foreignkey(
         db_field, request, **kwargs
     )
     if db_field.name == 'source_language':
         result.choices = sort_choices(result.choices)
     return result
Beispiel #7
0
    def render_options(self, selected_choices):
        """Render sorted options."""
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []

        # Actually sort values
        all_choices = sort_choices(list(self.choices))

        # Stolen from Select.render_options
        for option_value, option_label in all_choices:
            output.append(
                self.render_option(selected_choices, option_value,
                                   option_label))
        return '\n'.join(output)
Beispiel #8
0
    def render_options(self, selected_choices):
        """Render sorted options."""
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []

        # Actually sort values
        all_choices = sort_choices(list(self.choices))

        # Stolen from Select.render_options
        for option_value, option_label in all_choices:
            output.append(
                self.render_option(
                    selected_choices, option_value, option_label
                )
            )
        return '\n'.join(output)
Beispiel #9
0
    def render_options(self, choices, selected_choices=None):
        '''
        Renders sorted options.
        '''
        # Django 1.10 compatibility:
        # the choices parameter was removed there
        if selected_choices is None:
            selected_choices = choices
            choices = []
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []

        # Actually sort values
        all_choices = sort_choices(list(chain(self.choices, choices)))

        # Stolen from Select.render_options
        for option_value, option_label in all_choices:
            output.append(
                self.render_option(selected_choices, option_value,
                                   option_label))
        return '\n'.join(output)
Beispiel #10
0
    def render_options(self, choices, selected_choices=None):
        '''
        Renders sorted options.
        '''
        # Django 1.10 compatibility:
        # the choices parameter was removed there
        if selected_choices is None:
            selected_choices = choices
            choices = []
        # Normalize to strings.
        selected_choices = set(force_text(v) for v in selected_choices)
        output = []

        # Actually sort values
        all_choices = sort_choices(list(chain(self.choices, choices)))

        # Stolen from Select.render_options
        for option_value, option_label in all_choices:
            output.append(
                self.render_option(
                    selected_choices, option_value, option_label
                )
            )
        return '\n'.join(output)
Beispiel #11
0
 def as_choices(self):
     return sort_choices((code, "{0} ({1})".format(_(name), code))
                         for name, code in self.values_list("name", "code"))