Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#22245 closed Bug (fixed)

Widget on DecimalField subclass ignored

Reported by: jeroen.pulles@… Owned by: nobody
Component: Forms Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a subclass of DecimalField with a widget member set, like so:

class ParameterField(DecimalField):
    widget = ParameterWidget

This works in Django 1.5 (by way of the constructor of Field, I guess). Django 1.6 doesn't pick up the specialised widget. IntegerField does a setdefault on widget that I can't follow:

class IntegerField(Field):
...

    def __init__(self, max_value=None, min_value=None, *args, **kwargs):
        self.max_value, self.min_value = max_value, min_value
        kwargs.setdefault('widget', NumberInput if not kwargs.get('localize') else self.widget)
        super(IntegerField, self).__init__(*args, **kwargs)

Adding localize = False to the ParameterField class doesn't help because that doesn't make it appear in kwargs for IntegerField.

Attachments (1)

22245-1.diff (1.8 KB) - added by claudep 13 months ago.
Suggested fix

Download all attachments as: .zip

Change History (6)

comment:1 Changed 13 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

Changed 13 months ago by claudep

Suggested fix

comment:2 Changed 13 months ago by claudep

  • Has patch set

comment:3 Changed 13 months ago by charettes

  • Triage Stage changed from Accepted to Ready for checkin

Patch looks RFC.

comment:4 Changed 13 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 5a976b4bec79cdb6b75581be6478356fb13fda77:

Fixed #22245 -- Avoided widget overwrite in forms.IntegerField subclasses

Thanks Jeroen Pulles for the report and Simon Charette for the review.

comment:5 Changed 13 months ago by Claude Paroz <claude@…>

In 1a2939bc26b7077e3196cea9bce52826ec7a6d9d:

[1.6.x] Fixed #22245 -- Avoided widget overwrite in forms.IntegerField subclasses

Thanks Jeroen Pulles for the report and Simon Charette for the review.
Backport of 5a976b4bec7 from master.

Note: See TracTickets for help on using tickets.
Back to Top