def required_size_for_config(request): try: payload = request.body if type(payload) is bytes: payload = payload.decode("UTF-8") data = json.loads(payload) except Exception: return JsonResponse({"error": str(request.body)}) # check disk space collection = get_collection( edupi=data.get("edupi", False), edupi_resources=data.get("edupi_resources", None), nomad=data.get("nomad", False), mathews=data.get("mathews", False), africatik=data.get("africatik", False), packages=data.get("packages", []), kalite_languages=data.get("kalite", []), wikifundi_languages=data.get("wikifundi", []), aflatoun_languages=["fr", "en"] if data.get("aflatoun", False) else [], ) required_image_size = get_required_image_size(collection) media = Media.get_min_for(required_image_size) return JsonResponse({ "size": required_image_size, "hsize": human_readable_size(required_image_size, False), "media_size": human_readable_size(media.size * ONE_GB, False) if media else None, "hfree": human_readable_size(media.bytes - required_image_size) if media else None, })
def collection(self): return get_collection( edupi=self.content_edupi, edupi_resources=self.content_edupi_resources or None, packages=self.content_zims or [], kalite_languages=self.kalite_languages, wikifundi_languages=self.wikifundi_languages, aflatoun_languages=["fr", "en"] if self.content_aflatoun else [], )