sqlhtml
模块¶
持有:
sqlform:为表提供一个表单(有/无记录)
sqltable:为一组记录提供一个表
Form_Factory:为非数据库支持的表提供一个sqlForm
- 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, default_var='ac', user_signature=True, hash_vars=False)[源代码]¶
基类:
object
- class gluon.sqlhtml.ExportClass(rows)[源代码]¶
基类:
object
- content_type = None¶
- file_ext = None¶
- label = None¶
- class gluon.sqlhtml.ExporterCSV(rows)[源代码]¶
-
- content_type = 'text/csv'¶
- file_ext = 'csv'¶
- label = 'CSV'¶
- class gluon.sqlhtml.ExporterHTML(rows)[源代码]¶
-
- content_type = 'text/html'¶
- file_ext = 'html'¶
- label = 'HTML'¶
- class gluon.sqlhtml.ExporterJSON(rows)[源代码]¶
-
- content_type = 'application/json'¶
- file_ext = 'json'¶
- label = 'JSON'¶
- class gluon.sqlhtml.ExporterTSV(rows)[源代码]¶
-
- content_type = 'text/tab-separated-values'¶
- file_ext = 'tsv'¶
- label = 'TSV'¶
- class gluon.sqlhtml.ExporterXML(rows)[源代码]¶
-
- content_type = 'text/xml'¶
- file_ext = 'xml'¶
- label = 'XML'¶
- 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)[源代码]¶
-
SQLForm用于将表(和当前记录)映射到HTML表单中。
给出一个类似db.table的表
生成插入表单::
SQLFORM(db.table)
生成更新表单:
record=db.table[some_id] SQLFORM(db.table, record)
使用“删除”按钮生成更新:
SQLFORM(db.table, record, deletable=True)
- 参数
table -- Table 对象
record -- 如果 id 是int,或从表中提取的记录
deletable -- 添加“删除”复选框
linkto -- 访问被引用的记录的控制器/函数的URL
upload -- 下载上载文件的控制器/函数的URL
fields -- 应放置在表单中的字段列表,默认为全部。
labels -- 一个字典,每个字段都有标签,关键字是字段名。
col3 -- 包含可选第三列(每个字段右侧)内容的字典。键是字段名。
submit_button -- 要在“提交”按钮中显示的文本
delete_label -- 要在“删除”复选框旁边显示的文本
showid -- 显示记录的ID
readonly -- 不允许任何修改
comments -- 显示注释(存储在 col3 或在字段定义中)
ignore_rw -- 重写可读/可写属性
record_id -- 用于针对CSRF创建会话密钥
formstyle -- 用于生成表单布局的内容
buttons -- 根据需要覆盖按钮(也将存储在 form.custom.submit )
separator -- 字符作为标签和输入之间的分隔符
任何命名的可选属性都会传递给<form>标记,例如u class、u id、u style、u action、u method等。
- AUTOTYPES = {<class 'str'>: ('string', None), <class 'bool'>: ('boolean', None), <class 'int'>: ('integer', <pydal.validators.IS_INT_IN_RANGE object>), <class 'float'>: ('double', <pydal.validators.IS_FLOAT_IN_RANGE object>), <class 'list'>: ('list:string', None), <class 'datetime.date'>: ('date', <pydal.validators.IS_DATE object>), <class 'datetime.datetime'>: ('datetime', <pydal.validators.IS_DATETIME object>)}¶
- 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)[源代码]¶
类似 FORM.accepts 但也可以在DAL中插入、更新或删除。如果检测到记录更改为 True 然后:
form.record_changed = False (记录已正确验证/提交)
form.record_changed = True (记录因更改而无法提交)
如果检测到_record_change==false,则:
form.record_changed = None
- 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=(▲, ▼), 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, represent_none=None, showblobs=False)[源代码]¶
- static smartgrid(table, constraints=None, linked_tables=None, links=None, links_in_grid=True, args=None, user_signature=True, divider='\xa0\xa0>\xa0\xa0', breadcrumbs_class='', **kwargs)[源代码]¶
在任何引用的表之间生成sqlform.grid系统
- 参数
table -- 主台
constraints (dict) -- {{'table':query}} 限制哪些记录可以访问
links (dict) -- 喜欢 {{'tablename':[lambda row: A(....), ...]}} 在显示表tablename时添加按钮
linked_tables (list) -- 要链接的表列表
例子
假设您将模型定义为:
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)
在控制器中,可以执行以下操作:
@auth.requires_login() def index(): form=SQLFORM.smartgrid(db[request.args(0) or 'person']) return dict(form=form)
- class gluon.sqlhtml.SQLTABLE(sqlrows, linkto=None, upload=None, orderby=None, query='', headers={}, truncate=16, columns=None, th_link='', extracolumns=None, selectid=None, renderstyle=False, cid=None, colgroup=False, **attributes)[源代码]¶
-
与Rows对象一起给定,由 db().select() ,生成带有行的HTML表。
- 参数
sqlrows -- 这个 Rows 对象
linkto -- 用于编辑单个记录的URL(或lambda以生成URL)
upload -- 下载上载文件的URL
orderby -- 添加到列标题的orderby链接。
query -- 支持orderby头的查询字符串。
headers -- 头到头的字典重新定义头也可以是一个字符串来从数据中生成头,目前只支持headers=“fieldname:capitalize”、headers=“labels”和headers=none。
truncate -- 截断表格单元格中文本的长度。默认为16个字符。
columns -- 包含要显示的列名称的列表或dict默认为all。
th_link -- 支持orderby标题的基本链接
extracolumns -- DICT列表
selectid -- 要选择的ID
renderstyle -- 布尔值用表格呈现样式
cid -- 对所有链接使用此CID
colgroup -- 固定器
列外示例:
[{'label':A('Extra', _href='#'), 'class': '', #class name of the header 'width':'', #width in pixels or % 'content':lambda row, rc: A('Edit', _href='edit/%s'%row.id), 'selected': False #agregate class selected to this column}]
- REGEX_ALIAS_MATCH = '^(.*) AS (.*)$'¶
- class gluon.sqlhtml.UploadWidget[源代码]¶
-
- DEFAULT_WIDTH = '150px'¶
- DELETE_FILE = 'delete'¶
- GENERIC_DESCRIPTION = 'file ## download'¶
- ID_DELETE_SUFFIX = '__delete'¶
- gluon.sqlhtml.form_factory(*fields, **attributes)¶
为给定字段生成一个sqlform。
内部将构建一个非基于数据库的数据模型来保存字段。