build a little database test in zope

1.go to http://localhost:2001/manage and add Z SQL Method which is named zsqltest
argument:
   user_name
    date1
   date2

select * from  user_assets where user_name=<dtml-sqlvar user_name type="string">
and date>=to_date(<dtml-sqlvar date1 type="string">,'yyyy-MM-dd')
 and date<to_date(<dtml-sqlvar date2 type="string">,'yyyy-MM-dd')+1


2.add
Script (Python)
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

p_date = context.REQUEST.get('Dd_reachdate', '')
p_date_e = context.REQUEST.get('Dd_reachdate_e', '')
myusername = context.REQUEST.get('username', '')
 

RESPONSE.setHeader("Cache-Control","no-store");

RESPONSE.setHeader("Content-Type","text/html;charset=utf-8");

from DateTime import DateTime
 
now = DateTime()




today=now.strftime('%Y-%m-%d')

yday=(now-3).strftime('%Y-%m-%d')
if p_date=='':
    p_date=yday
if p_date_e=='':
    p_date_e=today
 

print "<html><head><meta http-equiv=/"Content-Type/" content=/"text/html;charset=utf-8/" />"
print "</head><body  bgColor=#F3FAFF>"
 

print "<form name=form2 action=selectzc.py>"
print "<input   type=/"hidden/"   name=/"username/" value=/""+myusername+"/"  >"
print "begin time :<input   type=/"text/"   name=/"Dd_reachdate/" value=/""+p_date+"/"  ><br>"
print "end time :<input  type=/"text/"   name=/"Dd_reachdate_e/" value=/""+p_date_e+"/"  > "
print "<p><input type=/"submit/" value=/"search/"></p>"
print "</form>"

 
 
selectzcsql=container['selectzc.sql']


 

print "<table border=1> <tr><td>f1</td><td>f2</td><td>f3</td><td>f4</td><td>f5</td><td>f6</td><td>f7</td><td> f8</td> </tr>"

for f in  selectzcsql(user_name=myusername,date1=p_date,date2=p_date_e):
    print " <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (f['user_name'],f['date'],f['beginning'],f['stock'],f['bond'],f['warrant'],f['present'],f['profit_and_loss'])
 
print "</table>"

print "</body></html>"
 

return printed

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值