Макет API¶
- class layout.BaseInput(name, value, **kwargs)[исходный код]¶
A base class to reduce the amount of code in the Input classes.
- render(form, form_style, context, template_pack=<SimpleLazyObject: 'bootstrap'>, **kwargs)[исходный код]¶
Renders an <input /> if container is used as a Layout object. Input button value can be a variable in context.
- class layout.Button(*args, **kwargs)[исходный код]¶
Used to create a Submit input descriptor for the {% crispy %} template tag:
button = Button('Button 1', 'Press Me!')
Примечание
The first argument is also slugified and turned into the id for the button.
- class layout.ButtonHolder(*fields, **kwargs)[исходный код]¶
Layout object. It wraps fields in a <div class=»buttonHolder»>
This is where you should put Layout objects that render to form buttons like Submit. It should only hold HTML and BaseInput inherited objects.
Example:
ButtonHolder( HTML(<span style="display: hidden;">Information Saved</span>), Submit('Save', 'Save') )
- class layout.Column(*fields, **kwargs)[исходный код]¶
Layout object. It wraps fields in a div so the wrapper can be used as a column. Example:
Column('form_field_1', 'form_field_2')
- Depending on the template, css class associated to the div is formColumn, row, or nothing. For this last case, you
must provide css classes. Example:
Column('form_field_1', 'form_field_2', css_class='col-xs-6',)
- class layout.Div(*fields, **kwargs)[исходный код]¶
Layout object. It wraps fields in a <div>
You can set css_id for a DOM id and css_class for a DOM class. Example:
Div('form_field_1', 'form_field_2', css_id='div-example', css_class='divs')
- class layout.Field(*args, **kwargs)[исходный код]¶
Layout object, It contains one field name, and you can add attributes to it easily. For setting class attributes, you need to use css_class, as class is a Python keyword.
Example:
Field('field_name', style="color: #333;", css_class="whatever", id="field_name")
- class layout.Fieldset(legend, *fields, **kwargs)[исходный код]¶
Layout object. It wraps fields in a <fieldset>
Example:
Fieldset("Text for the legend", 'form_field_1', 'form_field_2' )
The first parameter is the text for the fieldset legend. This text is context aware, so you can do things like:
Fieldset("Data for {{ user.username }}", 'form_field_1', 'form_field_2' )
- class layout.HTML(html)[исходный код]¶
Layout object. It can contain pure HTML and it has access to the whole context of the page where the form is being rendered.
Examples:
HTML("{% if saved %}Data saved{% endif %}") HTML('<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />')
- class layout.Hidden(name, value, **kwargs)[исходный код]¶
Used to create a Hidden input descriptor for the {% crispy %} template tag.
- class layout.Layout(*fields)[исходный код]¶
Form Layout. It is conformed by Layout objects: Fieldset, Row, Column, MultiField, HTML, ButtonHolder, Button, Hidden, Reset, Submit and fields. Form fields have to be strings. Layout objects Fieldset, Row, Column, MultiField and ButtonHolder can hold other Layout objects within. Though ButtonHolder should only hold HTML and BaseInput inherited classes: Button, Hidden, Reset and Submit.
Example:
helper.layout = Layout( Fieldset('Company data', 'is_company' ), Fieldset(_('Contact details'), 'email', Row('password1', 'password2'), 'first_name', 'last_name', HTML('<img src="/media/somepicture.jpg"/>'), 'company' ), ButtonHolder( Submit('Save', 'Save', css_class='button white'), ), )
- class layout.MultiField(label, *fields, **kwargs)[исходный код]¶
MultiField container. Renders to a MultiField <div>
- class layout.MultiWidgetField(*args, **kwargs)[исходный код]¶
Layout object. For fields with
MultiWidget
as widget, you can pass additional attributes to each widget.Example:
MultiWidgetField( 'multiwidget_field_name', attrs=( {'style': 'width: 30px;'}, {'class': 'second_widget_class'} ), )
Примечание
To override widget’s css class use
class
notcss_class
.
- class layout.Reset(*args, **kwargs)[исходный код]¶
Used to create a Reset button input descriptor for the {% crispy %} template tag:
reset = Reset('Reset This Form', 'Revert Me!')
Примечание
The first argument is also slugified and turned into the id for the reset.
- class layout.Row(*fields, **kwargs)[исходный код]¶
Layout object. It wraps fields in a div whose default class is «formRow». Example:
Row('form_field_1', 'form_field_2', 'form_field_3')
- class layout.Submit(*args, **kwargs)[исходный код]¶
Used to create a Submit button descriptor for the {% crispy %} template tag:
submit = Submit('Search the Site', 'search this site')
Примечание
The first argument is also slugified and turned into the id for the submit button.