时间处理
来源:互联网 发布:美国mac口红海淘攻略 编辑:程序博客网 时间:2024/06/10 17:12
5-11 代码总结
一 . 将数据库中的运单的信息显示在一个表格里
@route('/manager/waybill/manage')class WaybillManageHandler(BaseHandler): def get(self): # 获取所有的运单信息 all_waybills = self.db.Waybill.find({ "status": 0 }) # 获取开始时间和终止时间 data = [] for i in all_waybills: tmp_dict = {} a = time.localtime(i["createtime"]) tmp_dict["createtime"] = str(a.tm_year) + "-" + str(a.tm_mon) + "-" + str(a.tm_mday) + "/" + str(a.tm_hour) + ":" + str(a.tm_min) + ":" + str(a.tm_sec) a = time.localtime(i["arrivaltime"]) tmp_dict["arrivaltime"] = str(a.tm_year) + "-" + str(a.tm_mon) + "-" + str(a.tm_mday) + "/" + str(a.tm_hour) + ":" + str(a.tm_min) + ":" + str(a.tm_sec) tmp_dict["destination"] = i["destination"] tmp_dict["origin"] = i["origin"] tmp_dict["status" ] = i["status"] tmp_dict["freight"] = self.db.Freight.find_one({"_id":i["freight"]})["freight"] tmp_dict["user"] = self.db.User.find_one({"_id":i["user"]})["contact"] b = i["content"]["name"] c = i["content"]["count"] tmp_dict["content"] = str(b) + "-" + str(c) data.append(tmp_dict) return self.render("waybill-manage.html", data=data, all_waybills=all_waybills)
1.根据运单的状态从数据库中取出status=0的全部运单信息
2. 首先将通过循环将运单信息依次处理,通过虚构一个字典放入将要展示在前端的数据
3. 依次处理要显示在页面的运单信息
1)数据createtime , arrivaltime
将时间戳转换成时间: 通过 time.local(所得时间戳) 可有,a = time.localtime(i["createtime"]) (ps: arrivaltime方法一样) 通过字符串连接处理所得数据 tmp_dict["createtime"] = str(a.tm_year) + "-" + str(a.tm_mon) + "-" + str(a.tm_mday) + "/" + str(a.tm_hour) + ":" + str(a.tm_min) + ":" + str(a.tm_sec)
2)表Waybills直接存储的数据,无需转换,只需依次给字典赋值
tmp_dict["destination"] = i["destination"] tmp_dict["origin"] = i["origin"] tmp_dict["status" ] = i["status"]
3)取出与其他表相关联的数据
tmp_dict["user"] = self.db.User.find_one({"_id":i["user"]})["contact"] b = i["content"]["name"] c = i["content"]["count"] tmp_dict["content"] = str(b) + "-" + str(c) 通过 _id 找到与该数据相关联的数据表,再通过键值对获得所需数据
二. 页面搜索框实现通过 origin, destination 对表格内容的搜索
@route('/manager/waybill/find')
class WaybillFindHandler(BaseHandler):
def get(self): origin = self.get_argument("origin") destination = self.get_argument("destination") _filter = {"$and":[{"origin": origin},{"destination": destination},{"status": 0}]} if origin == "" and destination == "": #显示所有 return self.redirect('/manager/waybill/manage') if origin == "" and destination != "": #显示特定目的地 _filter = {"$and":[{"destination": destination},{"status": 0}]} if origin != "" and destination == "": _filter = {"$and":[{"origin":origin}, {"status": 0}]} all_waybills = self.db.Waybill.find(_filter) data = [] if all_waybills.count() != 0: for i in all_waybills: tmp_dict = {} a = time.localtime(i["createtime"]) tmp_dict["createtime"] = str(a.tm_year) + "-" + str(a.tm_mon) + "-" + str(a.tm_mday) + "/" + str(a.tm_hour) + ":" + str(a.tm_min) + ":" + str(a.tm_sec) a = time.localtime(i["arrivaltime"]) tmp_dict["arrivaltime"] = str(a.tm_year) + "-" + str(a.tm_mon) + "-" + str(a.tm_mday) + "/" + str(a.tm_hour) + ":" + str(a.tm_min) + ":" + str(a.tm_sec) tmp_dict["destination"] = i["destination"] tmp_dict["origin"] = i["origin"] tmp_dict["status" ] = i["status"] tmp_dict["freight"] = self.db.Freight.find_one({"_id":i["freight"]})["freight"] tmp_dict["user"] = self.db.User.find_one({"_id":i["user"]})["contact"] b = i["content"]["name"] c = i["content"]["count"] tmp_dict["content"] = str(b) + "-" + str(c) data.append(tmp_dict) return self.render("waybill-manage.html", data=data, all_waybills=all_waybills, errcode=0) else: return self.render("waybill-manage.html", data=data, errcode=1)
1.通过self.get_argument(“name”)获得已选的出发地,目的地
origin = self.get_argument("origin") destination = self.get_argument("destination")
2. 通过 判断 origin,destination的值来将搜索内容进行分类,
1)origin != "" and destination != "" #显示所有 _filter = {"$and":[{"origin":origin},{"destination":destination},{"status":0}]}2) origin != "" and destination == "" #显示特定目的地 _filter = {"$and":[{"origin":origin},{"status":0}]}3)origin == "" and destination != "" #显示特定目的地 _filter = {"$and":[{"destination":destination},{"status":0}]}
3. 将搜索条件分类完毕,通过它获得取出数据库中的全部搜索内容
all_waybills = self.db.Waybill.find(_filter)
4. 最后获得了搜索的全部运单信息。操作就回到了将一个数据表单展示在前端页面的工作,具体如上(一)
0 0
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 时间处理
- 嵌入式视频方案学习第四篇——系统基本控制
- opencv:通道分离—split()函数
- 关于微信支付(H5获取openid)
- ubuntu16.04安装搜狗输入法
- HihoCoder第四周(Trie图)
- 时间处理
- opencv:通道合并—merge()函数
- 389. Find the Difference --字符串的共同字符
- C++第六次作业-数组操作、字符串操作
- opencv:图像对比度、亮度值调整(理论基础)
- Node.js中使用nextTick来调度工作
- 关于java多线程浅析三:每个对象都有的方法
- opencv:离散傅里叶变换
- 调整Linux的网络栈(Buffer Size)来提升网络性能