Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Improvements
- Added optional timezone parameter to Form initialisation.

New feature
- Added FormDataprovider. A Formdataprovider can be used to fill the form with
(dynamic) values and options.
- Added datetime picker widget. See https://github.com/Eonasdan/bootstrap-datetimepicker
- Added currency widget.
- Added new "fields" command to generate.py command (in contrib) to export the
Expand All @@ -28,7 +30,6 @@ Bugfix:
Internal release only already includes most of the features from 1.1.0 but
never has been released in the public.


1.0.2
=====
Maintenance release.
Expand Down
3 changes: 3 additions & 0 deletions formbar/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ def get_options(self):
elif isinstance(user_defined_options, str):
for option in self._form.merged_data.get(user_defined_options):
options.append((option[0], option[1], True))
elif self._form._item and hasattr(self._form._item, "get_options"):
for option in self._form._item.get_options(self.name):
options.append((option[0], option[1], True))
return self.sort_options(options)

def _from_python(self, value):
Expand Down
36 changes: 36 additions & 0 deletions formbar/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@ class ValidationException(Exception):
pass


class FormDataprovider(object):
"""Dummy class which can be used to provided dynamic data to the
form. It can be provided as item on the form init to provide
dynamically loaded options and values.

As said the dataprovider can be user to provide `options` and `values`.
Both are provided by defining propertys.

1. Value
The function should simply return the pythonic value of the field:

@property
def foo(self):
return "1"

1. Options
The function should return a list of tuples. The first value of the
tuple is the displayed label and the second value is the value of
the option:

@property
def foo_options(self):
return [("Foo", "1"), ("Bar", "2")]

or you can use the helper method `get_options(fieldname)`
"""

def __init__(self, ctx):
self.ctx = ctx
"""Can be anything. E.g db connection, request. It depends on the context."""

def get_options(self, name):
if hasattr(self, name+"_options"):
return getattr(self, name+"_options")
return []

class Validator(object):
"""Validator class for external validators. External validators can
be used to implement more complicated validations on the converted
Expand Down