コード例 #1
0
 def get(self, request):
     params = {k: v for k, v in request.GET.items() if v}
     response = auth_backend.get_client(
         request.session
     ).rating.hashmap.get_field(**params)
     json_response = json.dumps(response)
     return HttpResponse(json_response, content_type="application_json")
コード例 #2
0
 def get(self, request):
     try:
         response = auth_backend.get_client(
             request.session
         ).rating.get_module()
     except Exception as e:
         return HttpResponse(str(e), status=500)
     json_response = json.dumps(response)
     return HttpResponse(json_response, content_type="application_json")
コード例 #3
0
 def get(self, request):
     params = {k: v for k, v in request.GET.items() if v}
     try:
         response = auth_backend.get_client(
             request.session
         ).rating.hashmap.get_threshold(**params)
     except Exception as e:
         return HttpResponse(str(e), status=500)
     json_response = json.dumps(response)
     return HttpResponse(json_response, content_type="application_json")
コード例 #4
0
 def get(self, request):
     params = {k: v for k, v in request.GET.items() if v}
     try:
         response = auth_backend.get_client(
             request.session
         ).scope.get_scope_state(**params)
         json_response = json.dumps(response)
         return HttpResponse(
             json_response, content_type="application_json; charset=utf-8"
         )
     except Exception as e:
         error_message = str(e)
         return HttpResponse(error_message, status=500)
コード例 #5
0
 def delete(self, request):
     try:
         body_unicode = request.body.decode("utf-8")
         body_params = json.loads(body_unicode)
         response = auth_backend.get_client(
             request.session
         ).rating.hashmap.delete_threshold(**body_params)
         return HttpResponse(response, content_type="text/plain")
     except Exception as e:
         error_message = "Failed to delete threshold: " + str(e)
         return HttpResponse(
             error_message, content_type="text/plain", status=400
         )
コード例 #6
0
 def put(self, request):
     try:
         body_unicode = request.body.decode("utf-8")
         body_params = json.loads(body_unicode)
         body_params = {k: v for k, v in body_params.items() if v}
         response = auth_backend.get_client(
             request.session
         ).rating.hashmap.create_mapping(**body_params)
         json_response = json.dumps(response)
         return HttpResponse(json_response, content_type="application/json")
     except Exception as e:
         error_message = "Failed to create mapping: " + str(e)
         return HttpResponse(
             error_message, content_type="text/plain", status=400
         )
コード例 #7
0
 def get(self, request):
     params = {k: v for k, v in request.GET.items() if v}
     if "filters" in params:
         params["filters"] = json.loads(params.get("filters"))
     client = auth_backend.get_client(request.session)
     # Manage pagination
     if "page" in params and int(params["page"]) > 0:
         page = int(params["page"])
     else:
         page = 1
     if "limit" not in params:
         params["limit"] = settings.DEFAULT_PAGINATION_LIMIT
     params["offset"] = int(params["limit"]) * (page - 1)
     try:
         if ("chart" in params) and params["chart"] == "true":
             response = self.get_summary_chart_data(client, params)
         else:
             response = self.get_summary_data(client, params)
     except exceptions.CloudkittyAPIClientException as e:
         return HttpResponse(str(e), status=500)
     json_response = json.dumps(response)
     return HttpResponse(json_response, content_type="application/json")