API — Formbar 0.20.3 documentation

# API

`formbar.config.` `load`(path)

  Return the parsed XML form the given file. The function will load the file located in path and than returns the parsed content.

class `formbar.config.` `Config`(tree)

  Class for accessing the form configuration file. It provides methods to get certain elements from the configuration.

  `get_form`(id)

    Returns a `Form` instance with the configuration for a form with id in the configuration file. If the form can not be found a KeyError is raised.

    Id: | ID of the form in the configuration file
    Returns: | `FormConfig` instance

class `formbar.form.` `Form`(config, item=None, dbsession=None, translate=None, change_page_callback={}, renderers={}, request=None, csrf_token=None, eval_url=None, url_prefix='', locale=None)

  Class for forms. The form will take care for rendering the form, validating the submitted data and saving the data back to the item.

  The form must be instanciated with an instance of an `Form` configuration and optional an SQLAlchemy mapped item.

  If an SQLAlchemy mapped item is provided there are some basic validation is done based on the defintion in the database. Further the save method will save the values directly into the database.

  If no item was provided than a dummy item will be created with the attributes of the configured fields in the form.

  `get_errors`(page=None)

    Returns a dictionary of all errors in the form. If page parameter is given, then only the errors for fields on the given page are returned. This dictionary will contain the errors if the validation fails. The key of the dictionary is the fieldname of the field. As a field can have more than one error the value is a list.

    Page: | Dictionary with errors
    Returns: | Dictionary with errors

  `get_warnings`(page=None)

    Returns a dictionary of all warnings in the form. If page parameter is given, then only the warnings for fields on the given page are returned. This dictionary will contain the warnings if the validation fails. The key of the dictionary is the fieldname of the field. As a field can have more than one warning the value is a list.

    Page: | Name of the page
    Returns: | Dictionary with warnings

  `render`(values={}, page=0, buttons=True, previous_values={}, outline=True)

    Returns the rendererd form as an HTML string.

    Values: | Dictionary with values to be prefilled/overwritten in the rendered form.
    Previous_values:
    | Dictionary of values of the last saved state of the item. If provided a diff between the current and previous values will be renderered in readonly mode.
    Outline: | Boolean flag to indicate that the outline for pages should be rendered. Defaults to true.
    Returns: | Rendered form.

  `save`()

    Will save the validated data back into the item. In case of an SQLAlchemy mapped item the data will be stored into the database. :returns: Item with validated data.

  `validate`(submitted=None)

    Returns True if the validation succeeds else False. Validation of the data happens in three stages:

    1. Prevalidation. Custom rules that are checked before any datatype checks on type conversations are made. 2. Basic type checks and type conversation. Type checks and type conversation is done based on the data type of the field and further constraint defined in the database if the form is instanciated with an SQLAlchemy mapped item. 3. Postvalidation. Custom rules that are checked after the type conversation was done. Note: Postevaluation is only done for successfull converted values. 4. External Validators. External defined checks done on teh converted values. Note: Validators are only called for successfull converted values

    All errors are stored in the errors dictionary through the process of validation. After the validation finished the values are stored in the data dictionary. In case there has been errors the dictionary will contain the origin submitted data.

    Submitted: | Dictionary with submitted values.
    Returns: | True or False

class `formbar.renderer.` `FieldRenderer`(field, translate)

  Renderer for fields. The renderer will build the the HTML for the provided field.

class `formbar.renderer.` `InfoFieldRenderer`(field, translate)

  A Renderer to render simple fa_field elements