sqlhtml 模块

此文件是Web2py Web框架的一部分
版权所有:Massimo di Pierro<mdipierro@cs.depaul.edu>

持有:

  • 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

callback()[源代码]
class gluon.sqlhtml.BooleanWidget[源代码]

基类:gluon.sqlhtml.FormWidget

classmethod widget(field, value, **attributes)[源代码]

生成输入复选框标记。

参见: FormWidget.widget

class gluon.sqlhtml.CacheRepresenter[源代码]

基类:object

class gluon.sqlhtml.CheckboxesWidget[源代码]

基类:gluon.sqlhtml.OptionsWidget

classmethod widget(field, value, **attributes)[源代码]

生成一个表标记,包括输入复选框(允许多个)

参见: FormWidget.widget

class gluon.sqlhtml.DateWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.DatetimeWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.DecimalWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.DoubleWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.ExportClass(rows)[源代码]

基类:object

content_type = None
export()[源代码]
file_ext = None
label = None
represented()[源代码]
class gluon.sqlhtml.ExporterCSV(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/csv'
export()[源代码]
file_ext = 'csv'
label = 'CSV'
class gluon.sqlhtml.ExporterCSV_hidden(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/csv'
export()[源代码]
file_ext = 'csv'
label = 'CSV'
class gluon.sqlhtml.ExporterHTML(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/html'
export()[源代码]
file_ext = 'html'
label = 'HTML'
class gluon.sqlhtml.ExporterJSON(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'application/json'
export()[源代码]
file_ext = 'json'
label = 'JSON'
class gluon.sqlhtml.ExporterTSV(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/tab-separated-values'
export()[源代码]
file_ext = 'tsv'
label = 'TSV'
class gluon.sqlhtml.ExporterTSV_hidden(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/tab-separated-values'
export()[源代码]
file_ext = 'tsv'
label = 'TSV'
class gluon.sqlhtml.ExporterXML(rows)[源代码]

基类:gluon.sqlhtml.ExportClass

content_type = 'text/xml'
export()[源代码]
file_ext = 'xml'
label = 'XML'
class gluon.sqlhtml.FormWidget[源代码]

基类:object

用于SQLForm生成与FieldType相关的表单输入字段(小部件)的帮助程序

classmethod widget(field, value, **attributes)[源代码]

为字段生成小部件。

序列化后,将提供一个输入标记:

  • id=表名u字段名

  • class=字段类型

  • 名称=字段名

参数
  • field -- 需要小部件的字段

  • value -- 价值

  • attributes -- 要应用的任何其他属性

class gluon.sqlhtml.IntegerWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.JSONWidget[源代码]

基类:gluon.sqlhtml.FormWidget

classmethod widget(field, value, **attributes)[源代码]

为JSON符号生成一个文本区域。

参见: FormWidget.widget

class gluon.sqlhtml.ListWidget[源代码]

基类:gluon.sqlhtml.StringWidget

classmethod widget(field, value, **attributes)[源代码]

生成输入文本标记。

参见: FormWidget.widget

class gluon.sqlhtml.MultipleOptionsWidget[源代码]

基类:gluon.sqlhtml.OptionsWidget

classmethod widget(field, value, size=5, **attributes)[源代码]

生成一个select标记,包括选项(允许多个选项)

参见: FormWidget.widget

参数

size -- 可选参数(默认值=5)指示必须显示多少行

class gluon.sqlhtml.OptionsWidget[源代码]

基类:gluon.sqlhtml.FormWidget

static has_options(field)[源代码]

检查字段是否具有可选选项

参数

field -- 需要检查的字段

返回

如果字段有选项,则为true

classmethod widget(field, value, **attributes)[源代码]

生成select标记,包括选项(仅允许1个选项)

参见: FormWidget.widget

class gluon.sqlhtml.PasswordWidget[源代码]

基类:gluon.sqlhtml.FormWidget

classmethod widget(field, value, **attributes)[源代码]

生成输入密码标记。如果存在一个值,它将显示为一个数字“*”,与实际值的长度无关。

参见: FormWidget.widget

class gluon.sqlhtml.RadioWidget[源代码]

基类:gluon.sqlhtml.OptionsWidget

classmethod widget(field, value, **attributes)[源代码]

生成一个表标记,包括输入无线电(仅允许1个选项)

参见: FormWidget.widget

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)[源代码]

基类:gluon.html.FORM

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

assert_status(status, request_vars)[源代码]
static build_query(fields, keywords)[源代码]
createform(xfields)[源代码]
static dictform(dictionary, **kwargs)[源代码]
static factory(*fields, **attributes)[源代码]

为给定字段生成一个sqlform。

内部将构建一个非基于数据库的数据模型来保存字段。

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=(&#x25B2;, &#x25BC;), 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 search_menu(fields, search_options=None, prefix='w2p')[源代码]
static smartdictform(session, name, filename=None, query=None, **kwargs)[源代码]
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)[源代码]

基类:gluon.html.TABLE

与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 (.*)$'
style()[源代码]
class gluon.sqlhtml.StringWidget[源代码]

基类:gluon.sqlhtml.FormWidget

classmethod widget(field, value, **attributes)[源代码]

生成输入文本标记。

参见: FormWidget.widget

class gluon.sqlhtml.TextWidget[源代码]

基类:gluon.sqlhtml.FormWidget

classmethod widget(field, value, **attributes)[源代码]

生成文本区域标记。

参见: FormWidget.widget

class gluon.sqlhtml.TimeWidget[源代码]

基类:gluon.sqlhtml.StringWidget

class gluon.sqlhtml.UploadWidget[源代码]

基类:gluon.sqlhtml.FormWidget

DEFAULT_WIDTH = '150px'
DELETE_FILE = 'delete'
GENERIC_DESCRIPTION = 'file ## download'
ID_DELETE_SUFFIX = '__delete'
static is_image(value)[源代码]

尝试检查文件名是否提供了对图像的引用

检查基于文件扩展名。当前识别:

gif、png、jp(e)g、bmp

参数

value -- 文件名

classmethod represent(field, value, download_url=None)[源代码]

如何表示文件:

  • 使用下载URL,如果是图像:<a href=..><img…>。</a>

  • 否则,使用下载URL:<a href=..>文件</a>

  • 否则:文件

参数
  • field -- 田地

  • value -- 字段值

  • download_url -- 文件下载的URL(默认值=无)

classmethod widget(field, value, download_url=None, **attributes)[源代码]

生成输入文件标记。

(可选)提供指向该文件的链接,包括一个复选框,以便删除该文件。

所有的都包装在一个分区中。

参见: FormWidget.widget

参数
  • field -- 田地

  • value -- 字段值

  • download_url -- 文件下载的URL(默认值=无)

gluon.sqlhtml.add_class(a, b)[源代码]
gluon.sqlhtml.count_expected_args(f)[源代码]
gluon.sqlhtml.form_factory(*fields, **attributes)

为给定字段生成一个sqlform。

内部将构建一个非基于数据库的数据模型来保存字段。

gluon.sqlhtml.formstyle_bootstrap(form, fields)[源代码]

引导2.3.x格式表单布局

gluon.sqlhtml.formstyle_bootstrap3_inline_factory(col_label_size=3)[源代码]

引导3水平窗体布局

注解

实验!

gluon.sqlhtml.formstyle_bootstrap3_stacked(form, fields)[源代码]

引导3格式表单布局

注解

实验!

gluon.sqlhtml.formstyle_bootstrap4_inline_factory(col_label_size=3)[源代码]

引导4水平窗体布局

注解

实验!

gluon.sqlhtml.formstyle_bootstrap4_stacked(form, fields)[源代码]

引导4格式表单布局

注解

实验!

gluon.sqlhtml.formstyle_divs(form, fields)[源代码]

仅限div

gluon.sqlhtml.formstyle_inline(form, fields)[源代码]

仅限divs,但内联

gluon.sqlhtml.formstyle_table2cols(form, fields)[源代码]

2列表

gluon.sqlhtml.formstyle_table3cols(form, fields)[源代码]

3列表-默认

gluon.sqlhtml.formstyle_ul(form, fields)[源代码]

无序列表

gluon.sqlhtml.pluralize(singular, rules=None)[源代码]
gluon.sqlhtml.represent(field, value, record)[源代码]
gluon.sqlhtml.safe_float(x)[源代码]
gluon.sqlhtml.safe_int(x, i=0)[源代码]
gluon.sqlhtml.show_if(cond)[源代码]