Package web2py :: Package gluon :: Module sqlhtml :: Class SQLFORM

[hide private]
[frames] | no frames]

# Class SQLFORM

source code

           object --+
                    |
    html.XmlComponent --+
                        |
                 html.DIV --+
                            |
                    html.FORM --+
                                |
                               SQLFORM

    SQLFORM is used to map a table (and a current record) into an HTML form

    given a SQLTable stored in db.table

    generates an insert form::

        SQLFORM(db.table)

    generates an update form::

        record=db.table[some_id]
        SQLFORM(db.table, record)

    generates an update with a delete button::

        SQLFORM(db.table, record, deletable=True)

    if record is an int::

        record=db.table[record]

    optional arguments:

    :param fields: a list of fields that should be placed in the form,
        default is all.
    :param labels: a dictionary with labels for each field, keys are the field
        names.
    :param col3: a dictionary with content for an optional third column
            (right of each field). keys are field names.
    :param linkto: the URL of a controller/function to access referencedby
        records
            see controller appadmin.py for examples
    :param upload: the URL of a controller/function to download an uploaded file
            see controller appadmin.py for examples

    any named optional attribute is passed to the <form> tag
            for example _class, _id, _style, _action, _method, etc.

Instance Methods | [hide private]

__init__() SQLFORM(db.table,... | source code

createform(self, xfields) | source code

accepts(self, request_vars, session=global_settings.applications_parent, formname=`'``%(tablename)s/%(record_id)s``'`, keepvalues=True, onvalidation=global_settings.applications_parent, dbio=True, hideerror=True, detect_record_change=True) similar FORM.accepts but also does insert, update or delete in DAL. | source code

Inherited from `html.FORM`: `hidden_fields`, `process`, `validate`, `xml`

Inherited from `html.FORM` (private): `_postprocessing`

Inherited from `html.DIV`: `__delitem__`, `__getitem__`, `__len__`, `__nonzero__`, `__setitem__`, `__str__`, `append`, `element`, `elements`, `flatten`, `insert`, `sibling`, `siblings`, `update`

Inherited from `html.DIV` (private): `_fixup`, `_setnode`, `_traverse`, `_validate`, `_wrap_components`, `_xml`

Inherited from `object`: `__delattr__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`

Static Methods | [hide private]

factory(*fields, **attributes) generates a SQLFORM for the given fields. | source code

build_query(fields, keywords) | source code

search_menu(fields, search_options=global_settings.applications_parent) | source code

grid(query, fields=global_settings.applications_parent, field_id=global_settings.applications_parent, left=global_settings.applications_parent, headers=`{``}`, orderby=global_settings.applications_parent, searchable=True, sortable=True, paginate=20, deletable=True, editable=True, details=True, selectable=global_settings.applications_parent, create=True, csv=True, links=global_settings.applications_parent, links_in_grid=True, upload=`'``<default>``'`, args=`[``]`, user_signature=True, maxtextlengths=`{``}`, maxtextlength=20, onvalidation=global_settings.applications_parent, oncreate=global_settings.applications_parent, onupdate=global_settings.applications_parent, ondelete=global_settings.applications_parent, sorter_icons=(XML('&#x2191;'),XML('&#x2193;')), ui=`'``web2py``'`, showbuttontext=True, _class=`'``web2py_grid``'`, formname=`'``web2py_grid``'`, search_widget=`'``default``'`, ignore_rw=True, formstyle=`'``table3cols``'`)

source code

smartgrid(table, constraints=global_settings.applications_parent, linked_tables=global_settings.applications_parent, links=global_settings.applications_parent, links_in_grid=True, args=global_settings.applications_parent, user_signature=True, **kwargs)
@auth.requires_login() def index(): db.define_table('person',Field('name'),format='%(name)s') db.define_table('dog', Field('name'),Field('owner',db.person),format='%(name)s') db.define_table('comment',Field('body'),Field('dog',db.dog)) if db(db.person).isempty(): from gluon.contrib.populate import populate populate(db.person,300) populate(db.dog,300) populate(db.comment,1000) db.commit() form=SQLFORM.smartgrid(db[request.args(0) or 'person']) #*** return dict(form=form) *** builds a complete interface to navigate all tables links to the request.args(0) table: pagination, search, view, edit, delete, children, parent, etc.

source code

Class Variables | [hide private]

| widgets = `<Storage {'multiple': <class 'web2py.gluon.sqlhtml.M`...``
| FIELDNAME_REQUEST_DELETE = ``'``delete_this_record``'``
| FIELDKEY_DELETE_RECORD = ``'``delete_record``'``
| ID_LABEL_SUFFIX = ``'``__label``'``
| ID_ROW_SUFFIX = ``'``__row``'``
Inherited from `html.FORM`: `tag` Inherited from `html.DIV`: `regex_attr`, `regex_class`, `regex_id`, `regex_tag`

Properties | [hide private]

Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__()
(Constructor)

source code

    SQLFORM(db.table,
           record=None,
           fields=['name'],
           labels={'name': 'Your name'},
           linkto=URL(f='table/db/')

Overrides: html.FORM.__init__

### accepts(self, request_vars, session=global_settings.applications_parent, formname=`'``%(tablename)s/%(record_id)s``'`, keepvalues=True, onvalidation=global_settings.applications_parent, dbio=True, hideerror=True, detect_record_change=True)

source code

    similar FORM.accepts but also does insert, update or delete in DAL.
    but if detect_record_change == True than:
      form.record_changed = False (record is properly validated/submitted)
      form.record_changed = True (record cannot be submitted because changed)
    elseif detect_record_change == False than:
      form.record_changed = None

Overrides: html.FORM.accepts

### factory(*fields, **attributes)
Static Method

source code

generates a SQLFORM for the given fields.

Internally will build a non-database based data model to hold the fields.

### smartgrid(table, constraints=global_settings.applications_parent, linked_tables=global_settings.applications_parent, links=global_settings.applications_parent, links_in_grid=True, args=global_settings.applications_parent, user_signature=True, **kwargs)
Static Method

source code

    @auth.requires_login()
    def index():
        db.define_table('person',Field('name'),format='%(name)s')
        db.define_table('dog',
            Field('name'),Field('owner',db.person),format='%(name)s')
        db.define_table('comment',Field('body'),Field('dog',db.dog))
        if db(db.person).isempty():
            from gluon.contrib.populate import populate
            populate(db.person,300)
            populate(db.dog,300)
            populate(db.comment,1000)
            db.commit()
    form=SQLFORM.smartgrid(db[request.args(0) or 'person']) #***
    return dict(form=form)

    *** builds a complete interface to navigate all tables links
        to the request.args(0)
        table: pagination, search, view, edit, delete,
               children, parent, etc.

    constraints is a dict {'table',query} that limits which
    records can be accessible
    links is a dict like
       {'tablename':[lambda row: A(....), ...]}
    that will add buttons when table tablename is displayed
    linked_tables is a optional list of tablenames of tables
    to be linked

Class Variable Details | [hide private]

### widgets

Value:

      <Storage {'multiple': <class 'web2py.gluon.sqlhtml.MultipleOptionsWidg
      et'>, 'string': <class 'web2py.gluon.sqlhtml.StringWidget'>, 'text': <
      class 'web2py.gluon.sqlhtml.TextWidget'>, 'datetime': <class 'web2py.g
      luon.sqlhtml.DatetimeWidget'>, 'boolean': <class 'web2py.gluon.sqlhtml
      .BooleanWidget'>, 'radio': <class 'web2py.gluon.sqlhtml.RadioWidget'>,
       'date': <class 'web2py.gluon.sqlhtml.DateWidget'>, 'integer': <class
      'web2py.gluon.sqlhtml.IntegerWidget'>, 'password': <class 'web2py.gluo
      n.sqlhtml.PasswordWidget'>, 'double': <class 'web2py.gluon.sqlhtml.Dou
      ...