示例#1
0
    async def get(self, request, pk: Optional[int] = None):
        """Allow to get a single or a collection of `Sandbox`."""
        try:
            if not await has_perm_async(request.user,
                                        "pl_sandbox.view_sandbox"):
                raise PermissionDenied("Missing view permission on Sandbox")

            if pk is not None:
                sandbox = await database_sync_to_async(Sandbox.objects.get
                                                       )(pk=pk)
                response = {
                    "status": True,
                    "row": await database_sync_to_async(dgeq.serialize)
                    (sandbox)
                }
            else:
                query = dgeq.GenericQuery(Sandbox,
                                          request.GET,
                                          user=request.user,
                                          use_permissions=True)
                response = await database_sync_to_async(query.evaluate)()
            status = 200

        except Sandbox.DoesNotExist as e:
            response = {
                "status": False,
                "message": str(e),
                "code": ErrorCode.from_exception(e).value
            }
            status = 404

        except PermissionDenied as e:
            response = {
                "status": False,
                "message": str(e),
                "code": ErrorCode.from_exception(e).value
            }
            status = 403

        return JsonResponse(response, status=status)
示例#2
0
    async def get(self, request, pk: Optional[int] = None):
        try:
            if not await has_perm_async(request.user,
                                        "pl_sandbox.view_commandresult"):
                raise PermissionDenied(
                    "Missing view permission on CommandResult")

            if pk is not None:
                execution = await database_sync_to_async(
                    CommandResult.objects.get)(pk=pk)
                response = {
                    "status": True,
                    "row": await database_sync_to_async(dgeq.serialize)
                    (execution)
                }
            else:
                query = dgeq.GenericQuery(CommandResult,
                                          request.GET,
                                          user=request.user,
                                          use_permissions=True)
                response = await database_sync_to_async(query.evaluate)()
            status = 200

        except CommandResult.DoesNotExist as e:
            response = {
                "status": False,
                "message": str(e),
                "code": ErrorCode.from_exception(e).value
            }
            status = 404

        except PermissionDenied as e:
            response = {
                "status": False,
                "message": str(e),
                "code": ErrorCode.from_exception(e).value
            }
            status = 403

        return JsonResponse(response, status=status)
示例#3
0
文件: views.py 项目: qcoumes/dgeq
def continent(request: HttpRequest):
    q = dgeq.GenericQuery(models.Continent, request.GET, user=request.user)
    return JsonResponse(q.evaluate())
示例#4
0
文件: views.py 项目: qcoumes/dgeq
def disaster(request: HttpRequest):
    q = dgeq.GenericQuery(models.Disaster, request.GET, user=request.user)
    return JsonResponse(q.evaluate())
示例#5
0
文件: views.py 项目: qcoumes/dgeq
def forest(request: HttpRequest):
    q = dgeq.GenericQuery(models.Forest, request.GET, user=request.user)
    return JsonResponse(q.evaluate())
示例#6
0
文件: views.py 项目: qcoumes/dgeq
def mountain(request: HttpRequest):
    q = dgeq.GenericQuery(models.Mountain, request.GET, user=request.user)
    return JsonResponse(q.evaluate())
示例#7
0
文件: views.py 项目: qcoumes/dgeq
def region(request: HttpRequest):
    q = dgeq.GenericQuery(models.Region, request.GET, user=request.user)
    return JsonResponse(q.evaluate())