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=1, formname='%(tablename)s/%(record_id)s', keepvalues=True, onvalidation=1, 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 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'
  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(r=request, f='table/db/')

Overrides: html.FORM.__init__

accepts(self, request_vars, session=1, formname='%(tablename)s/%(record_id)s', keepvalues=True, onvalidation=1, 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.

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\
...