def addTable(request): res = StatusCode.OK() table = request.POST.get("table") table_collection = db.table table_collection.insert(table) res['data'] = table return JsonResponse(res, json_dumps_params={'default': json_util.default, 'ensure_ascii': False})
def addData(request): res = StatusCode.OK() data = {} label = request.POST.get("label") venue = request.POST.get("venue") item = request.POST.get("item") item = json.loads(item) # ri!! 踩了好多坑:前端:let data_obj = new FormData(); # for(i=0; i<this.imgList.length; i++) # { # data_obj.append("imgList[]", this.imgList[i].file); # } imgList = request.FILES.getlist("imgList[]") imgPath = [] for i in range(len(imgList)): fname = os.path.join(settings.MEDIA_ROOT, imgList[i].name) furl = settings.MEDIA_URL + imgList[i].name imgPath.append(furl) with open(fname, 'wb') as pic: for c in imgList[i].chunks(): pic.write(c) data["label"] = label data["venue"] = venue data["item"] = item data['imgList'] = imgPath data['videoList'] = [] data_collection = db.data data_collection.insert(data) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def delLabel(request, labelName): res = StatusCode.OK() venue_collection = db.venue venue_collection.update_one({"label": labelName}, {"$set": {"status": 0}}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def deleteUser(request, username): res = StatusCode.OK() user_collection = db.user user_collection.delete_one({"username": username}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def getTableByLabelName(request, labelName): res = StatusCode.OK() table_collection = db.table table = table_collection.find_one({"label": labelName}) res['data'] = table return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def addLabel(request): res = StatusCode.OK() labelName = request.POST.get("label") venue_collection = db.venue venue_collection.insert({"label": labelName, "venues": [], "status": 1}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def getDataByLabel(request, labelName): res = StatusCode.OK() data_collection = db.data datas = list(data_collection.find({"label": labelName})) res["data"] = datas return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def getUsers(request): res = StatusCode.OK() user_collection = db.user users = list(user_collection.find()) res["data"] = users return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def updateUser(request, username): res = StatusCode.OK() user = request.POST.get("user") user = json.loads(user) user_collection = db.user user_collection.update_one({"username": username}, {"$set": user}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def addUser(request): res = StatusCode.OK() user = request.POST.get("user") user = json.loads(user) user_collection = db.user user_collection.insert(user) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def deleteData(request, labelName, venueName, itemName): res = StatusCode.OK() data_collection = db.data data_collection.delete_one({ "label": labelName, "venue": venueName, "item.name": itemName }) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def addVenueByLabel(request): res = StatusCode.OK() labelName = request.POST.get("label") venueName = request.POST.get("venue") venue_collection = db.venue venue_collection.update_one({"label": labelName}, {"$push": { "venues": venueName }}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def modifyVenue(request, labelName, originVenueName, venueName): res = StatusCode.OK() venue_collection = db.venue venue_collection.update_one({"label": labelName}, {"$pull": { "venues": originVenueName }}) venue_collection.update_one({"label": labelName}, {"$push": { "venues": venueName }}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def login(request): # 未登录用户执行以下登录操作 if request.method == 'POST': result = {} username = request.POST.get("username") password = md5(request.POST.get("password")) user_collection = db.user user = user_collection.find_one({ 'username': username, 'password': password }) if user: if user['role'] == '普通用户': result = StatusCode.ACCESSERROR() response = JsonResponse(result, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False }) return response token = md5(username + str(time.time())) user['token'] = token user_collection.update({ 'username': username, 'password': password }, user) result = StatusCode.OK() response = JsonResponse(result, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False }) response.set_cookie("username", username, expires=60 * 60 * 2) response.set_cookie("token", token, expires=60 * 60 * 2) return response else: result = StatusCode.LOGINERROR() response = JsonResponse(result, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False }) return response return render(request, 'login.html') # 跳转到登录页面
def updateData(request, labelName, venueName, itemName): res = StatusCode.OK() data = {} labelName = request.POST.get("label") venueName = request.POST.get("venue") item = request.POST.get("item") item = json.loads(item) imgOldList = json.loads(request.POST.get("imgOldList")) # # ri!! 踩了好多坑:前端:let data_obj = new FormData(); # # j for(i=0; i<this.imgList.length; i++) # # { # # data_obj.append("imgList[]", this.imgList[i].file); # # } # imgList = request.FILES.getlist("imgList[]") imgPath = [] for i in range(len(imgOldList)): imgPath.append(imgOldList[i]) for i in range(len(imgList)): fname = os.path.join(settings.MEDIA_ROOT, imgList[i].name) furl = settings.MEDIA_URL + imgList[i].name imgPath.append(furl) with open(fname, 'wb') as pic: for c in imgList[i].chunks(): pic.write(c) data["label"] = labelName data["venue"] = venueName data["item"] = item data['imgList'] = imgPath data['videoList'] = [] data_collection = db.data data_collection.update_one( { "label": labelName, "venue": venueName, "item.name": itemName }, {"$set": data}) return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })
def searchData(request): res = StatusCode.OK() venueName = request.GET.get("venue") # 展馆名称 itemName = request.GET.get("item") # 展品名称 data_collection = db.data datas = list( data_collection.find({ "venue": { "$regex": venueName }, "item.name": { "$regex": itemName } })) res['length'] = len(datas) res['data'] = datas return JsonResponse(res, json_dumps_params={ 'default': json_util.default, 'ensure_ascii': False })