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(db.table.id==some_id).select()[0]
    SQLFORM(db.table, record)

generates an update with a delete button::

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

if record is an int::

    record=db(db.table.id==record).select()[0]

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
 
accepts(self, request_vars, session=None, formname='%(tablename)s_%(record_id)s', keepvalues=False, onvalidation=None, dbio=True)
same as FORM.accepts but also does insert, update or delete in SQLDB.
source code

Inherited from html.FORM: hidden_fields, xml

Inherited from html.FORM (private): _postprocessing

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

Inherited from html.DIV (private): _fixup, _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
Class Variables [hide private]
  widgets = <Storage {'multiple': <class 'web2py.gluon.sqlhtml.M...
  FIELDNAME_REQUEST_DELETE = 'delete_this_record'
  FIELDKEY_DELETE_RECORD = 'delete_record'

Inherited from html.FORM: 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(r=request, f='table/db/')

Overrides: object.__init__

accepts(self, request_vars, session=None, formname='%(tablename)s_%(record_id)s', keepvalues=False, onvalidation=None, dbio=True)

source code 

same as FORM.accepts but also does insert, update or delete in SQLDB.

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.


Class Variable Details [hide private]

widgets

Value:
<Storage {'multiple': <class 'web2py.gluon.sqlhtml.MultipleOptionsWidg\
et'>, 'string': <class 'web2py.gluon.sqlhtml.StringWidget'>, 'double':\
 <class 'web2py.gluon.sqlhtml.DoubleWidget'>, 'upload': <class 'web2py\
.gluon.sqlhtml.UploadWidget'>, 'datetime': <class 'web2py.gluon.sqlhtm\
l.DatetimeWidget'>, 'boolean': <class 'web2py.gluon.sqlhtml.BooleanWid\
get'>, 'radio': <class 'web2py.gluon.sqlhtml.RadioWidget'>, 'blob': No\
ne, 'time': <class 'web2py.gluon.sqlhtml.TimeWidget'>, 'date': <class \
'web2py.gluon.sqlhtml.DateWidget'>, 'integer': <class 'web2py.gluon.sq\
...