Пример #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
     ])
Пример #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
     ])
Пример #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
     ])
Пример #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
Пример #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
     ])
Пример #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
Пример #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)
Пример #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)
Пример #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)
Пример #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)
Пример #11
0
 def as_choices(self):
     return sort_choices((code, "{0} ({1})".format(_(name), code))
                         for name, code in self.values_list("name", "code"))