11import os
22import uuid
3+ import csv
34from django .shortcuts import render , redirect
45from django .http import HttpResponse , FileResponse , Http404
56from django .conf import settings
@@ -16,23 +17,40 @@ def index(request):
1617 # Page from the theme
1718 return render (request , 'pages/dashboard.html' , context = context )
1819
20+ def convert_csv_to_text (csv_file_path ):
21+ with open (csv_file_path , 'r' ) as file :
22+ reader = csv .reader (file )
23+ rows = list (reader )
24+
25+ text = ''
26+ for row in rows :
27+ text += ',' .join (row ) + '\n '
28+
29+ return text
30+
1931def get_files_from_directory (directory_path ):
2032 files = []
2133 for filename in os .listdir (directory_path ):
2234 file_path = os .path .join (directory_path , filename )
2335 if os .path .isfile (file_path ):
2436 try :
2537 print ( ' > file_path ' + file_path )
38+ _ , extension = os .path .splitext (filename )
39+ if extension .lower () == '.csv' :
40+ csv_text = convert_csv_to_text (file_path )
41+ else :
42+ csv_text = ''
43+
2644 files .append ({
2745 'file' : file_path .split (os .sep + 'media' + os .sep )[1 ],
2846 'filename' : filename ,
29- 'file_path' : file_path
47+ 'file_path' : file_path ,
48+ 'csv_text' : csv_text
3049 })
3150 except Exception as e :
3251 print ( ' > ' + str ( e ) )
3352 return files
3453
35-
3654def get_breadcrumbs (request ):
3755 path_components = [component for component in request .path .split ("/" ) if component ]
3856 breadcrumbs = []
0 commit comments