def get(self, request): """ 获取黑名单列表 :param request: :return: """ try: page_size = int(request.GET.get("page_size", 20)) page = int(request.GET.get("page", 1)) except (TypeError, ValueError): return JsonResponse(code="999985", msg="page and page_size must be integer!") name = request.GET.get("name") if name: obi = BlackList.objects.filter(status=True).filter( CompanyName__contains=name).order_by("-id") else: obi = BlackList.objects.filter(status=True).order_by("-id") paginator = Paginator(obi, page_size) # paginator对象 total = paginator.num_pages # 总页数 try: obm = paginator.page(page) except PageNotAnInteger: obm = paginator.page(1) except EmptyPage: obm = paginator.page(paginator.num_pages) serialize = BlackListSerializer(obm, many=True) return JsonResponse(data={ "data": serialize.data, "page": page, "total": total }, code="999999", msg="成功")
def post(self, request): """ 添加公司黑名单 :param request: :return: """ data = JSONParser().parse(request) black_serializer = BlackListDeserializer(data=data) if black_serializer.is_valid(): # 保持新项目 black_serializer.save() return JsonResponse(code="999999", msg="成功") return JsonResponse(code="999998", msg="参数有误")
def post(self, request): _file = request.FILES.get("file") if not _file: return JsonResponse(code="999998", msg="参数有误") file_to_save = open( os.path.join("../data", str(int(time.time())) + _file.name), "wb+") for chunk in _file.chunks(): file_to_save.write(chunk) file_to_save.close() return JsonResponse(code="999999", msg="成功", data="../data/" + str(int(time.time())) + _file.name)
def post(self, request): """ 添加面试反馈信息 :param request: :return: """ data = JSONParser().parse(request) data["InterviewTime"] = datetime.strptime(data["InterviewTime"], "%Y-%m-%d %H:%M:%S") feed_serializer = FeedBackDeserializer(data=data) if feed_serializer.is_valid(): # 保持新项目 feed_serializer.save() return JsonResponse(code="999999", msg="成功") return JsonResponse(code="999998", msg="参数有误")
def post(self, request): data = JSONParser().parse(request) try: _dict["GayFriend"] = data["GayFriend"] except KeyError: pass return JsonResponse(data=_dict, code="999999", msg="虽然我是post,但只要我想也可以修改数据,试试修改基友")
def get(self, request): value = request.GET.get("test", "GayFriend") try: _dict.pop(value) except KeyError: pass return JsonResponse(data=_dict, code="999999", msg="虽然我是get,但只要我想也可以删除数据, 传递test=key试试")
def __call__(self, request): ip = request.META['REMOTE_ADDR'] # 获取访问用户的ip if cache.has_key(ip): num = cache.get(ip) if num == 5: return JsonResponse(code="999997", msg="添加太频繁,请稍后添加") # 返回响应 else: cache.set(ip, num+1) else: cache.set(ip, 1, 60 * 60 * 24) response = self.get_response(request) return response
def download_doc(request): url = request.GET.get("url") if not url: return JsonResponse(code="999999", msg="参数有误") def file_iterator(_file, chunk_size=512): while True: c = _file.read(chunk_size) if c: yield c else: break layout = url.split(".")[-1] file_name = str(int(time.time())) + "." + layout _file = open(url, "rb") response = StreamingHttpResponse(file_iterator(_file)) response["Content-Type"] = "application/octet-stream" response["Content-Disposition"] = "attachment;filename=\"{0}\"".format( file_name) return response
def delete(self, request): value = request.GET.get("attribute", "成都测试群") _dict["attribute"] = value return JsonResponse(data=_dict, code="999999", msg="虽然我是delete,但我也可以添加数据,试试添加属性")
def put(self, request): JSONParser().parse(request) return JsonResponse(data=_dict, code="999999", msg="虽然我是put,但我也可以获取数据")