本文整理汇总了Python中gluon.sqlhtml.SQLFORM.factory方法的典型用法代码示例。如果您正苦于以下问题:Python SQLFORM.factory方法的具体用法?Python SQLFORM.factory怎么用?Python SQLFORM.factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.sqlhtml.SQLFORM
的用法示例。
在下文中一共展示了SQLFORM.factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: myform
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def myform():
form = SQLFORM.factory(Field("first_name", "string"), Field("last_name", "string"))
def onvalidation(form):
pass
if form.process(session=application.session, onvaliidation=onvalidation).accepted:
redirect(URL())
return dict(form=form)
示例2: reports
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def reports():
response.subtitle = T("Report templates")
response.view='nas/reports.html'
response.cmd_back = ui.control.get_mobil_button(label=T("Account"), href=URL("account",**{'user_signature': True}),
icon="back", ajax="false", theme="a", mini="true")
nas_reports= ntool.getReportFiles(os.path.join(ns.request.folder,'static/resources/report'))
frm_filter = SQLFORM.factory(
Field('database', db.databases, requires = IS_IN_DB(db((db.databases.deleted==False)),
db.databases.id, '%(alias)s'), label=T('Database')),
Field('reptype', "string", label=T('Rep.type'),
requires = IS_EMPTY_OR(IS_IN_SET(nas_reports["types"]))),
Field('label', "string", label=T('Group'),
requires = IS_EMPTY_OR(IS_IN_SET(nas_reports["labels"]))),
Field('repname', type='string', length=50, label=T('Name/Description')),
Field('install', type='boolean', label=T('Installed')),
submit_button=T("Load"), table_name="filter", _id="frm_filter"
)
if request.post_vars.has_key("report_labels"):
if ns.local.setEngine(database=db.databases(id=request.post_vars["database"]).alias, check_ndi=False, created=False, createdb=False):
for label_id in request.post_vars.keys():
if label_id not in("report_labels","database"):
row_id = ns.connect.updateData("ui_message",
values={"id":label_id,"msg":request.post_vars[label_id]}, validate=False, insert_row=False)
if not row_id:
response.flash = str(ns.error_message)
ns.db.commit()
if session.frm_filter:
frm_filter.vars = session.frm_filter
else:
response.flash = str(ns.error_message)
if request.post_vars.has_key("ins_cmd"):
if ns.local.setEngine(database=db.databases(id=request.post_vars["ins_database"]).alias, check_ndi=False, created=False, createdb=False):
if request.post_vars["ins_cmd"]=="delete":
try:
report_id = ns.db.ui_report(reportkey=request.post_vars["ins_reportkey"])["id"]
ns.db(ns.db.ui_reportfields.report_id==report_id).delete()
ns.db(ns.db.ui_reportsources.report_id==report_id).delete()
ns.db((ns.db.ui_message.secname.like(request.post_vars["ins_reportkey"]+"%"))).delete()
ns.db(ns.db.ui_report.id==report_id).delete()
ns.db.commit()
except Exception, err:
response.flash = str(err)
else:
load = dbtool.loadReport(fileName=request.post_vars["ins_reportkey"]+".xml")
if load != "OK":
response.flash = load
if session.frm_filter:
frm_filter.vars = session.frm_filter
else:
response.flash = str(ns.error_message)
示例3: qrgen
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def qrgen():
"Create QR codes"
image = IMG(_src=URL('static/images', 'none.png'), _alt="none")
form = SQLFORM.factory(
Field('message', requires=IS_NOT_EMPTY())
)
if form.accepts(request.vars, session):
msg=request.vars.message
session.msg=request.vars.message
image = IMG(_src=URL('qrcode',vars={'message':msg}))
return dict(form=form,image=image)
else:
return dict(form=form,image=image)
示例4: edit
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def edit():
form = SQLFORM.factory(
Field('first_name', 'string',
requires=IS_NOT_EMPTY(error_message='Please enter first name')),
Field('last_name', 'string',
requires=IS_NOT_EMPTY(error_message='Please enter last name')),
_action=URL('experiments', 'default', 'edit')
)
if form.process(session=application.session).accepted:
redirect(URL())
return {'form': form}
示例5: file_upload
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def file_upload():
form = SQLFORM.factory(
Field(
"file",
"upload",
uploadfolder=application.config.upload_folder,
requires=IS_IMAGE(extensions=("jpg", "jpeg")),
),
_action=URL(),
)
if form.process().accepted:
redirect(URL())
return {"form": form}
示例6: create_form
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def create_form(self):
"""
Build form for subscription settings
"""
T = current.T
db = current.db
response = current.response
user = current.auth.user.pe_id
stable = current.s3db.pr_subscription
formstyle = current.deployment_settings.get_ui_formstyle()
query = (stable.pe_id == user) & \
(stable.deleted != True)
row = db(query).select(stable.id,
stable.frequency,
stable.email_format,
limitby=(0, 1))
messages = Storage(
ERROR = T("Error: could not update subscription settings"),
SUCCESS = T("Settings updated"),
)
if row:
# Subscription exists, build form
freq_field = stable.frequency
format_field = stable.email_format
freq_field.default = row[0].frequency
format_field.default = row[0].email_format
form = SQLFORM.factory(freq_field,
format_field,
formstyle = formstyle)
if form.accepts(current.request.post_vars,
current.session,
keepvalues=True):
formvars = form.vars
from templates.SSF.config import TaskSubscriptions
sub = TaskSubscriptions()
sub.subscription["frequency"] = formvars.frequency
sub.subscription["email_format"] = formvars.email_format
if sub.update_subscription():
response.confirmation = messages.SUCCESS
else:
response.error = messages.ERROR
return form
else:
return None
示例7: change_password
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def change_password():
id = request.args(0)
form = SQLFORM.factory(
Field('password', 'password', requires=db.auth_user['password'].requires),
Field('password_again', 'password', requires=IS_EQUAL_TO(request.vars.password,
error_message=T('Passwords do not match.'))))
if form.accepts(request.vars, session):
dbutils.log_event(db, user_id=auth.user.id, item_id=id,
table_name='auth_user', access='change password',
details='')
db.auth_user[id] = dict(password=form.vars.password)
session.flash = T('Password successfully changed.')
redirect(URL('read', args=id))
return dict(form=form)
示例8: test_factory_applies_default_validators
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def test_factory_applies_default_validators(self):
from gluon import current
factory_form = SQLFORM.factory(
Field('a_date', type='date'),
)
# Fake user input
current.request.post_vars.update({
'_formname': 'no_table/create',
'a_date': '2018-09-14',
'_formkey': '123',
})
# Fake the formkey
current.session['_formkey[no_table/create]'] = ['123']
self.assertTrue(factory_form.process().accepted)
self.assertIsInstance(factory_form.vars.a_date, datetime.date)
示例9: create
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def create():
groups = db(db.auth_group.role != 'Admin'
).select(db.auth_group.id, db.auth_group.role,
orderby=db.auth_group.role).json()
form = SQLFORM.factory(db.auth_user, db.contact,
Field('password_again', 'password',
requires=IS_EQUAL_TO(request.vars.password,
error_message='Passwords do not match.')),
Field('is_active', 'boolean'),
Field('groups', label='Search groups'),
submit_button='Create User',
hidden=dict(groups_new=None),
table_name='user')
form.element(_name='groups')['_onkeyup'] = "showgroups()"
form.element(_name='groups')['_autocomplete'] = 'off'
form.element(_name='contact_info')['_placeholder'] = 'insert contact details here'
form.vars.is_active = 'on'
if form.accepts(request.vars, session):
if form.vars.is_active:
form.vars.registration_key = ''
else:
form.vars.registration_key = 'blocked'
id = db.auth_user.insert(**db.auth_user._filter_fields(form.vars))
form.vars.user_id = id
db.contact.insert(**db.contact._filter_fields(form.vars))
if request.vars.groups_new:
insert_groups(request.vars.groups_new.split(',')[:-1], id)
dbutils.log_event(db, user_id=auth.user.id, item_id=id,
table_name='auth_user', access='create')
session.flash = T('User successfully added.')
redirect(URL('index'))
return dict(form=form, json=SCRIPT('var groups=%s' % groups))
示例10: __call__
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def __call__(self):
output = {}
T = current.T
request = current.request
response = current.response
s3 = response.s3
# Check logged in and permissions
auth = current.auth
settings = current.deployment_settings
roles = current.session.s3.roles
system_roles = auth.get_system_roles()
AUTHENTICATED = system_roles.AUTHENTICATED
# Login/Registration forms
self_registration = current.deployment_settings.get_security_registration_visible()
registered = False
login_form = None
login_div = None
register_form = None
register_div = None
# Contact Form
request_email = settings.get_frontpage("request_email")
if request_email:
from s3dal import Field
from gluon.validators import IS_NOT_EMPTY
from gluon.sqlhtml import SQLFORM
fields = [Field("name",
label="Your name",
requires=IS_NOT_EMPTY(),
),
Field("address",
label="Your e-mail address",
requires=IS_NOT_EMPTY(),
),
Field("subject",
label="Subject",
requires=IS_NOT_EMPTY(),
),
Field("message", "text",
label="Message",
requires=IS_NOT_EMPTY(),
),
]
from s3 import s3_mark_required
labels, required = s3_mark_required(fields)
s3.has_required = required
response.form_label_separator = ""
contact_form = SQLFORM.factory(formstyle = settings.get_ui_formstyle(),
submit_button = T("Submit"),
labels = labels,
separator = "",
table_name = "contact", # Dummy table name
_id="mailform",
*fields
)
if contact_form.accepts(request.post_vars,
current.session,
formname="contact_form",
keepvalues=False,
hideerror=False):
# Processs Contact Form
form_vars = contact_form.vars
sender = "%s <%s>" % (form_vars.name, form_vars.address)
result = current.msg.send_email(to=request_email,
sender=sender,
subject=form_vars.subject,
message=form_vars.message,
reply_to=form_vars.address,
)
if result:
response.confirmation = "Thank you for your message - we'll be in touch shortly"
if s3.cdn:
if s3.debug:
s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js")
else:
s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js")
else:
if s3.debug:
s3.scripts.append("/%s/static/scripts/jquery.validate.js" % request.application)
else:
s3.scripts.append("/%s/static/scripts/jquery.validate.min.js" % request.application)
validation_script = '''
$('#mailform').validate({
errorClass:'req',
rules:{
name:{
required:true
},
address: {
required:true,
email:true
},
subject:{
required:true
#.........这里部分代码省略.........
示例11: create
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def create():
import os
form = SQLFORM.factory(db.msg,
Field('attachment', 'upload',
uploadfolder=os.path.join(request.folder, 'uploads')),
Field('tags', label='Search tags'),
Field('groups', label='Search groups'),
hidden=dict(tags_new=None, groups_new=None),
table_name='msg_attachment')
form.element(_name='tags')['_onkeyup'] = "showtags()"
form.element(_name='tags')['_autocomplete'] = 'off'
form.element(_name='groups')['_onkeyup'] = "showgroups()"
form.element(_name='groups')['_autocomplete'] = 'off'
tags = db(db.tag.name != 'Late').select(db.tag.id, db.tag.name).json()
groups = db().select(db.auth_group.id, db.auth_group.role).json()
if form.accepts(request.vars, session):
contact = get_contact(auth.user)
form.vars.created_by = contact.id
msg_id = db.msg.insert(**db.msg._filter_fields(form.vars))
form.vars.msg_id = msg_id
subject = form.vars.subject
if request.vars.attachment != '':
db.msg_attachment.msg_id.default = msg_id
db.msg_attachment.attach_by.default = contact.id
filename = request.vars.attachment.filename
form.vars.filename = filename
form.vars.attachment_type = filename[filename.rindex('.') + 1:]
msg_attachment_id = db.msg_attachment.insert(
**db.msg_attachment._filter_fields(form.vars))
dbutils.log_event(db, user_id=auth.user.id, item_id=msg_attachment_id,
table_name='msg_attachment', access='create',
details=','.join([subject, filename, `msg_id`]))
if request.vars.tags_new:
select_tags = request.vars.tags_new.split(',')[:-1]
for tag in select_tags:
id = db.msg_tag.insert(msg_id=msg_id, tag_id=int(tag[4:]))
tag_id = int(tag[4:])
tag = db.tag[tag_id].name
dbutils.log_event(db, user_id=auth.user.id, item_id=id,
table_name='msg_tag', access='create',
details=','.join([subject, tag]))
if request.vars.groups_new:
select_groups = request.vars.groups_new.split(',')[:-1]
for group in select_groups:
id = db.msg_group.insert(msg_id=msg_id, group_id=int(group[4:]),
assigned_by=auth.user.id)
dbutils.log_event(db, user_id=auth.user.id, item_id=id,
table_name='msg_group', access='create',
details=','.join([subject, group]))
dbutils.log_event(db, user_id=auth.user.id, item_id=msg_id,
table_name='msg', access='create')
session.flash = T('Message successfully created.')
redirect(URL('index'))
return dict(form=form, json=SCRIPT('var tags=%s; var groups=%s'
% (tags, groups)))
示例12: test_factory
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def test_factory(self):
factory_form = SQLFORM.factory(Field('field_one', 'string', IS_NOT_EMPTY()),
Field('field_two', 'string'))
self.assertEqual(factory_form.xml()[:5], b'<form')
示例13: index
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def index():
"""
This method has two functionalities:
1. Asks the user if he permits that a 3rd party app access his data
2. Receives the user's answer and redirect the user to the 3rd party
correspondant URI
In case of error, it redirects to the 'error' controller.
Of course, you can modify this behavior. For instance, you may want return
a JSON or HTTP error instead.
The request MUST be like this:
http://[your_server]{:port}/[your_application]/auth?
client_id=[your_client_id]&
redirect_uri=[your_callback_uri]&
response_type=code&
access_type=online
NOTE: You can pass a "scope" parameter, but you need to configure it at the
OAuth2 object constructor.
"""
from oauth.storage import web2pyStorage as storage # change to MongoStorage if you aren't using DAL
storage = storage()
storage.connect()
oauth = OAuth2(storage)
# Validates GET parameters
params = dict()
success = False
# try:
params = oauth.validate_authorize_params(request.get_vars)
# except Exception as ex:
# redirect(URL(c='error', vars=dict(msg=ex)))
error = []
client_id = params.get("client_id", error.append("No client_id"))
redirect_uri = params.get("redirect_uri", error.append("No redirect_uri"))
scope = params.get("scope", None)
response_type = params.get("response_type", error.append("No response_type"))
access_type = params.get("access_type", error.append("No access_type"))
"""
if error:
print 'KeyError(s): {0}'.format(', '.join(error))
"""
approval_form = SQLFORM.factory(submit_button="Yes")
approval_form.add_button("No", redirect_uri + "#error=access_denied")
if approval_form.process().accepted:
user_id = "501faa19a34feb05890005c9" # Change to `auth.user` for web2py
code = oauth.storage.add_code(client_id, user_id, oauth.config[oauth.CONFIG_CODE_LIFETIME])
redirect(redirect_uri + "?code={code}".format(code=code))
url = "?client_id={client_id}&redirect_uri={redirect_uri}"
url += "&response_type={response_type}&access_type={access_type}"
url = url.format(
client_id=client_id, redirect_uri=redirect_uri, response_type=response_type, access_type=access_type
)
return locals()
示例14: LABEL
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
LABEL("check1", _width="65%"),
LABEL("", _width="25%"),
INPUT(_type="checkbox", _name="myvar", _width="10%"),
LABEL("check1", _width="65%"),
LABEL("", _width="25%"),
INPUT(_type="checkbox", _name="myvar", _width="10%"),
LABEL("check1", _width="65%"),
TEXTAREA("hola!", _name="mytextarea", _width="100%"),
"hola3!",
INPUT(_type="submit", _name="submit"),
)
elif "--sqlform" in sys.argv:
form = SQLFORM.factory(
Field("test", "string", requires=IS_NOT_EMPTY(), comment="some data"),
Field("test1", "string", requires=IS_NOT_EMPTY(), comment="some data"),
Field("test2", "string", requires=IS_NOT_EMPTY(), comment="some data"),
Field("test3", "string", requires=IS_NOT_EMPTY(), comment="some data"),
formname=None,
)
elif "--object" in sys.argv:
form = OBJECT(
TAG.PARAM(_name="label", _value='"test"'),
TAG.PARAM(_name="name", _value='"btnTest"'),
_class="Button",
_width="100%",
_height="80%",
)
else:
raise RuntimeError("please use\npython forms_example.py --login, --form or --sqlform")
form_xml = BODY(
示例15: test_factory
# 需要导入模块: from gluon.sqlhtml import SQLFORM [as 别名]
# 或者: from gluon.sqlhtml.SQLFORM import factory [as 别名]
def test_factory(self):
factory_form = SQLFORM.factory(Field('field_one', 'string', IS_NOT_EMPTY()),
Field('field_two', 'string'))
self.assertEqual(factory_form.xml(), b'<form action="#" enctype="multipart/form-data" method="post"><table><tr id="no_table_field_one__row"><td class="w2p_fl"><label class="" for="no_table_field_one" id="no_table_field_one__label">Field One: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_one" name="field_one" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="no_table_field_two__row"><td class="w2p_fl"><label class="" for="no_table_field_two" id="no_table_field_two__label">Field Two: </label></td><td class="w2p_fw"><input class="string" id="no_table_field_two" name="field_two" type="text" value="" /></td><td class="w2p_fc"></td></tr><tr id="submit_record__row"><td class="w2p_fl"></td><td class="w2p_fw"><input type="submit" value="Submit" /></td><td class="w2p_fc"></td></tr></table></form>')