Table Of Contents

Previous topic

Utilities And Internals

Next topic

Navigation Utilities

This Page

Uniforms

This module complements the django forms library by adding ajax functionality, inline forms, and custom layout based on uni-form style. The module has been adapted from django-uni-form.

Using uniforms to render form is easy:

from djcms.utils.uniforms import FormLayout, Fieldset, blockLabels2

class MyForm(uniforms.Form):
    name = forms.CharField()

    #create the form layout
    layout = FormLayout(Fieldset('name', css_class=blockLabels2))

There are three types of layout: inlineLabels, blockLabels and blockLabels2 (the default).

Layout Types

inlineLabels, blockLabels, blockLabels2.

FormLayout class

class djpcms.utils.uniforms.FormLayout(*fields, **kwargs)

Main class for defining the layout of a uniform. For example:

class NoteForm(forms.Form):
    name = forms.CharField()
    dt   = forms.DateTimeField()
    content = forms.TextField()

    layout = FormLayout(Fieldset('name', 'dt'),
                        Fieldset('description'),
                        Row('password1','password2'),
                        Html('<img src="/media/somepicture.jpg"/>'))
id

String id for layout.

template

Template file name or None

default_style

The default layout style of UniFormElement in self. One of layout types. Default inlineLabels.

add(*fields)

Add fields to all fields. A field must be an instance of UniFormElement.

render(form, inputs=None)

Render the uniform layout or form.

Form Element Class

class djpcms.utils.uniforms.UniFormElement

Base class for elements in a uniform FormLayout.

css_class

The class used for the form element, one of layout types. If missing the FormLayout.default_style will be used.

elem_css

Extra css class for the element. Default None.

template

An optional template file name for rendering the element. Default None.

render(form, layout=None)

Render the uniform element. This function is called the the instance of FormLayout which contains self.

Form Elements

class djpcms.utils.uniforms.Fieldset(*fields, **kwargs)

A UniFormElement which renders to a <fieldset>.

class djpcms.utils.uniforms.Row(*fields, **kwargs)

A UniFormElement which renders to a <div>.

class djpcms.utils.uniforms.Columns(*columns, **kwargs)

A UniFormElement whiche defines a set of columns. Renders to a set of <div>.

class djpcms.utils.uniforms.Html(html, **kwargs)

A UniFormElement which renders to self.

UniForm Wrapper

class djpcms.utils.uniforms.UniForm(form, template=None, request=None, instance=None, method='post', enctype='multipart/form-data', error_message=None, action='.', inputs=None, tag=True, csrf=False, is_ajax=False)

Class holding a form, formsets and helper for displaying forms as uni-forms.

json_errors(withmessage=True)

Serialize form errors for AJAX-JSON interaction.

render(djp=None, validate=False)

Render the uniform by rendering individual forms, inline forms and inputs.