Ticket #22137: 22137-1.diff

File 22137-1.diff, 2.7 KB (added by Claude Paroz, 11 years ago)
  • django/contrib/admin/widgets.py

    diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py
    index f501ffb..6857579 100644
    a b class RelatedFieldWidgetWrapper(forms.Widget):  
    235235    admin interface.
    236236    """
    237237    def __init__(self, widget, rel, admin_site, can_add_related=None):
    238         self.is_hidden = widget.is_hidden
    239238        self.needs_multipart_form = widget.needs_multipart_form
    240239        self.attrs = widget.attrs
    241240        self.choices = widget.choices
    class RelatedFieldWidgetWrapper(forms.Widget):  
    257256        return obj
    258257
    259258    @property
     259    def is_hidden(self):
     260        return self.widget.is_hidden
     261
     262    @property
    260263    def media(self):
    261264        return self.widget.media
    262265
  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index aeb674d..0d78d91 100644
    a b class SubWidget(object):  
    166166
    167167
    168168class Widget(six.with_metaclass(MediaDefiningClass)):
    169     is_hidden = False             # Determines whether this corresponds to an <input type="hidden">.
    170169    needs_multipart_form = False  # Determines does this widget need multipart form
    171170    is_localized = False
    172171    is_required = False
    class Widget(six.with_metaclass(MediaDefiningClass)):  
    183182        memo[id(self)] = obj
    184183        return obj
    185184
     185    @property
     186    def is_hidden(self):
     187        return self.input_type == 'hidden' if hasattr(self, 'input_type') else False
     188
    186189    def subwidgets(self, name, value, attrs=None, choices=()):
    187190        """
    188191        Yields all "subwidgets" of this widget. Used only by RadioSelect to
    class PasswordInput(TextInput):  
    286289
    287290class HiddenInput(Input):
    288291    input_type = 'hidden'
    289     is_hidden = True
    290292
    291293
    292294class MultipleHiddenInput(HiddenInput):
    class MultiWidget(Widget):  
    778780        self.widgets = [w() if isinstance(w, type) else w for w in widgets]
    779781        super(MultiWidget, self).__init__(attrs)
    780782
     783    @property
     784    def is_hidden(self):
     785        return all(w.is_hidden for w in self.widgets)
     786
    781787    def render(self, name, value, attrs=None):
    782788        if self.is_localized:
    783789            for widget in self.widgets:
    class SplitHiddenDateTimeWidget(SplitDateTimeWidget):  
    865871    """
    866872    A Widget that splits datetime input into two <input type="hidden"> inputs.
    867873    """
    868     is_hidden = True
    869 
    870874    def __init__(self, attrs=None, date_format=None, time_format=None):
    871875        super(SplitHiddenDateTimeWidget, self).__init__(attrs, date_format, time_format)
    872876        for widget in self.widgets:
    873877            widget.input_type = 'hidden'
    874             widget.is_hidden = True
Back to Top