Ticket #8169: admin-widgets-attrs.3.diff

File admin-widgets-attrs.3.diff, 1.9 KB (added by Alex Gaynor, 16 years ago)

Really good patch, like amazing

  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index 884171b..f45ff36 100644
    a b class RelatedFieldWidgetWrapper(forms.Widget):  
    210210        return self.widget.id_for_label(id_)
    211211
    212212class AdminTextareaWidget(forms.Textarea):
    213     def __init__(self, attrs={}):
    214         super(AdminTextareaWidget, self).__init__(attrs={'class': 'vLargeTextField'})
     213    def __init__(self, attrs=None):
     214        final_attrs = {'class': 'vLargeTextField'}
     215        if attrs is not None:
     216            attrs = final_attrs
     217        else:
     218            final_attrs.update(attrs)
     219        super(AdminTextareaWidget, self).__init__(attrs=final_attrs})
    215220
    216221class AdminTextInputWidget(forms.TextInput):
    217     def __init__(self, attrs={}):
    218         super(AdminTextInputWidget, self).__init__(attrs={'class': 'vTextField'})
     222    def __init__(self, attrs=None):
     223        final_attrs = {'class': 'vTextField'}
     224        if attrs is not None:
     225            final_attrs.update(attrs)
     226        super(AdminTextInputWidget, self).__init__(attrs=final_attrs)
    219227
    220228class AdminURLFieldWidget(forms.TextInput):
    221     def __init__(self, attrs={}):
    222         super(AdminURLFieldWidget, self).__init__(attrs={'class': 'vURLField'})
     229    def __init__(self, attrs=None):
     230        final_attrs = {'class': 'vURLField'}
     231        if attrs is not None:
     232            final_attrs.update(attrs)
     233        super(AdminURLFieldWidget, self).__init__(attrs=final_attrs)
    223234
    224235class AdminIntegerFieldWidget(forms.TextInput):
    225     def __init__(self, attrs={}):
    226         super(AdminIntegerFieldWidget, self).__init__(attrs={'class': 'vIntegerField'})
     236    def __init__(self, attrs=None):
     237        final_attrs = {'class': 'vIntegerField'}
     238        if attrs is not None:
     239            final_attrs.update(attrs)
     240        super(AdminIntegerFieldWidget, self).__init__(attrs=final_attrs)
Back to Top