From 04efae91d292bffb569bd7cc13e5c941e42e8698 Mon Sep 17 00:00:00 2001 From: Sean Hayes Date: Mon, 28 Sep 2015 10:04:08 -0400 Subject: [PATCH] Fixes KeyError when form field has no "initial" value. --- bitfield/forms.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bitfield/forms.py b/bitfield/forms.py index 63405489..961f8180 100644 --- a/bitfield/forms.py +++ b/bitfield/forms.py @@ -28,12 +28,11 @@ def _has_changed(self, initial, data): class BitFormField(IntegerField): def __init__(self, choices=(), widget=BitFieldCheckboxSelectMultiple, *args, **kwargs): - - if isinstance(kwargs['initial'], int): - iv = kwargs['initial'] + initial = kwargs.get('initial') + if isinstance(initial, int): l = [] for i in range(0, 63): - if (1 << i) & iv > 0: + if (1 << i) & initial > 0: l += [choices[i][0]] kwargs['initial'] = l self.widget = widget