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]
 
assert_status(self, status, request_vars) source code
 
__init__()
SQLFORM(db.table,...
source code
 
createform(self, xfields) source code
 
accepts(self, request_vars, session=None, formname='%(tablename)s/%(record_id)s', keepvalues=None, onvalidation=None, dbio=True, hideerror=False, detect_record_change=False, **kwargs)
similar FORM.accepts but also does insert, update or delete in DAL.
source code

Inherited from html.FORM: add_button, as_dict, as_json, as_xml, as_yaml, 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.XmlComponent: __add__, __mul__, add_class, remove_class

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Static Methods [hide private]
 
dictform(dictionary, **kwargs) source code
 
smartdictform(session, name, filename=None, query=None, **kwargs) source code
 
factory(*fields, **attributes)
generates a SQLFORM for the given fields.
source code
 
build_query(fields, keywords) source code
 
search_menu(fields, search_options=None, prefix='w2p') source code
 
grid(query, fields=None, field_id=None, left=None, headers={}, orderby=None, groupby=None, searchable=True, sortable=True, paginate=20, deletable=True, editable=True, details=True, selectable=None, create=True, csv=True, links=None, links_in_grid=True, upload='<default>', args=[], user_signature=True, maxtextlengths={}, maxtextlength=20, onvalidation=None, onfailure=None, oncreate=None, onupdate=None, ondelete=None, sorter_icons=(XML('&#x25B2;'),XML('&#x25BC;')), ui='web2py', showbuttontext=True, _class='web2py_grid', formname='web2py_grid', search_widget='default', ignore_rw=False, formstyle='table3cols', exportclasses=None, formargs={}, createargs={}, editargs={}, viewargs={}, selectable_submit_button='Submit', buttons_placement='right', links_placement='right', noconfirm=False, cache_count=None, client_side_delete=False, ignore_common_filters=None) source code
 
smartgrid(table, constraints=None, linked_tables=None, links=None, links_in_grid=True, args=None, user_signature=True, divider='>', breadcrumbs_class='', **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)
source code

Inherited from html.FORM: confirm

Class Variables [hide private]
  widgets = <Storage {'multiple': <class 'gluon.sqlhtml.Multiple...
  formstyles = <Storage {'table2cols': <function formstyle_table...
  FIELDNAME_REQUEST_DELETE = 'delete_this_record'
  FIELDKEY_DELETE_RECORD = 'delete_record'
  ID_LABEL_SUFFIX = '__label'
  ID_ROW_SUFFIX = '__row'
  AUTOTYPES = {<type 'float'>: ('double', <gluon.validators.IS_F...

Inherited from html.FORM: REDIRECT_JS, tag

Inherited from html.DIV: regex_attr, regex_class, regex_id, regex_tag

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

assert_status(self, status, request_vars)

source code 
Overrides: html.FORM.assert_status

__init__()
(Constructor)

source code 

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

Overrides: object.__init__

accepts(self, request_vars, session=None, formname='%(tablename)s/%(record_id)s', keepvalues=None, onvalidation=None, dbio=True, hideerror=False, detect_record_change=False, **kwargs)

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=None, linked_tables=None, links=None, links_in_grid=True, args=None, user_signature=True, divider='>', breadcrumbs_class='', **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 'gluon.sqlhtml.MultipleOptionsWidget'>, '\
string': <class 'gluon.sqlhtml.StringWidget'>, 'text': <class 'gluon.s\
qlhtml.TextWidget'>, 'datetime': <class 'gluon.sqlhtml.DatetimeWidget'\
>, 'boolean': <class 'gluon.sqlhtml.BooleanWidget'>, 'radio': <class '\
gluon.sqlhtml.RadioWidget'>, 'date': <class 'gluon.sqlhtml.DateWidget'\
>, 'integer': <class 'gluon.sqlhtml.IntegerWidget'>, 'password': <clas\
s 'gluon.sqlhtml.PasswordWidget'>, 'double': <class 'gluon.sqlhtml.Dou\
bleWidget'>, 'decimal': <class 'gluon.sqlhtml.DecimalWidget'>, 'list':\
...

formstyles

Value:
<Storage {'table2cols': <function formstyle_table2cols at 0x3371b18>, \
'ul': <function formstyle_ul at 0x3371c80>, 'table3cols': <function fo\
rmstyle_table3cols at 0x33711b8>, 'inline': <function formstyle_inline\
 at 0x3371c08>, 'bootstrap': <function formstyle_bootstrap at 0x3371cf\
8>, 'divs': <function formstyle_divs at 0x3371b90>, 'bootstrap3': <fun\
ction formstyle_bootstrap3 at 0x3371d70>}>

AUTOTYPES

Value:
{<type 'float'>: ('double',
                  <gluon.validators.IS_FLOAT_IN_RANGE object at 0x3382\
7d0>),
 <type 'int'>: ('integer',
                <gluon.validators.IS_INT_IN_RANGE object at 0x3382790>\
),
 <type 'bool'>: ('boolean', None),
 <type 'list'>: ('list:string', None),
...