Browse Source

fixed a bug breaking callable defaults in forms

master
phryk 11 months ago
parent
commit
9b99401c4f
2 changed files with 1 additions and 7 deletions
  1. +1
    -1
      poobrains/form/__init__.py
  2. +0
    -6
      poobrains/form/fields.py

+ 1
- 1
poobrains/form/__init__.py View File

@@ -71,7 +71,7 @@ class BaseForm(poobrains.rendering.Renderable, metaclass=FormMeta):
value = getattr(attr, propname)
if not callable(value):
value = copy.deepcopy(value)
elif propname in ('default', 'choices'):
elif propname in ('default', 'choices', 'value'):
value = value() # handle arguments to Fields that are optionally callable; ex: Checkbox(default=lambda: bool(random.randint(0,1)))
kw[propname] = value



+ 0
- 6
poobrains/form/fields.py View File

@@ -80,9 +80,6 @@ class BaseField(object, metaclass=poobrains.helpers.MetaCompatibility):
if not choices is None:
self.choices = choices # leave choices of other __init__ intact. <- TODO: what other __init__? did i mean statically defined properties in subclasses?

#if callable(self.choices):
# self.choices = self.choices()


if not default is None:
self.default = default
@@ -90,9 +87,6 @@ class BaseField(object, metaclass=poobrains.helpers.MetaCompatibility):
if self.default is None and self.multi:
self.default = []

#if callable(self.default):
# self.default = self.default()


if not value is None:
self.value = value


Loading…
Cancel
Save