
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
btc-flex-forms
Advanced tools
Some form mixins, styles and scripts for fast form development.
Detailed documentation is in the "docs" directory.
Add "flex_forms" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = ( ... 'flex_forms', )
Add static files css::
Classes for usage: StaticFieldset designed for rendering only static fieldsets::
static_data = StaticFieldset(model_1=some_model, model_2=another_model)
grid = { ['field_1', 'field_2'], # etc. ... } field_1 = StaticFlexField(label='Data 1', help_text='Field 1') field_2 = StaticFlexField(data='Some data', label='Data 2')
def init(*args, **kwargs) self.model_1 = kwargs.pop('model_1', None) self.model_2 = kwargs.pop('model_2', None) super().init(*args, **kwargs) self.static_fieldset['field_1'].data = self.model_1.field_1 + self.model_2.field_1 ...
StaticModelFieldset::
my_model = get_object_or_404(MyModel, pk=self.kwargs.get('pk')) static_model_data = StaticModelFieldset(instance=my_model)
grid = { '_1': ['model_field_1', 'model_field_2'], '_2': ['separate_static_field'], # etc. ... } separate_field = StaticFlexField('This is a static field') # only static fields can be defined.
MixedFlexForm::
mix = MixedFlexForm([form_1, form_2, formset_1]) # form_1, form_2, formset_1 - must be are flex too!
grid = { /
'_1': ['form_1_field_2', 'form_2_static_field_1', [formset_1_field_1, form_1_field_1]],
'_2': ['separate_field', 'form_1_field_3', 'separate_static_field'], # etc.
...
} field defined below (non-forms field)
separate_field = forms.CharField() separate_static_field = StaticFlexField('This is a static field')
grid = { ['form_1_prefix-form_1_field_2', 'form_2_prefix-form_2_field_1'], # etc. ... }
FlexForm, FlexModelForm designed for rendering good known django forms - Form, ModelForm with flex layout::
class CustomFlexForm(FlexForm):
grid = {
'Fields': ['field_1', 'field_2'],
'New row': ['field_3'],
'Controls': ['button'],
...
}
field_1 = forms.MultipleChoiceField(
label='Fruits?',
choices=(('0', 'Apple'), ('1', 'Mango')),
widget=forms.CheckboxSelectMultiple(attrs={
'field_group_class': 'checkbox-as-button checkbox-as-row',
})
)
# static fields support
field_2 = StaticFlexField(
data='Example', label='Example', help_text='Example')
)
field_3 = StaticFlexField(data='Example', label='Example')
button = FlexButton('Submit')
...
FlexFormset, FlexModelFormset, FlexInlineFormset - respectively implementation of
BaseFormSet, BaseModelFormSet, BaseInlineFormSet::
formset = formset_factory(CustomFlexForm, FlexFormset, extra=4)
Grid: to locate fields you must specify them in grid variable as shown below. The dict key is a row title
that allows you to horizontally split field rows. If the title is not needed, it must starts with _ symbol::
grid = { 'User Info': ['field_1', 'field_2'], '_1': ['field_3', ['field_4', 'field_5'], 'field_6'], '_2': ['field_7', 'field_8'], '_3': ['field_9', 'field_10', 'field_14'], '_4': ['field_11'], '_5': ['field_12'], '_6': ['button'], }
Template tags::
{% load flex_forms %}
{% as_flex form_object %} # use this tag for rendering form or formset {% flex_form_grid form %} # use this tag for rendering form body generated with form_grid (visible fields) {% complex_flex_field field %} # use this tag for rendering a single flex field of the form
Manual template building::
{% load flex_forms %}
{% csrf_token %} {% for field in form.hidden_fields %} {{ field }} {% endfor %} <div class="flex-fields-column">
<div class="flex-fields-row_title">Title</div>
<div class="flex-fields-row">
<div class="flex-fields-block block-with-padding">
{% complex_flex_field form.field_1 %}
{% complex_flex_field form.static_fieldset.field_44 default_value='No value' %}
{% complex_flex_field form.static_fieldset.button %}
</div>
</div>
</div>
<div class="flex-fields-column">
<div class="flex-fields-row_title">Controls</div>
<div class="flex-fields-row">
<div class="flex-fields-block block-with-padding">
{% complex_flex_field form.static_fieldset.button %}
</div>
</div>
</div>
class MyForm(FlexForm):
template = 'custom_form_template.html'
Example
.. image:: https://user-images.githubusercontent.com/33987296/73204264-b7cb5780-414f-11ea-859a-356aecdfd5c7.png
FAQs
Some form mixins, styles and scripts for fast form development.
We found that btc-flex-forms demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.