本文共 5343 字,大约阅读时间需要 17 分钟。
直接把之后的一些功能都贴出来吧,都是一些简单的小功能,理解一个之后其他的也就都懂了
"""modify修改一个礼品的信息,仓库管理员可操作,但不可修改其状态值以及打折、热度情况method:PUT"""def modify(request, employee_id): employee = Employee.objects.get(pk=employee_id) context = { 'error': 0 } if (not employee) or ('EMPLOYEE_ID' not in request.session) or ('IS_LOGIN' not in request.session) \ or (request.session['EMPLOYEE_ID'] != employee_id): context['error'] = 1 return HttpResponse(json.dumps(context), content_type="application/json") if request.method == 'PUT': modify = QueryDict(request.body) id = modify.get('id') present = Present.objects.filter(id=id) if not present or present[0].pdepot != Depot.objects.get(manager=employee): context['error'] = 2 return HttpResponse(json.dumps(context), content_type="application/json") status = present[0].status name = modify.get('name') introduction = modify.get('introduction') on_date = modify.get('on_date') store_num = modify.get('store_num') cost = modify.get('cost') hot = present[0].hot off = present[0].off off_cost = present[0].off_cost url = modify.get('url') pdepot = present[0].pdepot present.update(name=name, introduction=introduction, status=status, on_date=on_date, store_num=store_num, cost=cost, hot=hot, off=off, off_cost=off_cost, url=url, pdepot=pdepot) conx = serializers.serialize("json", present) return HttpResponse(conx, content_type="application/json")
"""delete删除一个礼品,仅仓库管理员可操作method:DELETE"""def delete(request, employee_id): employee = Employee.objects.get(pk=employee_id) context = { 'error': 0 } if (not employee) or ('EMPLOYEE_ID' not in request.session) or ('IS_LOGIN' not in request.session) \ or (request.session['EMPLOYEE_ID'] != employee_id): context['error'] = 1 return HttpResponse(json.dumps(context), content_type="application/json") if request.method == 'DELETE': delete = QueryDict(request.body) key = delete.get('id') present = Present.objects.filter(id=key) if not present or present[0].pdepot != Depot.objects.get(manager=employee): context['error'] = 2 return HttpResponse(json.dumps(context), content_type="application/json") conx = serializers.serialize("json", present) present.delete() return HttpResponse(conx, content_type="application/json")
"""sell修改一个礼品的状态值,即上架或下架该礼品,以及修改其打折、热度情况,仅普通员工可操作method:PUT"""def sell(request, employee_id): employee = Employee.objects.get(pk=employee_id) context = { 'error': 0 } if (not employee) or ('EMPLOYEE_ID' not in request.session) or ('IS_LOGIN' not in request.session) \ or (request.session['EMPLOYEE_ID'] != employee_id): context['error'] = 1 return HttpResponse(json.dumps(context), content_type="application/json") # 修改礼品的状态、热度及折扣信息请求 if request.method == 'PUT': sell = QueryDict(request.body) key = sell.get('id') present = Present.objects.filter(id=key) if not present: context['error'] = 2 return HttpResponse(json.dumps(context), content_type="application/json") name = present[0].name introduction = present[0].introduction on_date = present[0].on_date store_num = present[0].store_num status = sell.get('status') cost = present[0].cost hot = sell.get('hot') off = sell.get('off') off_cost = sell.get('off_cost') url = present[0].url pdepot = present[0].pdepot present.update(name=name, introduction=introduction, status=status, on_date=on_date, store_num=store_num, cost=cost, hot=hot, off=off, off_cost=off_cost, url=url, pdepot=pdepot) conx = serializers.serialize("json", present) return HttpResponse(conx, content_type="application/json") # 返回礼品请求 if request.method == 'GET': depots = QueryDict(request.body) key1 = depots.get('depot_id') key2 = depots.get('present_status') # 返回某一个仓库礼品请求 if key1: depot = Depot.objects.get(id=key1) presents = Present.objects.filter(pdepot=depot) conx = serializers.serialize("json", presents) return HttpResponse(conx, content_type="application/json") # 根据状态返回礼品请求 if key2: # 返回上架礼品 if key2 == '1': presents = Present.objects.filter(status=key2) conx = serializers.serialize("json", presents) return HttpResponse(conx, content_type="application/json") # 返回待审核礼品 elif key2 == '0': presents = Present.objects.filter(status=key2) conx = serializers.serialize("json", presents) return HttpResponse(conx, content_type="application/json") # 返回未上架礼品 elif key2 == '2': presents = Present.objects.filter(status=key2) conx = serializers.serialize("json", presents) return HttpResponse(conx, content_type="application/json")
转载地址:http://baprn.baihongyu.com/