def findById(_id): try: _id = DB.str2ObjectId(_id) except: return None g = DB.c.myNCUT.Goods.find_one({"_id": _id}) g["_id"] = str(g["_id"]) g["time"] = str(g["time"]) return g
def getOne(id: str): ''' 根据id查询并返回一个课件字典 ''' try: cw = DB.c.myNCUT.Courseware.find_one({"_id": DB.str2ObjectId(id)}) except: return None cw["_id"] = str(cw["_id"]) return cw
def publicDownload(id: str): ''' 传入临时文件id 返回真实文件id ''' try: tempFile = DB.c.myNCUT.TempFile.find_one( {"_id": DB.str2ObjectId(id)}) except: return None if tempFile is None: return None else: return tempFile["id"]
def del_comment_id(good_id): g = DB.c.myNCUT.Goods.find_one({"_id": DB.str2ObjectId(good_id)}) if g is None: return responseError(None, 404, "找不到对应的商品") elif request.method == "POST": reply_id = request.form.get("reply_id") if reply_id == "0": reply_id = None to_openid = request.form.get("to_openid") if to_openid == "0": to_openid = None Comment.create(good_id, reply_id, Session(request.headers.get("Token")).openid, to_openid, request.form.get("content")) return responseOK() elif request.method == "GET": return responseOK(Comment.get(good_id))
def update(_id, data): try: _id = DB.str2ObjectId(_id) except: return False new = { "title": data.get("title"), "time": datetime.datetime.utcnow(), "describe": data.get("describe"), "state":int(data.get("state")), "contact": data.get("contact") } if data.get("price")is not None: new["price"] = float(data.get("price")) if data.get("photos")is not None: new["photos"] = data.get("photos").split(",") submitData = {} for k in new: if new[k]is not None: submitData[k] = new[k] DB.c.myNCUT.Goods.update_one({"_id": _id}, {"$set": submitData}) return True
from app import app from app.utils.DB import DB import sys if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "-d": debug = True else: debug = False DB.connect(debug) # app.run(host="0.0.0.0", port=8001, debug=True) app.run(host="0.0.0.0", port=8001, debug=debug)
def delete(_id): DB.c.myNCUT.Comment.delete_one({"_id": DB.str2ObjectId(_id)})
def getOne(_id): res = DB.c.myNCUT.Comment.find_one({"_id": DB.str2ObjectId(_id)}) return Comment.processComment(res)