From 1959e285e679cef983898fcc7bf55ffa6abd2aa2 Mon Sep 17 00:00:00 2001 From: Uday Sagar Date: Tue, 12 Mar 2024 16:59:38 +0530 Subject: [PATCH] added limit support for assets import --- care/facility/api/viewsets/asset.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/care/facility/api/viewsets/asset.py b/care/facility/api/viewsets/asset.py index 98df9b8a86..e2d8ca9317 100644 --- a/care/facility/api/viewsets/asset.py +++ b/care/facility/api/viewsets/asset.py @@ -422,6 +422,14 @@ def bulk_upsert(self, request, *args, **kwargs): if "location" not in request.data: raise ValidationError({"location": "Location is required"}) + limit = request.data.get("limit", None) + if limit is None: + limit = float("inf") + if len(request.data["assets"]) > limit: + raise ValidationError( + {"assets": f"Maximum of {limit} assets can be created at once"} + ) + assets = request.data.get("assets", []) location = request.data.get("location") errors = []