Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added dat files to download and content view climate #62 #63

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions framework/climate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
HASH_LENGTH = 32
TEMP_FILESIZE_LIMIT = 75 # MB
TEMP_NUM_BANDS_LIMIT = 1300 # Integer
ALLOWED_FILETYPES = ['nc', 'tif']
ALLOWED_FILETYPES = ['nc', 'tif', 'dat']

# test_file_name = "CLMcom-KIT-CCLM5-0-15_v1_MOHC-HadGEM2-ES__water_budget_all__yearsum_mean_2080_2099.nc"

Expand Down Expand Up @@ -387,10 +387,13 @@ def extract_ncfile_metadata(filename: str, source_dir: str, file_category: str,
return True, new_doc


def read_folder_constrained(source_dir: str):
foldercontent = list((file for file in os.listdir(source_dir)
if (os.path.isfile(os.path.join(source_dir, file)) and Path(file).suffix == '.nc')
))
def read_folder_constrained(source_dir: str, only_nc: bool = False):
if only_nc:
foldercontent = list((file for file in os.listdir(source_dir)
if (os.path.isfile(os.path.join(source_dir, file)) and Path(file).suffix == '.nc')))
else:
foldercontent = list((file for file in os.listdir(source_dir)
if (os.path.isfile(os.path.join(source_dir, file)))))
return foldercontent


Expand Down Expand Up @@ -669,7 +672,7 @@ def get(self, request):
return HttpResponse(content="Selected folder does currently not exist and cant be accessed.", status=500)

try:
foldercontent = read_folder_constrained(source_dir)
foldercontent = read_folder_constrained(source_dir, only_convertable)
except Exception as e:
print(e)
return HttpResponse(content="Reading the content of the selected folder has failed.", status=500)
Expand Down Expand Up @@ -726,6 +729,7 @@ def get(self, request):

# now either None (no database info) or file_info
dir_content_element.append(file_info)
dir_content_element.append(Path(f).suffix)

# Current format:
# [filename, filesize, creation date, number of bands]
Expand Down Expand Up @@ -777,8 +781,9 @@ def get(self, request):
if filetype == 'nc':
return self.serve_file(filepath, filename)
elif filetype == 'tif':

return self.serve_tif_file(filepath, filename, foldertype)
elif filetype == 'dat':
return self.serve_file(filepath, filename)
else:
# this should never be reached... only for readability/when adding more filetypes
return HttpResponse(content="Unknown filetype param value", status=400)
Expand Down
Loading