本文整理汇总了Python中gluon.SQLFORM类的典型用法代码示例。如果您正苦于以下问题:Python SQLFORM类的具体用法?Python SQLFORM怎么用?Python SQLFORM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SQLFORM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create():
org = db.organization(session.org_id)
tbl = db.desk
tbl.item_list.readable = False
tbl.item_list.writable = False
tbl.name.requires = IS_NOT_EMPTY()
form = SQLFORM(db.desk)
form.add_button(T('Cancel'), URL('org', 'view', args=[org.id]))
if form.process().accepted:
# add the new desk to the org list
desk_id = form.vars.id
# add current users as the one with permission to update manage
# this desk
auth.add_permission(
auth.user_group(auth.user.id),
'update',
db.desk,
desk_id)
desk_list = org.desks
desk_list.insert(0, desk_id)
org.update_record(desks=desk_list)
# return to the org desk list
redirect(URL('org', 'view', args=[org.id]))
return locals()
示例2: venda
def venda():
if not session.flashed:
response.flash = T('Bem vindo a tela de vendas!')
title = "Venda"
####SQL####################################################
#######################################################
#aqui ele formata tudo sozinho e ainda envia para o banco sozinho também
#mas não mostra a mensagem de falha ou aceitação sozinho
venda_sqlform = SQLFORM(db2.venda)
if venda_sqlform.accepts(request,session):
response.flash = 'Form accepted'
formulario = db2().select(db2.venda.ALL).last()
fecha_venda(formulario)
elif venda_sqlform.errors:
response.flash = 'Form has errors'
else:
response.flash = 'Please fill the form'
form_venda = detalhes_geral(db2.venda, 2)
(form_crud,table_crud) = pesquisa_geral(db2.venda)
return locals()
示例3: getEditgameUpdateForm
def getEditgameUpdateForm (game):
"""
Gets an update for the edit game page.
Keyword Arguments:
game -- row representing the current game
Return Values:
formUpdate -- web2py form
"""
from gluon import current, redirect, URL, SQLFORM
db = current.db
#Hide some fields of the form
hideFields (db.game, ['id', 'host_id', 'game_status', 'password'])
formUpdate = SQLFORM(db.game, game.id)
formUpdate.add_class('assassins-form')
if formUpdate.process().accepted:
resizeImage(db.game, game.id)
redirect(getUrl('edit', game.id))
return formUpdate
示例4: inserir
def inserir():
u"""Permite inserir um novo registro.
Um registro pode ser:
- Uma notícia;
- Um evento;
- Um produto;
- Um membro;
- Um apoiador.
Observação: Somente usuários com permissão de admin podem inserir novos
membros e apoiadores.
"""
argumento = current.request.args(0) or redirect(URL('default', 'index'))
lista_tabelas = ['noticias', 'eventos', 'produtos']
auth = current.globalenv['auth']
db = current.globalenv['db']
if auth.has_membership('admin'):
lista_tabelas.extend(['membros', 'apoiadores'])
if argumento not in lista_tabelas:
current.session.flash = current.T(
'Operação não permitida a seu usuário.'
)
redirect(URL('admin', 'listar', args='noticias'))
form = SQLFORM(
db[argumento], submit_button="Enviar",
formstyle='bootstrap3_stacked')
if form.process().accepted:
current.response.flash = 'Registro inserido com sucesso!'
elif form.errors:
current.response.flash = 'Formulário contem erros'
return {'argumento': argumento, 'form': form}
示例5: editform
def editform():
"""
Return a sqlform object for editing the specified slide.
"""
sid = session.plugin_slider_sid
form = SQLFORM(db.plugin_slider_slides, sid,
separator='',
deletable=True,
showid=True)
if form.process(formname='plugin_slider_slides/{}'.format(sid)).accepted:
response.flash = 'The changes were recorded successfully.'
elif form.errors:
print('\n\nlistandedit form errors:')
pprint({k: v for k, v in form.errors.items()})
print('\n\nlistandedit form vars')
pprint({k: v for k, v in form.vars.items()})
print('\n\nlistandedit request vars')
pprint({k: v for k, v in request.vars.items()})
response.flash = 'Sorry, there was an error processing ' \
'the form. The changes have not been recorded.'
else:
pass
return form
示例6: create
def create():
"""Create a new organization"""
tbl = db.organization
tbl.users.readable = False
tbl.users.writable = False
tbl.desks.readable = False
tbl.desks.writable = False
tbl.name.requires = [
IS_NOT_EMPTY(
error_message=T("Cannot be empty")
),
IS_NOT_IN_DB(
db,
'organization.name',
error_message=T(
"An Organization witch that name is allready in nStock"))]
form = SQLFORM(tbl)
form.add_button(T('Cancel'), URL('index'))
if form.process().accepted:
# add the new organization
g_id = auth.user_group(auth.user.id)
# give the user all perms over this org
auth.add_permission(g_id, 'update', tbl, form.vars.id)
auth.add_permission(g_id, 'read', tbl, form.vars.id)
auth.add_permission(g_id, 'delete', tbl, form.vars.id)
redirect(URL('index'))
return locals()
示例7: vendedor
def vendedor():
title = "Cadastro de Vendedores"
#lista todos os carros na tela
vendedor_grid = SQLFORM.smartgrid(db2.vendedor)
#CRUD
#aqui ele formata tudo sozinho e ainda envia para o banco sozinho também
#mostra a mensagem de falha sozinho
vendedor_crud = crud.create(db2.vendedor)
####SQL####################################################
#######################################################
#aqui ele formata tudo sozinho e ainda envia para o banco sozinho também
#mas não mostra a mensagem de falha ou aceitação sozinho
vendedor_sqlform = SQLFORM(db2.vendedor)
if vendedor_sqlform.accepts(request,session):
response.flash = 'Form accepted'
elif vendedor_sqlform.errors:
response.flash = 'Form has errors'
else:
response.flash = 'Please fill the form'
form_vendedor = detalhes_geral(db2.vendedor, 1)
(form_crud,table_crud) = pesquisa_geral(db2.vendedor)
return locals()
示例8: inserir
def inserir():
"""Insere um novo banner."""
db = current.globalenv['db']
form = SQLFORM(
db.carousel, submit_button="Enviar",
formstyle='bootstrap3_stacked')
if form.process().accepted:
current.response.flash = 'Registro inserido com sucesso!'
elif form.errors:
current.response.flash = 'Formulário contem erros'
return {'form': form}
示例9: detalhes_geral
def detalhes_geral(tabela, tb_id):
registro_geral = tabela(tb_id) or redirect(URL('Inicio'))
form_geral =SQLFORM(tabela,registro_geral,deletable=True,upload=URL('veiculo','download'))
if form_geral.accepts(request.vars,session):
response.flash = 'Sucesso'
elif form_geral.errors:
response.flash = 'Erro'
return form_geral
示例10: edit
def edit():
desk = db.desk(request.args(0))
session.desk_id = desk.id
db.desk.item_list.readable = False
db.desk.item_list.writable = False
form = SQLFORM(db.desk, record=desk, showid=False)
if form.process().accepted:
redirect(URL('index', args=[desk.id]))
return locals()
示例11: edit
def edit():
org = db.organization(request.args(0))
tbl = db.organization
tbl.users.readable = False
tbl.users.writable = False
tbl.desks.readable = False
tbl.desks.writable = False
tbl.name.requires = [IS_NOT_EMPTY()]
# edit form
form = SQLFORM(db.organization, record=org, showid=False)
if form.process().accepted:
redirect(URL('view', args=[org.id]))
return locals()
示例12: bulk_update
def bulk_update():
"""
Controller function to perform a programmatic update to a field in one table.
"""
response = current.response
db = current.db
myrecs = None
form = SQLFORM.factory(
Field('table', requires=IS_IN_SET(db.tables)),
Field('field'),
Field('query'),
Field('new_value'))
if form.process().accepted:
query = eval(form.vars.query)
try:
recs = db(query)
recs.update(**{form.vars.field: form.vars.new_value})
myrecs = recs.select()
response.flash = 'update succeeded'
except Exception:
print traceback.format_exc(5)
elif form.errors:
myrecs = BEAUTIFY(form.errors)
response.flash = 'form has errors'
return form, myrecs
示例13: send_email
def send_email():
title = 'Contato'
form = SQLFORM.factory(
Field('name', requires=IS_NOT_EMPTY()),
Field('email', requires =[ IS_EMAIL(error_message='invalid email!'), IS_NOT_EMPTY() ]),
Field('subject', requires=IS_NOT_EMPTY()),
Field('message', requires=IS_NOT_EMPTY(), type='text')
)
if form.process().accepted:
session.name = form.vars.name
session.email = form.vars.email
session.subject = form.vars.subject
session.message = form.vars.message
x = mails.send(to=['[email protected]'],
subject='loja de carros',
message= "Olá esse é um email de teste da lja de carros.\nName:"+ session.name+" \nEmail : " + session.email +"\nSubject : "+session.subject +"\nMessage : "+session.message+ ".\n "
)
if x == True:
response.flash = 'email sent sucessfully.'
else:
response.flash = 'fail to send email sorry!'
#response.flash = 'form accepted.'
elif form.errors:
response.flash='form has errors.'
form_carro = detalhes_geral(db2.carro, 2)
(form_crud,table_crud) = pesquisa_geral(db2.carro)
return locals()
示例14: handle_upload
def handle_upload(self):
"""
Get an upload from CKEditor and returns the new filename.
Get an upload from CKEditor and returns the new filename that
can then be inserted into a database. Returns (new_filename,
old_filename, length, mime_type)
"""
upload = current.request.vars.upload
path = os.path.join(current.request.folder, 'uploads')
if upload is not None:
if hasattr(upload, 'file'):
form = SQLFORM.factory(
Field('upload', 'upload', requires=IS_NOT_EMPTY(),
uploadfs=self.settings.uploadfs,
uploadfolder=path),
table_name=self.settings.table_upload_name,
)
old_filename = upload.filename
new_filename = form.table.upload.store(upload.file,
upload.filename)
if self.settings.uploadfs:
length = self.settings.uploadfs.getsize(new_filename)
else:
length = os.path.getsize(os.path.join(path, new_filename))
mime_type = upload.headers['content-type']
return (new_filename, old_filename, length, mime_type)
else:
raise HTTP(401, 'Upload is not proper type.')
else:
raise HTTP(401, 'Missing required upload.')
示例15: projeto
def projeto():
u"""Editar informações sobre o projeto marolo.
Permite que um usuário com permissão de admin edite as informações sobre
o projeto.
"""
path = os.path.dirname(os.path.abspath(__file__))
with open(path + '/../views/default/sobre_projeto.html', 'r') as arq:
sobre_projeto = arq.read()
ckeditor = current.globalenv['ckeditor']
form = SQLFORM.factory(
Field(
'texto',
'text',
widget=ckeditor.widget,
default=sobre_projeto,
requires=IS_NOT_EMPTY()
),
hideerror=True,
message_onfailure=current.T('O conteúdo não pode ser vazio.')
)
form.elements('label', replace=None)
if form.process().accepted:
with open(path + '/../views/default/sobre_projeto.html',
'w') as arq:
arq.write(form.vars.texto)
current.session.flash = current.T(
'Sobre o projeto editado com sucesso!'
)
redirect(URL('admin', 'listar', args='noticias'))
return {'form': form}