Ticket #5247: multipatch.patch

File multipatch.patch, 2.4 KB (added by uhlr@…, 17 years ago)

svn diff for patch application

  • django/newforms/models.py

     
    77from util import ValidationError
    88from forms import BaseForm, DeclarativeFieldsMetaclass, SortedDictFromList
    99from fields import Field, ChoiceField
    10 from widgets import Select, SelectMultiple, MultipleHiddenInput
     10from widgets import Select, SelectMultiple, MultipleHiddenInput, ModelSelectMultiple
    1111
    1212__all__ = ('save_instance', 'form_for_model', 'form_for_instance', 'form_for_fields',
    1313           'ModelChoiceField', 'ModelMultipleChoiceField')
     
    168168    "A MultipleChoiceField whose choices are a model QuerySet."
    169169    hidden_widget = MultipleHiddenInput
    170170    def __init__(self, queryset, cache_choices=False, required=True,
    171             widget=SelectMultiple, label=None, initial=None, help_text=None):
     171            widget=ModelSelectMultiple, label=None, initial=None, help_text=None):
    172172        super(ModelMultipleChoiceField, self).__init__(queryset, None, cache_choices,
    173173            required, widget, label, initial, help_text)
    174174
  • django/newforms/widgets.py

     
    191191        if value is None: value = []
    192192        final_attrs = self.build_attrs(attrs, name=name)
    193193        output = [u'<select multiple="multiple"%s>' % flatatt(final_attrs)]
    194         str_values = set([smart_unicode(v) for v in value]) # Normalize to strings.
     194        str_values = set([self.value_to_str(v) for v in value]) # Normalize to strings.
    195195        for option_value, option_label in chain(self.choices, choices):
    196196            option_value = smart_unicode(option_value)
    197197            selected_html = (option_value in str_values) and ' selected="selected"' or ''
     
    204204            return data.getlist(name)
    205205        return data.get(name, None)
    206206
     207    def value_to_str(cls, value):
     208        return smart_unicode(value)
     209
     210def ModelSelectMultiple(forms.SelectMultiple):
     211    def value_to_str(cls, value):
     212        return super(ModelSelectMultiple, cls).value_to_str(value._get_pk_val())
     213
    207214class RadioInput(StrAndUnicode):
    208215    "An object used by RadioFieldRenderer that represents a single <input type='radio'>."
    209216    def __init__(self, name, value, attrs, choice, index):
Back to Top