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)
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)
def continent(request: HttpRequest): q = dgeq.GenericQuery(models.Continent, request.GET, user=request.user) return JsonResponse(q.evaluate())
def disaster(request: HttpRequest): q = dgeq.GenericQuery(models.Disaster, request.GET, user=request.user) return JsonResponse(q.evaluate())
def forest(request: HttpRequest): q = dgeq.GenericQuery(models.Forest, request.GET, user=request.user) return JsonResponse(q.evaluate())
def mountain(request: HttpRequest): q = dgeq.GenericQuery(models.Mountain, request.GET, user=request.user) return JsonResponse(q.evaluate())
def region(request: HttpRequest): q = dgeq.GenericQuery(models.Region, request.GET, user=request.user) return JsonResponse(q.evaluate())