From 07538555fe7b26093d9cc1859b72749d97ff2113 Mon Sep 17 00:00:00 2001 From: devilsautumn Date: Mon, 16 Sep 2024 16:55:37 +0530 Subject: [PATCH] added template downloading. --- .../src/zango/apps/shared/tenancy/models.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/zango/apps/shared/tenancy/models.py b/backend/src/zango/apps/shared/tenancy/models.py index 260e276d..17f56e05 100644 --- a/backend/src/zango/apps/shared/tenancy/models.py +++ b/backend/src/zango/apps/shared/tenancy/models.py @@ -1,5 +1,7 @@ import os import re +import requests +import tempfile import uuid from collections import namedtuple @@ -139,12 +141,26 @@ def create(cls, name, schema_name, description, app_template_name, **other_param ) app_template_path = None if obj.app_template: + if obj.app_template.url.startswith("https://"): + downloaded_file_path = cls.download_file(obj.app_template.url) + else: + downloaded_file_path = obj.app_template app_template_path = os.path.join( - extract_zip_to_temp_dir(obj.app_template), app_template_name + extract_zip_to_temp_dir(downloaded_file_path), app_template_name ) # initialize tenant's workspace init_task = initialize_workspace.delay(str(obj.uuid), app_template_path) return obj, init_task.id + + @staticmethod + def download_file(url): + response = requests.get(url) + response.raise_for_status() # Raise an exception for bad status codes + + # Create a temporary file + with tempfile.NamedTemporaryFile(delete=False) as temp_file: + temp_file.write(response.content) + return temp_file.name class Domain(DomainMixin, FullAuditMixin):