Skip to content

Commit

Permalink
Replace fixed folder with dynamic folder for download #53
Browse files Browse the repository at this point in the history
  • Loading branch information
geofranzi committed Jun 10, 2024
1 parent dc8911e commit 9baa415
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions framework/climate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@

# URLTXTFILES_DIR = os.path.join(settings.STATICFILES_DIRS[0], 'urltxtfiles')
URLTXTFILES_DIR = "/opt/rbis/www/tippecc_data/tmp/"
TESTCONTENT_DIR = "/opt/rbis/www/tippecc_data/tmp/water_budget"
#TESTCONTENT_DIR = "/opt/rbis/www/tippecc_data/tmp/water_budget"

folder_list = {}
folder_list["water_budget"] = "/opt/rbis/www/tippecc_data/tmp/water_budget"
folder_list["water_budget_bias"] = "/opt/rbis/www/tippecc_data/tmp/water_budget/bias"


GENERAL_API_URL = "https://leutra.geogr.uni-jena.de/backend_geoportal/"
FORBIDDEN_CHARACTERS = ["/", "\\", ".", "-", ":", "@", "&", "^", ">", "<", "~", "$"]
Expand Down Expand Up @@ -70,8 +75,8 @@ class SelectionForWgetView(APIView):
def post(self, request):
body_unicode = request.body.decode("utf-8")
body = json.loads(body_unicode)

foldercontent = os.listdir(TESTCONTENT_DIR)
type = request.GET.get("type", default=None)
foldercontent = os.listdir(folder_list[type])

# for all requested files in requestbody, check if they really exist
for entry in body:
Expand All @@ -80,7 +85,7 @@ def post(self, request):

url_content = ""
for entry in body:
url_content += GENERAL_API_URL + "/climate/get_file?name=" + entry + "\n"
url_content += GENERAL_API_URL + "/climate/get_file?name=" + entry + "&type="+ type + "\n"

unique_filehash = str(uuid.uuid4().hex)
unique_filename = unique_filehash + ".txt"
Expand All @@ -107,8 +112,11 @@ def post(self, request):
# returns all filenames of the specified directory ('TESTCONTENT_DIR' rn)
class ContentView(APIView):
def get(self, request):

folder = request.GET.get("type", default=None)
TESTCONTENT_DIR = folder_list[folder]
foldercontent = os.listdir(TESTCONTENT_DIR)

dir_content = []

for i, f in enumerate(foldercontent):
Expand Down Expand Up @@ -149,6 +157,10 @@ def sizeof_fmt(self, num, suffix="B"):
class GetFileView(APIView):
def get(self, request):
filename = request.GET.get("name", default=None)
folder = request.GET.get("type", default=None)

TESTCONTENT_DIR = folder_list[folder]


foldercontent = os.listdir(TESTCONTENT_DIR)
print("FILENAME: ", filename)
Expand Down

0 comments on commit 9baa415

Please sign in to comment.