sqlhtml
Module¶
Holds:
- SQLFORM: provide a form for a table (with/without record)
- SQLTABLE: provides a table for a set of records
- form_factory: provides a SQLFORM for an non-db backed table
- class
gluon.sqlhtml.
AutocompleteWidget
(request,field,id_field=None,db=None,orderby=None,limitby=(0,10),distinct=False,keyword='_autocomplete_%(tablename)s_%(fieldname)s',min_length=2,help_fields=None,help_string=None,at_beginning=True)[source]¶ Bases:
object
- class
gluon.sqlhtml.
BooleanWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
ExportClass
(rows)[source]¶ Bases:
object
content_type
= None¶
file_ext
= None¶
label
= None¶
- class
gluon.sqlhtml.
ExporterCSV
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'text/csv'¶
file_ext
= 'csv'¶
label
= 'CSV'¶
- class
gluon.sqlhtml.
ExporterCSV_hidden
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'text/csv'¶
file_ext
= 'csv'¶
label
= 'CSV'¶
- class
gluon.sqlhtml.
ExporterHTML
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'text/html'¶
file_ext
= 'html'¶
label
= 'HTML'¶
- class
gluon.sqlhtml.
ExporterJSON
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'application/json'¶
file_ext
= 'json'¶
label
= 'JSON'¶
- class
gluon.sqlhtml.
ExporterTSV
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'text/tab-separated-values'¶
file_ext
= 'csv'¶
label
= 'TSV'¶
- class
gluon.sqlhtml.
ExporterXML
(rows)[source]¶ Bases:
gluon.sqlhtml.ExportClass
content_type
= 'text/xml'¶
file_ext
= 'xml'¶
label
= 'XML'¶
- class
gluon.sqlhtml.
FormWidget
[source]¶ Bases:
object
Helper for SQLFORM to generate form input fields (widget), related to thefieldtype
- class
gluon.sqlhtml.
JSONWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
OptionsWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
PasswordWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
SQLFORM
(table, record=None, deletable=False, linkto=None, upload=None, fields=None, labels=None, col3={}, submit_button='Submit', delete_label='Check to delete', showid=True, readonly=False, comments=True, keepopts=[], ignore_rw=False, record_id=None, formstyle=None, buttons=['submit'], separator=None, extra_fields=None, **attributes)[source]¶ Bases:
gluon.html.FORM
SQLFORM is used to map a table (and a current record) into an HTML form.
Given a Table like 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)
Parameters: - table –Table object
- record – either an int if theid is an int, or the record fetchedfrom the table
- deletable – adds the delete checkbox
- linkto – the URL of a controller/function to access referencedbyrecords
- upload – the URL of a controller/function to download an uploaded file
- fields – a list of fields that should be placed in the form,default is all.
- labels – a dictionary with labels for each field, keys are the fieldnames.
- col3 – a dictionary with content for an optional third column(right of each field). keys are field names.
- submit_button – text to show in the submit button
- delete_label – text to show next to the delete checkbox
- showid – shows the id of the record
- readonly – doesn’t allow for any modification
- comments – show comments (stored incol3 or in Field definition)
- ignore_rw – overrides readable/writable attributes
- record_id – used to create session key against CSRF
- formstyle – what to use to generate the form layout
- buttons – override buttons as you please (will be also stored inform.custom.submit)
- separator – character as separator between labels and inputs
any named optional attribute is passed to the <form> tagfor example _class, _id, _style, _action, _method, etc.
AUTOTYPES
= {<type 'int'>: ('integer', <gluon.validators.IS_INT_IN_RANGE object at 0x7ff70776e250>), <type 'float'>: ('double', <gluon.validators.IS_FLOAT_IN_RANGE object at 0x7ff70776e290>), <type 'unicode'>: ('string', None), <type 'bool'>: ('boolean', None), <type 'str'>: ('string', None), <type 'list'>: ('list:string', None), <type 'datetime.datetime'>: ('datetime', <gluon.validators.IS_DATETIME object at 0x7ff70776e350>), <type 'datetime.date'>: ('date', <gluon.validators.IS_DATE object at 0x7ff70776e310>)}¶
FIELDKEY_DELETE_RECORD
= 'delete_record'¶
FIELDNAME_REQUEST_DELETE
= 'delete_this_record'¶
ID_LABEL_SUFFIX
= '__label'¶
ID_ROW_SUFFIX
= '__row'¶
accepts
(request_vars,session=None,formname='%(tablename)s/%(record_id)s',keepvalues=None,onvalidation=None,dbio=True,hideerror=False,detect_record_change=False,**kwargs)[source]¶Similar toFORM.accepts but also does insert, update or delete in DAL.If detect_record_change isTrue than:
- form.record_changed = False (record is properly validated/submitted)
- form.record_changed = True (record cannot be submitted because changed)
If detect_record_change == False than:
- form.record_changed = None
- static
factory
(*fields,**attributes)[source]¶ Generates a SQLFORM for the given fields.
Internally will build a non-database based data modelto hold the fields.
formstyles
= {'bootstrap': <function formstyle_bootstrap at 0x7ff70776c9b0>, 'bootstrap3_inline': <function _inner at 0x7ff70776cb90>, 'bootstrap3_stacked': <function formstyle_bootstrap3_stacked at 0x7ff70776ca28>, 'divs': <function formstyle_divs at 0x7ff70776c848>, 'inline': <function formstyle_inline at 0x7ff70776c8c0>, 'table2cols': <function formstyle_table2cols at 0x7ff70776c7d0>, 'table3cols': <function formstyle_table3cols at 0x7ff70774ede8>, 'ul': <function formstyle_ul at 0x7ff70776c938>}¶
- static
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=(<gluon.html.XML object>,<gluon.html.XML object>),ui='web2py',showbuttontext=True,_class='web2py_grid',formname='web2py_grid',search_widget='default',advanced_search=True,ignore_rw=False,formstyle=None,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,auto_pagination=True,use_cursor=False)[source]¶
- static
smartgrid
(table,constraints=None,linked_tables=None,links=None,links_in_grid=True,args=None,user_signature=True,divider='>',breadcrumbs_class='',**kwargs)[source]¶ Builds a system of SQLFORM.grid(s) between any referenced tables
Parameters: - table – main table
- constraints (dict) –{‘table’:query} that limits which records canbe accessible
- links (dict) – like{‘tablename’:[lambda row: A(….), …]} thatwill add buttons when table tablename is displayed
- linked_tables (list) – list of tables to be linked
Example
given you defined a model as:
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))ifdb(db.person).isempty():fromgluon.contrib.populateimportpopulatepopulate(db.person,300)populate(db.dog,300)populate(db.comment,1000)
in a controller, you can do:
@auth.requires_login()defindex():form=SQLFORM.smartgrid(db[request.args(0)or'person'])returndict(form=form)
widgets
= {'autocomplete': <class 'gluon.sqlhtml.AutocompleteWidget'>, 'blob': None, 'boolean': <class 'gluon.sqlhtml.BooleanWidget'>, 'checkboxes': <class 'gluon.sqlhtml.CheckboxesWidget'>, 'date': <class 'gluon.sqlhtml.DateWidget'>, 'datetime': <class 'gluon.sqlhtml.DatetimeWidget'>, 'decimal': <class 'gluon.sqlhtml.DecimalWidget'>, 'double': <class 'gluon.sqlhtml.DoubleWidget'>, 'integer': <class 'gluon.sqlhtml.IntegerWidget'>, 'json': <class 'gluon.sqlhtml.JSONWidget'>, 'list': <class 'gluon.sqlhtml.ListWidget'>, 'multiple': <class 'gluon.sqlhtml.MultipleOptionsWidget'>, 'options': <class 'gluon.sqlhtml.OptionsWidget'>, 'password': <class 'gluon.sqlhtml.PasswordWidget'>, 'radio': <class 'gluon.sqlhtml.RadioWidget'>, 'string': <class 'gluon.sqlhtml.StringWidget'>, 'text': <class 'gluon.sqlhtml.TextWidget'>, 'time': <class 'gluon.sqlhtml.TimeWidget'>, 'upload': <class 'gluon.sqlhtml.UploadWidget'>}¶
- class
gluon.sqlhtml.
SQLTABLE
(sqlrows,linkto=None,upload=None,orderby=None,headers={},truncate=16,columns=None,th_link='',extracolumns=None,selectid=None,renderstyle=False,cid=None,colgroup=False,**attributes)[source]¶ Bases:
gluon.html.TABLE
Given with a Rows object, as returned by adb().select(), generatesan html table with the rows.
Parameters: - sqlrows – theRows object
- linkto – URL (or lambda to generate a URL) to edit individual records
- upload – URL to download uploaded files
- orderby – Add an orderby link to column headers.
- headers – dictionary of headers to headers redefinionsheaders can also be a string to generate the headers from datafor now only headers=”fieldname:capitalize”,headers=”labels” and headers=None are supported
- truncate – length at which to truncate text in table cells.Defaults to 16 characters.
- columns – a list or dict contaning the names of the columns to be shownDefaults to all
- th_link – base link to support orderby headers
- extracolumns – a list of dicts
- selectid – The id you want to select
- renderstyle – Boolean render the style with the table
- cid – use this cid for all links
- colgroup – #FIXME
Extracolumns example
[{'label':A('Extra',_href='#'),'class':'',#class name of the header'width':'',#width in pixels or %'content':lambdarow,rc:A('Edit',_href='edit/%s'%row.id),'selected':False#agregate class selected to this column}]
- class
gluon.sqlhtml.
StringWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
TextWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
- class
gluon.sqlhtml.
UploadWidget
[source]¶ Bases:
gluon.sqlhtml.FormWidget
DEFAULT_WIDTH
= '150px'¶
DELETE_FILE
= 'delete'¶
GENERIC_DESCRIPTION
= 'file ## download'¶
ID_DELETE_SUFFIX
= '__delete'¶
- static
is_image
(value)[source]¶ Tries to check if the filename provided references to an image
- Checking is based on filename extension. Currently recognized:
- gif, png, jp(e)g, bmp
Parameters: value – filename
- classmethod
represent
(field,value,download_url=None)[source]¶ How to represent the file:
- with download url and if it is an image: <A href=…><IMG …></A>
- otherwise with download url: <A href=…>file</A>
- otherwise: file
Parameters: - field – the field
- value – the field value
- download_url – url for the file download (default = None)
- classmethod
widget
(field,value,download_url=None,**attributes)[source]¶ generates a INPUT file tag.
Optionally provides an A link to the file, including a checkbox sothe file can be deleted.
All is wrapped in a DIV.
see also:FormWidget.widget
Parameters: - field – the field
- value – the field value
- download_url – url for the file download (default = None)
gluon.sqlhtml.
form_factory
(*fields,**attributes)¶Generates a SQLFORM for the given fields.
Internally will build a non-database based data modelto hold the fields.
gluon.sqlhtml.
formstyle_bootstrap3_inline_factory
(col_label_size=3)[source]¶bootstrap 3 horizontal form layout
Note
Experimental!