求助全能的CU大侠们,web.py的自定义验证解决了,可是又出现sqlite数据库提交错误
时间:2011-01-21
来源:互联网
本帖最后由 hlsd665 于 2011-01-22 00:08 编辑
官网上给的代码如下:
复制代码
我想把验证用的lambda表达式换成自己定义的方法,用于验证输入框中提交的数据在数据库中的重复
复制代码
验证方法m_account.validclient带有参数,按照原有lambda表达式能看出来只能给一个参数,应该是表单对象
可是象上面的方法调用时无论验证方法返回什么值,都不会通过验证。
万能的CU大侠们给看看。难死我了。拜谢了。
官网上给的代码如下:
- vpass = web.form.regexp(r".{3,20}$", '密码长度3到20位字符')
- register_form = web.form.Form(
- web.form.Textbox("username", description="用户名"),
- web.form.Password("password", vpass, description="密 码"),
- web.form.Password("password2", description="密 码"),
- web.form.Button("submit", type="submit",html="添加"),
- validators = [
- web.form.Validator("两次密码不一致", lambda i: i.password == i.password2)]
- )
- client_form = web.form.Form(
- web.form.Textbox("code",web.form.notnull,description="代码"),
- web.form.Textbox("name",description="名称"),
- web.form.Button("submit",type="submit",html="添加"),
- validators = [
- web.form.Validator('代码或名称重复', m_account.validclient)]
-
- )
可是象上面的方法调用时无论验证方法返回什么值,都不会通过验证。
万能的CU大侠们给看看。难死我了。拜谢了。
作者: hlsd665 发布时间: 2011-01-21
本帖最后由 hlsd665 于 2011-01-22 00:04 编辑
自己建个验证类继承原有验证类,解决了,可是又出现数据库提交错误。是查询和提交的时间间隔太短了,还是两次调用数据库时分别建立了两个连接造成的冲突????????
错误代码如下:
复制代码
复制代码
m_account代码如下:
复制代码
自己建个验证类继承原有验证类,解决了,可是又出现数据库提交错误。是查询和提交的时间间隔太短了,还是两次调用数据库时分别建立了两个连接造成的冲突????????
错误代码如下:
- 0.0 (1): SELECT * FROM c_client WHERE years='2011' ORDER BY code
- 0.0 (2): SELECT * FROM c_client WHERE code='105'
- 0.02 (3): INSERT INTO c_client (code, name, years) VALUES ('105', '3213213', '2011')
- 0.0 (4): SELECT last_insert_rowid();
- Traceback (most recent call last):
- File "C:\Python26\lib\site-packages\web\application.py", line 242, in process
- return self.handle()
- File "C:\Python26\lib\site-packages\web\application.py", line 233, in handle
- return self._delegate(fn, self.fvars, args)
- File "C:\Python26\lib\site-packages\web\application.py", line 415, in _delegate
- return handle_class(cls)
- File "C:\Python26\lib\site-packages\web\application.py", line 390, in handle_class
- return tocall(*args)
- File "F:\workspace\dev\finance.py", line 56, in POST
- m_account.newclient(client_data.code,client_data.name,year='2011')
- File "F:\workspace\dev\model\m_account.py", line 12, in newclient
- dbh.insert('c_client',code=code,name=name,years=year)
- File "C:\Python26\lib\site-packages\web\db.py", line 744, in insert
- self.ctx.commit()
- File "C:\Python26\lib\site-packages\web\db.py", line 504, in commit
- ctx.db.commit()
- OperationalError: cannot commit transaction - SQL statements in progress
-
- 127.0.0.1:4275 - - [22/Jan/2011 00:04:04] "HTTP/1.1 POST /finance/clientsetup" - 500 Internal Server Error
- #coding:utf-8
- import web
-
- from model import m_account
-
- from web import form
- class revalid(form.Validator):
- def __init__(self,msg):
- self.msg = msg
-
- def valid(self, value):
- return m_account.recode(value)
-
- urls = (
- '/', 'index',
- '/system','system',
- '/clientsetup','clientsetup',
- )
- render = web.template.render('templates/finance',base='../base')
-
-
- class clientsetup:
- client_form = web.form.Form(
- web.form.Textbox("code",web.form.notnull,revalid('no requ'),description="代码"),
- web.form.Textbox("name",web.form.notnull,description="名称"),
- web.form.Button("submit",type="submit",html="添加")
- )
-
-
- def GET(self):
- clist=m_account.getclientlist('2011')
- f=self.client_form()
- return render.allsetup('客户',clist,'添加客户',f)
- def POST(self):
- f=self.client_form()
- clist=m_account.getclientlist('2011')
- if not f.validates():
- return render.allsetup('客户',clist,'添加客户',f)
- else:
- client_data = web.input()
- m_account.newclient(client_data.code,client_data.name,year='2011')
- raise web.seeother('/clientsetup')
- #-*-coding:utf-8-*-
-
- import web
-
- import dbcon
-
- dbh=dbcon.dbs()
-
- def getclientlist(year):
- return dbh.select('c_client',where='years=$year',order = 'code',vars=locals())
- def newclient(code,name,year):
- dbh.insert('c_client',code=code,name=name,years=year)
- def recode(code):
- return not bool(dbh.select('c_client',where='code=$code',vars=locals()))
作者: hlsd665 发布时间: 2011-01-21
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28