Package Dropbox :: 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]
 
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, 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('&#x2191;'),XML('&#x2193;')), ui='web2py', showbuttontext=True, _class='web2py_grid', formname='web2py_grid', search_widget='default', ignore_rw=False, formstyle='table3cols', exportclasses=None, formargs={}, createargs={}, editargs={}, viewargs={}, buttons_placement='right', links_placement='right') 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 'Dropbox.web2py.gluon.s...
  formstyles = <Storage {'ul': <function formstyle_ul at 0x107e7...
  FIELDNAME_REQUEST_DELETE = 'delete_this_record'
  FIELDKEY_DELETE_RECORD = 'delete_record'
  ID_LABEL_SUFFIX = '__label'
  ID_ROW_SUFFIX = '__row'
  AUTOTYPES = {<type 'bool'>: ('boolean', None), <type 'float'>:...

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 'Dropbox.web2py.gluon.sqlhtml.MultipleOpt\
ionsWidget'>, 'string': <class 'Dropbox.web2py.gluon.sqlhtml.StringWid\
get'>, 'text': <class 'Dropbox.web2py.gluon.sqlhtml.TextWidget'>, 'dat\
etime': <class 'Dropbox.web2py.gluon.sqlhtml.DatetimeWidget'>, 'boolea\
n': <class 'Dropbox.web2py.gluon.sqlhtml.BooleanWidget'>, 'radio': <cl\
ass 'Dropbox.web2py.gluon.sqlhtml.RadioWidget'>, 'date': <class 'Dropb\
ox.web2py.gluon.sqlhtml.DateWidget'>, 'integer': <class 'Dropbox.web2p\
y.gluon.sqlhtml.IntegerWidget'>, 'password': <class 'Dropbox.web2py.gl\
...

formstyles

Value:
<Storage {'ul': <function formstyle_ul at 0x107e76de8>, 'table2cols': \
<function formstyle_table2cols at 0x107e76c80>, 'table3cols': <functio\
n formstyle_table3cols at 0x107e76398>, 'inline': <function formstyle_\
inline at 0x107e76d70>, 'bootstrap': <function formstyle_bootstrap at \
0x107e76e60>, 'divs': <function formstyle_divs at 0x107e76cf8>}>

AUTOTYPES

Value:
{<type 'bool'>: ('boolean', None),
 <type 'float'>: ('double',
                  <Dropbox.web2py.gluon.validators.IS_FLOAT_IN_RANGE o\
bject at 0x107e7cd10>),
 <type 'int'>: ('integer',
                <Dropbox.web2py.gluon.validators.IS_INT_IN_RANGE objec\
t at 0x107e7ccd0>),
 <type 'list'>: ('list:string', None),
...