django_param provides ParamForm class which allows python param to be used in django form.
Project description
django_param provides ParamForm class which allows python param to be used in django form.
Quick start
Add ‘colorfield’, ‘django_select2’, ‘django_param’ and ‘django.forms’ to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'colorfield', 'django_select2', 'django_param', 'django.forms' ]
Usage:
# Specify your param class
class MyParam(param.Parameterized):
probability = param.Number(0.5, bounds=(0, 1), doc="Probability that...")
test_string = param.String(default="test string", doc="Your String")
my_param = MyParam()
# Initialize Django Form
django_form = ParamForm({'probability': 0.1, 'test_string': 'test_bound'}, param=my_param)
# Get data from request.POST
django_form = ParamForm(request.POST, param=my_param)
# To return param with values from request.POST
param = django_form.as_param()
Add Form data (assuming your form is named form):
First you need to add the form media, you can include {{ form.media }} in your header page.
To add the form, simply use {{ form }}
you can pass your param to the page and retrieve the values using
{% for p in param.get_param_values %}
<li>{{ p.0 }}: {{ p.1 }}</li>
{% endfor %}
Supported Param Class:
Boolean
Color
CalendarDate
DataFrame
Date
FileSelector
List
ListSelector
Magnitude
MultiFileSelector
NumericTuple
ObjectSelector
Range
Selector
String
Tuple
XYCoordinates
You can also override the default widget with your own custom widget. For example:
widget_map = {
param.parameterized.String:
lambda po, p, name: forms.CharField(
initial=po.inspect_value(name) or p.default,
widget=Textarea,
),
}
form = ParamForm(param=my_param, widget_map=widget_map)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django_param-0.1.0.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d42675e79a3fac7d344a6fb3804111b6c4efb881e719bcaf5004a6c98b6e5352 |
|
MD5 | a7612882cf47e28c34882d5c0dfb6c8f |
|
BLAKE2b-256 | d83b5ed403e1994ac1b4116d156d9f5b77a0bdd8cc647602d56a4b9a197b849b |